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.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/pthread_spin_trylock.c b/pthread_spin_trylock.c
index c54fe53..040a2b0 100644
--- a/pthread_spin_trylock.c
+++ b/pthread_spin_trylock.c
@@ -39,34 +39,41 @@
int
-pthread_spin_trylock(pthread_spinlock_t *lock)
+pthread_spin_trylock (pthread_spinlock_t * lock)
{
register pthread_spinlock_t s;
if (NULL == lock || NULL == *lock)
{
- return(EINVAL);
+ return (EINVAL);
}
if (*lock == PTHREAD_SPINLOCK_INITIALIZER)
{
int result;
- if ((result = ptw32_spinlock_check_need_init(lock)) != 0)
- {
- return(result);
- }
+ if ((result = ptw32_spinlock_check_need_init (lock)) != 0)
+ {
+ return (result);
+ }
}
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 ))
+ switch ((long)
+ ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG) &
+ (s->interlock),
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_SPIN_LOCKED,
+ (PTW32_INTERLOCKED_LONG)
+ PTW32_SPIN_UNLOCKED))
{
- case PTW32_SPIN_UNLOCKED: return 0;
- case PTW32_SPIN_LOCKED: return EBUSY;
- case PTW32_SPIN_USE_MUTEX: return pthread_mutex_trylock(&(s->u.mutex));
+ case PTW32_SPIN_UNLOCKED:
+ return 0;
+ case PTW32_SPIN_LOCKED:
+ return EBUSY;
+ case PTW32_SPIN_USE_MUTEX:
+ return pthread_mutex_trylock (&(s->u.mutex));
}
return EINVAL;