summaryrefslogtreecommitdiff
path: root/implement.h
diff options
context:
space:
mode:
authorrpj <rpj>2001-02-12 08:28:05 +0000
committerrpj <rpj>2001-02-12 08:28:05 +0000
commit3208cee87389dbe7479e44208f8c0a4f8725fae8 (patch)
tree2fa02fd9e27c30d459ea447f76748c99eba3e239 /implement.h
parent1c38dfed3806cf142ebb0b1be473c88c5b2ac929 (diff)
Revamp experimental mutex routines again to make
more atomic and cancel-safe.
Diffstat (limited to 'implement.h')
-rw-r--r--implement.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/implement.h b/implement.h
index 8297a46..bd74d55 100644
--- a/implement.h
+++ b/implement.h
@@ -118,6 +118,31 @@ struct pthread_attr_t_ {
* ====================
*/
+/*
+ * The following macros provide exclusive access to an object's pointer.
+ * See mutex.c:pthread_mutex_lock() for an example.
+ */
+
+#define PTW32_OBJECT_GET(type, ppObject, pDest) \
+ while (((pDest) = (type) InterlockedCompareExchangePointer((PVOID *)(ppObject), \
+ (PVOID)PTW32_OBJECT_IN_USE, \
+ (PVOID)PTW32_OBJECT_IN_USE)) \
+ == (type)PTW32_OBJECT_IN_USE) \
+ { \
+ Sleep(0); \
+ }
+
+#define PTW32_OBJECT_SET(ppObject, value) \
+ (void) InterlockedExchangePointer((PVOID *)(ppObject), (PVOID)(value))
+
+#define PTW32_OBJECT_TRYGET(type, ppObject, pDest) \
+ ((((pDest) = (type) InterlockedExchangePointer((PVOID *)(ppObject), \
+ (PVOID)PTW32_OBJECT_IN_USE)) \
+ == (type)PTW32_OBJECT_IN_USE) ? ((void) InterlockedExchangePointer((PVOID *)(ppObject), \
+ (PVOID)(pDest)) , 0) \
+ : 1)
+
+#define PTW32_OBJECT_IN_USE ((void *) -2)
#define PTW32_OBJECT_AUTO_INIT ((void *) -1)
#define PTW32_OBJECT_INVALID NULL