mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
xarray: Add definition of struct xarray
This is a direct replacement for struct radix_tree_root. Some of the struct members have changed name; convert those, and use a #define so that radix_tree users continue to work without change. Signed-off-by: Matthew Wilcox <willy@infradead.org> Reviewed-by: Josef Bacik <jbacik@fb.com>
This commit is contained in:
parent
02c02bf12c
commit
f8d5d0cc14
12 changed files with 181 additions and 68 deletions
|
@ -10,6 +10,8 @@
|
|||
*/
|
||||
|
||||
#include <linux/bug.h>
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/kconfig.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
|
@ -153,6 +155,74 @@ static inline bool xa_is_internal(const void *entry)
|
|||
return ((unsigned long)entry & 3) == 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* struct xarray - The anchor of the XArray.
|
||||
* @xa_lock: Lock that protects the contents of the XArray.
|
||||
*
|
||||
* To use the xarray, define it statically or embed it in your data structure.
|
||||
* It is a very small data structure, so it does not usually make sense to
|
||||
* allocate it separately and keep a pointer to it in your data structure.
|
||||
*
|
||||
* You may use the xa_lock to protect your own data structures as well.
|
||||
*/
|
||||
/*
|
||||
* If all of the entries in the array are NULL, @xa_head is a NULL pointer.
|
||||
* If the only non-NULL entry in the array is at index 0, @xa_head is that
|
||||
* entry. If any other entry in the array is non-NULL, @xa_head points
|
||||
* to an @xa_node.
|
||||
*/
|
||||
struct xarray {
|
||||
spinlock_t xa_lock;
|
||||
/* private: The rest of the data structure is not to be used directly. */
|
||||
gfp_t xa_flags;
|
||||
void __rcu * xa_head;
|
||||
};
|
||||
|
||||
#define XARRAY_INIT(name, flags) { \
|
||||
.xa_lock = __SPIN_LOCK_UNLOCKED(name.xa_lock), \
|
||||
.xa_flags = flags, \
|
||||
.xa_head = NULL, \
|
||||
}
|
||||
|
||||
/**
|
||||
* DEFINE_XARRAY_FLAGS() - Define an XArray with custom flags.
|
||||
* @name: A string that names your XArray.
|
||||
* @flags: XA_FLAG values.
|
||||
*
|
||||
* This is intended for file scope definitions of XArrays. It declares
|
||||
* and initialises an empty XArray with the chosen name and flags. It is
|
||||
* equivalent to calling xa_init_flags() on the array, but it does the
|
||||
* initialisation at compiletime instead of runtime.
|
||||
*/
|
||||
#define DEFINE_XARRAY_FLAGS(name, flags) \
|
||||
struct xarray name = XARRAY_INIT(name, flags)
|
||||
|
||||
/**
|
||||
* DEFINE_XARRAY() - Define an XArray.
|
||||
* @name: A string that names your XArray.
|
||||
*
|
||||
* This is intended for file scope definitions of XArrays. It declares
|
||||
* and initialises an empty XArray with the chosen name. It is equivalent
|
||||
* to calling xa_init() on the array, but it does the initialisation at
|
||||
* compiletime instead of runtime.
|
||||
*/
|
||||
#define DEFINE_XARRAY(name) DEFINE_XARRAY_FLAGS(name, 0)
|
||||
|
||||
void xa_init_flags(struct xarray *, gfp_t flags);
|
||||
|
||||
/**
|
||||
* xa_init() - Initialise an empty XArray.
|
||||
* @xa: XArray.
|
||||
*
|
||||
* An empty XArray is full of NULL entries.
|
||||
*
|
||||
* Context: Any context.
|
||||
*/
|
||||
static inline void xa_init(struct xarray *xa)
|
||||
{
|
||||
xa_init_flags(xa, 0);
|
||||
}
|
||||
|
||||
#define xa_trylock(xa) spin_trylock(&(xa)->xa_lock)
|
||||
#define xa_lock(xa) spin_lock(&(xa)->xa_lock)
|
||||
#define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue