summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBrian Nguyen <brnguyen@nvidia.com>2013-08-12 13:12:09 -0700
committerbrnguyen <brnguyen@nvidia.com>2013-08-26 11:03:41 -0700
commit4c68d3cc1ba9ee8a8a446cc90cfc61b7c9d30b6f (patch)
treeb66dc9f5c0cff94913b040cba22e6fe9af1818e4 /include
parentcbe758799754203d3f82d1d21e6f3eec7ccc155f (diff)
Add lkdhash.h
This is a simple wrapper around uthash which simplifies read/write locking around hashtables used by libGLX.
Diffstat (limited to 'include')
-rw-r--r--include/lkdhash.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/include/lkdhash.h b/include/lkdhash.h
new file mode 100644
index 0000000..e8349c5
--- /dev/null
+++ b/include/lkdhash.h
@@ -0,0 +1,43 @@
+#ifndef __LKDHASH_H__
+#define __LKDHASH_H__
+
+// This is intended to be used in conjunction with uthash and libglvnd_pthread.
+#include "glvnd_pthread.h"
+#include "uthash.h"
+
+/*
+ * Macros for defining a "locked hash": a hashtable protected by a lock.
+ */
+#define DEFINE_LKDHASH(_hashtype, _hashname) \
+ struct { \
+ _hashtype *hash; \
+ glvnd_rwlock_t lock; \
+ } _hashname
+
+#define DEFINE_INITIALIZED_LKDHASH(_hashtype, _hashname) \
+ struct { \
+ _hashtype *hash; \
+ glvnd_rwlock_t lock; \
+ } _hashname = { NULL, GLVND_RWLOCK_INITIALIZER }
+
+#define LKDHASH_INIT(imp, _lockedhash) do { \
+ (_lockedhash).hash = NULL; \
+ (imp).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)
+
+/*
+ * Converts a locked hash into a hash suitable for use with uthash.
+ */
+#define _LH(_lockedhash) ((_lockedhash).hash)
+
+#endif