diff options
author | rpj <rpj> | 2003-06-27 15:52:49 +0000 |
---|---|---|
committer | rpj <rpj> | 2003-06-27 15:52:49 +0000 |
commit | a250b09c42f9a261da78ecec6226d722e27eea67 (patch) | |
tree | 88749de8489643073f691c137988d8f8d3d6bb4a /pthread_spin_destroy.c | |
parent | 5c6e3df46e6f6a357d83ac817c73780ea5e64957 (diff) |
Free the spinlock struct in ALL appropriate cases.
Diffstat (limited to 'pthread_spin_destroy.c')
-rw-r--r-- | pthread_spin_destroy.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/pthread_spin_destroy.c b/pthread_spin_destroy.c index dbe6713..129e5eb 100644 --- a/pthread_spin_destroy.c +++ b/pthread_spin_destroy.c @@ -42,6 +42,7 @@ int pthread_spin_destroy(pthread_spinlock_t *lock) { register pthread_spinlock_t s; + int result = 0; if (lock == NULL || *lock == NULL) { @@ -52,34 +53,28 @@ pthread_spin_destroy(pthread_spinlock_t *lock) { if (s->interlock == PTW32_SPIN_USE_MUTEX) { - return pthread_mutex_destroy(&(s->u.mutex)); + result = pthread_mutex_destroy(&(s->u.mutex)); } - - if ( (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED == - ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &(s->interlock), - (PTW32_INTERLOCKED_LONG) PTW32_OBJECT_INVALID, - (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED)) + else if ( (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED != + ptw32_interlocked_compare_exchange((PTW32_INTERLOCKED_LPLONG) &(s->interlock), + (PTW32_INTERLOCKED_LONG) PTW32_OBJECT_INVALID, + (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED)) { + result = EINVAL; + } + + if (0 == result) + { /* - * The spinlock isn't held by another thread so other threads that have - * just entered another spin_* routine will get PTW32_OBJECT_INVALID - * and so return EINVAL. This will not be so if the memory freed below is - * re-allocated and initialised before that happens. - * - * We are relying on the application to be responsible for ensuring that - * all other threads have finished with the spinlock before destroying it. + * We are relying on the application to ensure that all other threads + * have finished with the spinlock before destroying it. */ *lock = NULL; (void) free(s); - return 0; - } - - return EINVAL; + } } else { - int result = 0; - /* * See notes in ptw32_spinlock_check_need_init() above also. */ @@ -108,6 +103,7 @@ pthread_spin_destroy(pthread_spinlock_t *lock) } LeaveCriticalSection(&ptw32_spinlock_test_init_lock); - return(result); } + + return(result); } |