Linux Kernel
3.7.1
|
#include <linux/types.h>
#include <linux/bitops.h>
#include <linux/init.h>
#include <linux/rcupdate.h>
Go to the source code of this file.
Data Structures | |
struct | idr_layer |
struct | idr |
struct | ida_bitmap |
struct | ida |
Macros | |
#define | IDR_SIZE (1 << IDR_BITS) |
#define | IDR_MASK ((1 << IDR_BITS)-1) |
#define | MAX_IDR_SHIFT (sizeof(int)*8 - 1) |
#define | MAX_IDR_BIT (1U << MAX_IDR_SHIFT) |
#define | MAX_IDR_MASK (MAX_IDR_BIT - 1) |
#define | MAX_IDR_LEVEL ((MAX_IDR_SHIFT + IDR_BITS - 1) / IDR_BITS) |
#define | MAX_IDR_FREE (MAX_IDR_LEVEL * 2) |
#define | IDR_INIT(name) |
#define | DEFINE_IDR(name) struct idr name = IDR_INIT(name) |
#define | IDR_NEED_TO_GROW -2 |
#define | IDR_NOMORE_SPACE -3 |
#define | _idr_rc_to_errno(rc) ((rc) == -1 ? -EAGAIN : -ENOSPC) |
#define | IDA_CHUNK_SIZE 128 /* 128 bytes per chunk */ |
#define | IDA_BITMAP_LONGS (IDA_CHUNK_SIZE / sizeof(long) - 1) |
#define | IDA_BITMAP_BITS (IDA_BITMAP_LONGS * sizeof(long) * 8) |
#define | IDA_INIT(name) { .idr = IDR_INIT(name), .free_bitmap = NULL, } |
#define | DEFINE_IDA(name) struct ida name = IDA_INIT(name) |
#define IDA_BITMAP_BITS (IDA_BITMAP_LONGS * sizeof(long) * 8) |
#define IDA_BITMAP_LONGS (IDA_CHUNK_SIZE / sizeof(long) - 1) |
#define IDR_INIT | ( | name | ) |
#define MAX_IDR_FREE (MAX_IDR_LEVEL * 2) |
#define MAX_IDR_LEVEL ((MAX_IDR_SHIFT + IDR_BITS - 1) / IDR_BITS) |
#define MAX_IDR_MASK (MAX_IDR_BIT - 1) |
ida_get_new - allocate new ID : idr handle : pointer to the allocated handle
Allocate new ID. It should be called with any required locks.
If memory is required, it will return %-EAGAIN, you should unlock and go back to the idr_pre_get() call. If the idr is full, it will return %-ENOSPC.
returns a value in the range %0 ... %0x7fffffff.
ida_get_new_above - allocate new ID above or equal to a start id : ida handle : id to start search at : pointer to the allocated handle
Allocate new ID above or equal to . It should be called with any required locks.
If memory is required, it will return %-EAGAIN, you should unlock and go back to the ida_pre_get() call. If the ida is full, it will return %-ENOSPC.
returns a value in the range ... %0x7fffffff.
ida_pre_get - reserve resources for ida allocation : ida handle : memory allocation flag
This function should be called prior to locking and calling the following function. It preallocates enough memory to satisfy the worst possible allocation.
If the system is REALLY out of memory this function returns %0, otherwise %1.
ida_simple_get - get a new id. : the (initialized) ida. : the minimum id (inclusive, < 0x8000000) : the maximum id (exclusive, < 0x8000000 or 0) : memory allocation flags
Allocates an id in the range start <= id < end, or returns -ENOSPC. On memory allocation failure, returns -ENOMEM.
Use ida_simple_remove() to get rid of an id.
DOC: idr sync idr synchronization (stolen from radix-tree.h)
idr_find() is able to be called locklessly, using RCU. The caller must ensure calls to this function are made within rcu_read_lock() regions. Other readers (lock-free or otherwise) and modifications may be running concurrently.
It is still required that the caller manage the synchronization and lifetimes of the items. So if RCU lock-free lookups are used, typically this would mean that the items have their own locks, or are amenable to lock-free access; and that the items are freed by RCU (or only freed after having been deleted from the idr tree and a synchronize_rcu() grace period).
idr_find - return pointer for given id : idr handle : lookup key
Return the pointer given the id it has been registered with. A NULL return indicates that is not valid or you passed NULL in idr_get_new().
This function can be called under rcu_read_lock(), given that the leaf pointers lifetimes are correctly managed.
idr_get_new - allocate new idr entry : idr handle : pointer you want associated with the id : pointer to the allocated handle
If allocation from IDR's private freelist fails, idr_get_new_above() will return %-EAGAIN. The caller should retry the idr_pre_get() call to refill IDR's preallocation and then retry the idr_get_new_above() call.
If the idr is full idr_get_new_above() will return %-ENOSPC.
returns a value in the range %0 ... %0x7fffffff
idr_get_new_above - allocate new idr entry above or equal to a start id : idr handle : pointer you want associated with the id : id to start search at : pointer to the allocated handle
This is the allocate id function. It should be called with any required locks.
If allocation from IDR's private freelist fails, idr_get_new_above() will return %-EAGAIN. The caller should retry the idr_pre_get() call to refill IDR's preallocation and then retry the idr_get_new_above() call.
If the idr is full idr_get_new_above() will return %-ENOSPC.
returns a value in the range ... %0x7fffffff
idr_get_next - lookup next object of id to given id. : idr handle : pointer to lookup key
Returns pointer to registered object with id, which is next number to given id. After being looked up, * will be updated for the next iteration.
This function can be called under rcu_read_lock(), given that the leaf pointers lifetimes are correctly managed.
idr_pre_get - reserve resources for idr allocation : idr handle : memory allocation flags
This function should be called prior to calling the idr_get_new* functions. It preallocates enough memory to satisfy the worst possible allocation. The caller should pass in GFP_KERNEL if possible. This of course requires that no spinning locks be held.
If the system is REALLY out of memory this function returns %0, otherwise %1.
idr_remove_all - remove all ids from the given idr tree : idr handle
idr_destroy() only frees up unused, cached idp_layers, but this function will remove all id mappings and leave all idp_layers unused.
A typical clean-up sequence for objects stored in an idr tree will use idr_for_each() to free all objects, if necessay, then idr_remove_all() to remove all ids, and idr_destroy() to free up the cached idr_layers.
idr_replace - replace pointer for given id : idr handle : pointer you want associated with the id : lookup key
Replace the pointer registered with an id and return the old value. A %-ENOENT return indicates that was not found. A %-EINVAL return indicates that was not within valid constraints.
The caller must serialize with writers.