diff options
Diffstat (limited to 'include/lkdhash.h')
-rw-r--r-- | include/lkdhash.h | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/include/lkdhash.h b/include/lkdhash.h index 3557515..8dbf3aa 100644 --- a/include/lkdhash.h +++ b/include/lkdhash.h @@ -1,7 +1,16 @@ #ifndef __LKDHASH_H__ #define __LKDHASH_H__ -// This is intended to be used in conjunction with uthash and libglvnd_pthread. +/** + * \file + * + * Macros to implement a hashtable protected by a rwlock. + * + * With the exception of \c DEFINE_LKDHASH and \c DEFINE_INITIALIZED_LKDHASH, + * these macros all use the pthreads function table in glvnd_pthread.h, so you + * have to call \c glvndSetupPthreads before using them. + */ + #include "glvnd_pthread.h" #include "uthash.h" @@ -20,28 +29,28 @@ glvnd_rwlock_t lock; \ } _hashname = { NULL, GLVND_RWLOCK_INITIALIZER } -#define LKDHASH_INIT(imp, _lockedhash) do { \ +#define LKDHASH_INIT(_lockedhash) do { \ (_lockedhash).hash = NULL; \ - (imp).rwlock_init(&(_lockedhash).lock, NULL); \ + __glvndPthreadFuncs.rwlock_init(&(_lockedhash).lock, NULL); \ } while (0) /* * Macros for locking/unlocking the locked hash. */ -#define LKDHASH_RDLOCK(imp, _lockedhash) \ - (imp).rwlock_rdlock(&(_lockedhash).lock) -#define LKDHASH_WRLOCK(imp, _lockedhash) \ - (imp).rwlock_wrlock(&(_lockedhash).lock) -#define LKDHASH_UNLOCK(imp, _lockedhash) \ - (imp).rwlock_unlock(&(_lockedhash).lock) +#define LKDHASH_RDLOCK(_lockedhash) \ + __glvndPthreadFuncs.rwlock_rdlock(&(_lockedhash).lock) +#define LKDHASH_WRLOCK(_lockedhash) \ + __glvndPthreadFuncs.rwlock_wrlock(&(_lockedhash).lock) +#define LKDHASH_UNLOCK(_lockedhash) \ + __glvndPthreadFuncs.rwlock_unlock(&(_lockedhash).lock) /* * Converts a locked hash into a hash suitable for use with uthash. */ #define _LH(_lockedhash) ((_lockedhash).hash) -#define LKDHASH_TEARDOWN_2(imp, _lockedhash, _param, _cur, _tmp, _cleanup) do { \ - LKDHASH_WRLOCK(imp, _lockedhash); \ +#define LKDHASH_TEARDOWN_2(_lockedhash, _param, _cur, _tmp, _cleanup) do { \ + LKDHASH_WRLOCK(_lockedhash); \ HASH_ITER(hh, _LH( _lockedhash), _cur, _tmp) { \ HASH_DEL(_LH(_lockedhash), _cur); \ if (_cleanup) { \ @@ -50,7 +59,7 @@ free(_cur); \ } \ assert(!_LH(_lockedhash)); \ - LKDHASH_UNLOCK(imp, _lockedhash); \ + LKDHASH_UNLOCK(_lockedhash); \ } while (0) /*! @@ -70,16 +79,16 @@ * _reset indicates whether the lock needs to be re-initialized (for fork * handling). */ -#define LKDHASH_TEARDOWN(imp, _ht, _lh, _cleanup, _param, _reset) do { \ +#define LKDHASH_TEARDOWN(_ht, _lh, _cleanup, _param, _reset) do { \ _ht *cur ## _ht, *tmp ## _ht; \ typedef void (*pfnCleanup ## _ht)(void *p, _ht *h); \ pfnCleanup ## _ht pCleanup ## _ht = _cleanup; \ - LKDHASH_TEARDOWN_2(imp, _lh, _param, cur ## _ht, \ + LKDHASH_TEARDOWN_2(_lh, _param, cur ## _ht, \ tmp ## _ht, pCleanup ## _ht); \ if (_reset) { \ - (imp).rwlock_init(&(_lh).lock, NULL); \ + __glvndPthreadFuncs.rwlock_init(&(_lh).lock, NULL); \ } else { \ - (imp).rwlock_destroy(&(_lh).lock); \ + __glvndPthreadFuncs.rwlock_destroy(&(_lh).lock); \ } \ } while (0) |