FreeBSD ZFS
The Zettabyte File System
Defines | Functions

zrlock.c File Reference

Zero Reference Locks. More...

#include <sys/zrlock.h>
Include dependency graph for zrlock.c:

Go to the source code of this file.

Defines

#define ZRL_LOCKED   ((uint32_t)-1)
#define ZRL_DESTROYED   -2

Functions

void zrl_init (zrlock_t *zrl)
void zrl_destroy (zrlock_t *zrl)
void zrl_add (zrlock_t *zrl)
void zrl_remove (zrlock_t *zrl)
int zrl_tryenter (zrlock_t *zrl)
void zrl_exit (zrlock_t *zrl)
int zrl_refcount (zrlock_t *zrl)
int zrl_is_zero (zrlock_t *zrl)
int zrl_is_locked (zrlock_t *zrl)

Detailed Description

Zero Reference Locks.

A Zero Reference Lock (ZRL) is a reference count that can lock out new references only when the count is zero and only without waiting if the count is not already zero. It is similar to a read-write lock in that it allows multiple readers and only a single writer, but it does not allow a writer to block while waiting for readers to exit, and therefore the question of reader/writer priority is moot (no WRWANT bit). Since the equivalent of rw_enter(&lock, RW_WRITER) is disallowed and only tryenter() is allowed, it is perfectly safe for the same reader to acquire the same lock multiple times. The fact that a ZRL is reentrant for readers (through multiple calls to zrl_add()) makes it convenient for determining whether something is actively referenced without the fuss of flagging lock ownership across function calls.

Definition in file zrlock.c.


Define Documentation

#define ZRL_DESTROYED   -2

Definition at line 49 of file zrlock.c.

#define ZRL_LOCKED   ((uint32_t)-1)

Definition at line 48 of file zrlock.c.


Function Documentation

void zrl_add ( zrlock_t zrl)

Definition at line 77 of file zrlock.c.

void zrl_destroy ( zrlock_t zrl)

Definition at line 64 of file zrlock.c.

void zrl_exit ( zrlock_t zrl)

Definition at line 151 of file zrlock.c.

void zrl_init ( zrlock_t zrl)

Definition at line 52 of file zrlock.c.

int zrl_is_locked ( zrlock_t zrl)

Definition at line 184 of file zrlock.c.

int zrl_is_zero ( zrlock_t zrl)

Definition at line 176 of file zrlock.c.

int zrl_refcount ( zrlock_t zrl)

Definition at line 167 of file zrlock.c.

void zrl_remove ( zrlock_t zrl)

Definition at line 114 of file zrlock.c.

int zrl_tryenter ( zrlock_t zrl)

Definition at line 129 of file zrlock.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines