diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2013-03-22 21:41:45 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2013-03-22 21:41:45 -0400 |
commit | c324c3a9e7558e87ec628d45d3d0577d614ee350 (patch) | |
tree | c175f3e81fa765a571f82566decc8f54af0b548a /libdimension/threads.c | |
parent | 62fac6e15e51422a544de01ce6cb01b0921a6706 (diff) | |
download | dimension-faster-futures.tar.xz |
Use spinlock for futures when possible.faster-futures
Diffstat (limited to 'libdimension/threads.c')
-rw-r--r-- | libdimension/threads.c | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/libdimension/threads.c b/libdimension/threads.c index 0aed16d..9749976 100644 --- a/libdimension/threads.c +++ b/libdimension/threads.c @@ -1,5 +1,5 @@ /************************************************************************* - * Copyright (C) 2010-2011 Tavian Barnes <tavianator@tavianator.com> * + * Copyright (C) 2010-2013 Tavian Barnes <tavianator@tavianator.com> * * * * This file is part of The Dimension Library. * * * @@ -169,7 +169,7 @@ dmnsn_initialize_mutex(pthread_mutex_t *mutex) } void -dmnsn_lock_mutex_impl(pthread_mutex_t *mutex) +dmnsn_lock_mutex(pthread_mutex_t *mutex) { if (pthread_mutex_lock(mutex) != 0) { dmnsn_error("Couldn't lock mutex."); @@ -177,7 +177,7 @@ dmnsn_lock_mutex_impl(pthread_mutex_t *mutex) } void -dmnsn_unlock_mutex_impl(pthread_mutex_t *mutex) +dmnsn_unlock_mutex(pthread_mutex_t *mutex) { if (pthread_mutex_unlock(mutex) != 0) { dmnsn_error("Couldn't unlock mutex."); @@ -201,7 +201,7 @@ dmnsn_initialize_rwlock(pthread_rwlock_t *rwlock) } void -dmnsn_read_lock_impl(pthread_rwlock_t *rwlock) +dmnsn_read_lock(pthread_rwlock_t *rwlock) { if (pthread_rwlock_rdlock(rwlock) != 0) { dmnsn_error("Couldn't acquire read lock."); @@ -209,7 +209,7 @@ dmnsn_read_lock_impl(pthread_rwlock_t *rwlock) } void -dmnsn_write_lock_impl(pthread_rwlock_t *rwlock) +dmnsn_write_lock(pthread_rwlock_t *rwlock) { if (pthread_rwlock_wrlock(rwlock) != 0) { dmnsn_error("Couldn't acquire write lock."); @@ -217,7 +217,7 @@ dmnsn_write_lock_impl(pthread_rwlock_t *rwlock) } void -dmnsn_unlock_rwlock_impl(pthread_rwlock_t *rwlock) +dmnsn_unlock_rwlock(pthread_rwlock_t *rwlock) { if (pthread_rwlock_unlock(rwlock) != 0) { dmnsn_error("Couldn't unlock read-write lock."); @@ -232,6 +232,42 @@ dmnsn_destroy_rwlock(pthread_rwlock_t *rwlock) } } +#if DMNSN_SPINLOCK + +void +dmnsn_initialize_spinlock(pthread_spinlock_t *lock, int pshared) +{ + if (pthread_spin_init(lock, pshared) != 0) { + dmnsn_error("Couldn't initialize spinlock."); + } +} + +void +dmnsn_lock_spinlock(pthread_spinlock_t *lock) +{ + if (pthread_spin_lock(lock) != 0) { + dmnsn_error("Couldn't lock spinlock."); + } +} + +void +dmnsn_unlock_spinlock(pthread_spinlock_t *lock) +{ + if (pthread_spin_unlock(lock) != 0) { + dmnsn_error("Couldn't unlock spinlock."); + } +} + +void +dmnsn_destroy_spinlock(pthread_spinlock_t *lock) +{ + if (pthread_spin_destroy(lock) != 0) { + dmnsn_warning("Couldn't destroy spinlock."); + } +} + +#endif /* DMNSN_SPINLOCK */ + void dmnsn_initialize_cond(pthread_cond_t *cond) { |