nfs-ganesha 1.4
|
Generic weak reference package. More...
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <time.h>
#include <pthread.h>
#include <assert.h>
#include <stdint.h>
#include "nlm_list.h"
#include "fsal.h"
#include "nfs_core.h"
#include "log.h"
#include "cache_inode.h"
#include "generic_weakref.h"
Go to the source code of this file.
Classes | |
struct | gweakref_partition_ |
The table partition. More... | |
struct | gweakref_table_ |
The weakref table structure. More... | |
struct | gweakref_priv_ |
Element within the AVL tree implementing weak references. More... | |
Defines | |
#define | CACHE_LINE_SIZE 64 |
#define | CACHE_PAD(_n) char __pad ## _n [CACHE_LINE_SIZE] |
#define | gwt_partition_of_addr_k(xt, k) (((xt)->partition)+(((uint64_t)k)%(xt)->npart)) |
Find the correct partition for a pointer. | |
#define | GWR_FLAG_NONE 0x0000 |
#define | GWR_FLAG_WLOCKED 0x0001 |
Typedefs | |
typedef struct gweakref_partition_ | gweakref_partition_t |
The table partition. | |
typedef struct gweakref_priv_ | gweakref_priv_t |
Element within the AVL tree implementing weak references. | |
Functions | |
gweakref_table_t * | gweakref_init (uint32_t npart, uint32_t cache_sz) |
Create a weak reference table. | |
gweakref_t | gweakref_insert (gweakref_table_t *wt, void *obj) |
Insert a pointer into the weakref table. | |
void * | gweakref_lookupex (gweakref_table_t *wt, gweakref_t *ref, pthread_rwlock_t **lock) |
Search the table for an entry. | |
void * | gweakref_lookup (gweakref_table_t *wt, gweakref_t *ref) |
Wrapper around gweakref_lookupex. | |
void | gweakref_delete (gweakref_table_t *wt, gweakref_t *ref) |
Delete an entry from the table. | |
void | gweakref_destroy (gweakref_table_t *wt) |
Destroy a weakref table. |
Generic weak reference package.
This module defines an infrastructure for enforcement of reference counting guarantees, eviction safety, and access restrictions using ordinary object addresses.
Definition in file generic_weakref.c.
#define CACHE_LINE_SIZE 64 |
Definition at line 66 of file generic_weakref.c.
#define CACHE_PAD | ( | _n | ) | char __pad ## _n [CACHE_LINE_SIZE] |
Definition at line 67 of file generic_weakref.c.
#define GWR_FLAG_NONE 0x0000 |
Definition at line 358 of file generic_weakref.c.
#define GWR_FLAG_WLOCKED 0x0001 |
Definition at line 359 of file generic_weakref.c.
#define gwt_partition_of_addr_k | ( | xt, | |
k | |||
) | (((xt)->partition)+(((uint64_t)k)%(xt)->npart)) |
Find the correct partition for a pointer.
To lower thread contention, the table is composed of multiple trees, with the tree that receives a pointer determined by a modulus. This macro yields an expression that yields a pointer to the correct partition.
Definition at line 109 of file generic_weakref.c.
typedef struct gweakref_partition_ gweakref_partition_t |
The table partition.
Each tree is independent, having its own lock and generation number, thus reducing thread contention.
typedef struct gweakref_priv_ gweakref_priv_t |
Element within the AVL tree implementing weak references.
In this implementation, weak references are stored in an AVL tree of (pointer, generation) pairs. The pointer acts as the key in the tree, and a lookup is successful only if the generation number matches that stored in the found node. The same pointer that serves as the key serves as the value.
void gweakref_delete | ( | gweakref_table_t * | wt, |
gweakref_t * | ref | ||
) |
Delete an entry from the table.
This function deletes and frees the given entry from the weakref table.
wt | [in,out] The table from which to delete the entry |
ref | [in] The entry to delete |
Definition at line 415 of file generic_weakref.c.
void gweakref_destroy | ( | gweakref_table_t * | wt | ) |
Destroy a weakref table.
This function frees all entries in a weakref table, then all partition subtrees.
wt | [in,out] The table to be freed |
Definition at line 429 of file generic_weakref.c.
gweakref_table_t* gweakref_init | ( | uint32_t | npart, |
uint32_t | cache_sz | ||
) |
Create a weak reference table.
This function creates a new, empty weak reference table possessing the specified number of partitions. This table must be freed with gweakref_destroy rather than simply deallocated.
npart | [in] The number of partitions for the table |
Definition at line 189 of file generic_weakref.c.
gweakref_t gweakref_insert | ( | gweakref_table_t * | wt, |
void * | obj | ||
) |
Insert a pointer into the weakref table.
This function inserts a pointer into the weak reference table and returns a weak reference, consisting of a poitner and generation number. If the given pointer already exists within the table, a weak reference consisting of the address NULL and the generation number 0 is returned.
wt | [in] The table in which to add the pointer |
obj | [in] The address to insert |
Definition at line 242 of file generic_weakref.c.
void* gweakref_lookup | ( | gweakref_table_t * | wt, |
gweakref_t * | ref | ||
) |
Wrapper around gweakref_lookupex.
This function is a wrapper around gweakref_lookupex that frees the tree lock after the call.
wt | [in] The table to search |
ref | [in] The reference to search for |
Definition at line 343 of file generic_weakref.c.
void* gweakref_lookupex | ( | gweakref_table_t * | wt, |
gweakref_t * | ref, | ||
pthread_rwlock_t ** | lock | ||
) |
Search the table for an entry.
This function searches the weakref table for the supplied entry. If the entry is found, it is returned and the partition tree is held read-locked, to be unlocked by the caller. Otherwise NULL is returned and the partition tree is unlocked.
wt | [in] The table to search |
ref | [in] The reference to search for |
lock | [out] if the object is found, the lock for the tree. |
Definition at line 290 of file generic_weakref.c.