summaryrefslogtreecommitdiff
path: root/implement.h
diff options
context:
space:
mode:
authorrpj <rpj>2001-07-06 18:16:50 +0000
committerrpj <rpj>2001-07-06 18:16:50 +0000
commit06974b302eaf8f08382e6e786aea53f420c12222 (patch)
tree1b574a41dacc634a105a74127b2dac30a60bda13 /implement.h
parent7a3104dc65b469cbb9c88b6a9c7b7bea4126a43e (diff)
Spinlocks and barriers fixed and working. Beta level.
* spin.c: Revamped and working; included static initialiser. * barrier.c: Likewise. * condvar.c: Macro constant change; inline auto init routine. * mutex.c: Likewise. * rwlock.c: Likewise. * private.c: Add support for spinlock initialiser. * global.c: Likewise. * implement.h: Likewise. * pthread.h (PTHREAD_SPINLOCK_INITIALIZER): Fix typo. tests/ChangeLog: * spin3.c: Changed test and fixed. * spin4.c: Fixed. * barrier3.c: Fixed. * barrier4.c: Fixed.
Diffstat (limited to 'implement.h')
-rw-r--r--implement.h36
1 files changed, 31 insertions, 5 deletions
diff --git a/implement.h b/implement.h
index 8d19406..5a146c0 100644
--- a/implement.h
+++ b/implement.h
@@ -39,6 +39,12 @@
#include "semaphore.h"
#include "sched.h"
+#if defined(HAVE_C_INLINE) || defined(__cplusplus)
+#define INLINE inline
+#else
+#define INLINE
+#endif
+
typedef enum {
/*
* This enumeration represents the state of the thread;
@@ -136,9 +142,6 @@ struct sem_t_ {
#define PTW32_OBJECT_AUTO_INIT ((void *) -1)
#define PTW32_OBJECT_INVALID NULL
-#define PTW32_SPIN_UNLOCKED (1)
-#define PTW32_SPIN_LOCKED (2)
-#define PTW32_SPIN_INTERLOCK_MASK (~3L)
struct pthread_mutex_t_ {
LONG lock_idx;
@@ -154,10 +157,32 @@ struct pthread_mutexattr_t_ {
int kind;
};
+/*
+ * Possible values, other than PTW32_OBJECT_INVALID,
+ * for the "interlock" element in a spinlock.
+ *
+ * In this implementation, when a spinlock is initialised,
+ * the number of cpus available to the process is checked.
+ * If there is only one cpu then "interlock" is set equal to
+ * PTW32_SPIN_USE_MUTEX and u.mutex is a initialised mutex.
+ * If the number of cpus is greater than 1 then "interlock"
+ * is set equal to PTW32_SPIN_UNLOCKED and the number is
+ * stored in u.cpus. This arrangement allows the spinlock
+ * routines to attempt an InterlockedCompareExchange on "interlock"
+ * immediately and, if that fails, to try the inferior mutex.
+ *
+ * "u.cpus" isn't used for anything yet, but could be used at
+ * some point to optimise spinlock behaviour.
+ */
+#define PTW32_SPIN_UNLOCKED (1)
+#define PTW32_SPIN_LOCKED (2)
+#define PTW32_SPIN_USE_MUTEX (3)
+
struct pthread_spinlock_t_ {
+ long interlock; /* Locking element for multi-cpus. */
union {
- LONG interlock;
- pthread_mutex_t mx;
+ int cpus; /* No. of cpus if multi cpus, or */
+ pthread_mutex_t mutex; /* mutex if single cpu. */
} u;
};
@@ -359,6 +384,7 @@ extern int ptw32_concurrency;
extern CRITICAL_SECTION ptw32_mutex_test_init_lock;
extern CRITICAL_SECTION ptw32_cond_test_init_lock;
extern CRITICAL_SECTION ptw32_rwlock_test_init_lock;
+extern CRITICAL_SECTION ptw32_spinlock_test_init_lock;
#ifdef _UWIN
extern int pthread_count;