summaryrefslogtreecommitdiff
path: root/pthread_spin_trylock.c
diff options
context:
space:
mode:
Diffstat (limited to 'pthread_spin_trylock.c')
-rw-r--r--pthread_spin_trylock.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/pthread_spin_trylock.c b/pthread_spin_trylock.c
index 39b7fd3..02cfd40 100644
--- a/pthread_spin_trylock.c
+++ b/pthread_spin_trylock.c
@@ -38,15 +38,17 @@
#include "implement.h"
-/*
- * NOTE: For speed, these routines don't check if "lock" is valid.
- */
int
pthread_spin_trylock(pthread_spinlock_t *lock)
{
- pthread_spinlock_t s = *lock;
+ register pthread_spinlock_t s;
+
+ if (NULL == lock || NULL == *lock)
+ {
+ return(EINVAL);
+ }
- if (s == PTHREAD_SPINLOCK_INITIALIZER)
+ if (*lock == PTHREAD_SPINLOCK_INITIALIZER)
{
int result;
@@ -56,6 +58,8 @@ pthread_spin_trylock(pthread_spinlock_t *lock)
}
}
+ s = *lock;
+
switch ((long) ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &(s->interlock),
(PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED,
(PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED ))