nfs-ganesha 1.4
Classes | Typedefs | Functions

generic_weakref.h File Reference

Generic weak reference package. More...

Go to the source code of this file.

Classes

struct  gweakref_

Typedefs

typedef struct gweakref_ gweakref_t
typedef struct gweakref_table_ gweakref_table_t

Functions

gweakref_table_tgweakref_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_lookup (gweakref_table_t *wt, gweakref_t *ref)
 Wrapper around gweakref_lookupex.
void * gweakref_lookupex (gweakref_table_t *wt, gweakref_t *ref, pthread_rwlock_t **lock)
 Search the table for an entry.
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.

Detailed Description

Generic weak reference package.

Author:
Matt Benjamin

DESCRIPTION

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.h.


Typedef Documentation

typedef struct gweakref_ gweakref_t

Definition at line 53 of file generic_weakref.h.


Function Documentation

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.

Parameters:
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.

Parameters:
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.

Parameters:
npart[in] The number of partitions for the table
Returns:
The address of the newly created table, NULL on failure.

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.

Parameters:
wt[in] The table in which to add the pointer
obj[in] The address to insert
Returns:
The weak reference created.

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.

Parameters:
wt[in] The table to search
ref[in] The reference to search for
Returns:
The found object, otherwise NULL.

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.

Parameters:
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.
Returns:
The found object, otherwise NULL.

Definition at line 290 of file generic_weakref.c.