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.h | |
parent | 62fac6e15e51422a544de01ce6cb01b0921a6706 (diff) | |
download | dimension-faster-futures.tar.xz |
Use spinlock for futures when possible.faster-futures
Diffstat (limited to 'libdimension/threads.h')
-rw-r--r-- | libdimension/threads.h | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/libdimension/threads.h b/libdimension/threads.h index ea9fb2a..7b7aae6 100644 --- a/libdimension/threads.h +++ b/libdimension/threads.h @@ -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. * * * @@ -67,24 +67,17 @@ DMNSN_INTERNAL int dmnsn_execute_concurrently(dmnsn_ccthread_fn *ccthread_fn, */ DMNSN_INTERNAL void dmnsn_initialize_mutex(pthread_mutex_t *mutex); -/** dmnsn_lock_mutex() implementation. */ -DMNSN_INTERNAL void dmnsn_lock_mutex_impl(pthread_mutex_t *mutex); -/** dmnsn_unlock_mutex() implementation. */ -DMNSN_INTERNAL void dmnsn_unlock_mutex_impl(pthread_mutex_t *mutex); - /** * Lock a mutex, bailing out on failure. - * Contains a {, so must be used in the same block as dmnsn_unlock_mutex(). * @param[in,out] mutex The mutex to lock. */ -#define dmnsn_lock_mutex(mutex) dmnsn_lock_mutex_impl((mutex)); { +DMNSN_INTERNAL void dmnsn_lock_mutex(pthread_mutex_t *mutex); /** - * Lock a mutex, bailing out on failure. - * Contains a }, so must be used in the same block as dmnsn_lock_mutex(). + * Unlock a mutex, bailing out on failure. * @param[in,out] mutex The mutex to unlock. */ -#define dmnsn_unlock_mutex(mutex) dmnsn_unlock_mutex_impl((mutex)); } +DMNSN_INTERNAL void dmnsn_unlock_mutex(pthread_mutex_t *mutex); /** * Destroy a mutex, warning on failure. @@ -98,34 +91,23 @@ DMNSN_INTERNAL void dmnsn_destroy_mutex(pthread_mutex_t *mutex); */ DMNSN_INTERNAL void dmnsn_initialize_rwlock(pthread_rwlock_t *rwlock); -/** dmnsn_read_lock() implementation. */ -DMNSN_INTERNAL void dmnsn_read_lock_impl(pthread_rwlock_t *rwlock); -/** dmnsn_write_lock() implementation. */ -DMNSN_INTERNAL void dmnsn_write_lock_impl(pthread_rwlock_t *rwlock); -/** dmnsn_unlock_rwlock() implementation. */ -DMNSN_INTERNAL void dmnsn_unlock_rwlock_impl(pthread_rwlock_t *rwlock); - /** * Lock a read-write lock, bailing out on failure. - * Contains a {, so must be used in the same block as dmnsn_unlock_rwlock(). * @param[in,out] rwlock The read-write lock to lock. */ -#define dmnsn_read_lock(rwlock) dmnsn_read_lock_impl((rwlock)); { +DMNSN_INTERNAL void dmnsn_read_lock(pthread_rwlock_t *rwlock); /** * Lock a read-write lock, bailing out on failure. - * Contains a {, so must be used in the same block as dmnsn_unlock_rwlock(). * @param[in,out] rwlock The read-write lock to lock. */ -#define dmnsn_write_lock(rwlock) dmnsn_write_lock_impl((rwlock)); { +DMNSN_INTERNAL void dmnsn_write_lock(pthread_rwlock_t *rwlock); /** - * Lock a read-write lock, bailing out on failure. - * Contains a }, so must be used in the same block as dmnsn_read_lock() or - * dmnsn_write_lock(). + * Unlock a read-write lock, bailing out on failure. * @param[in,out] rwlock The read-write lock to lock. */ -#define dmnsn_unlock_rwlock(rwlock) dmnsn_unlock_rwlock_impl((rwlock)); } +DMNSN_INTERNAL void dmnsn_unlock_rwlock(pthread_rwlock_t *rwlock); /** * Destroy a read-write lock, warning on failure. @@ -133,6 +115,36 @@ DMNSN_INTERNAL void dmnsn_unlock_rwlock_impl(pthread_rwlock_t *rwlock); */ DMNSN_INTERNAL void dmnsn_destroy_rwlock(pthread_rwlock_t *rwlock); +#if DMNSN_SPINLOCK + +/** + * Initialize a read-write lock, bailing out on failure. + * @param[out] lock The spinlock to initialize. + * @param[in] pshared The process-specific flag (PTHREAD_PROCESS_SHARED or + * PTHREAD_PROCESS_PRIVATE). + */ +DMNSN_INTERNAL void dmnsn_initialize_spinlock(pthread_spinlock_t *lock, int pshared); + +/** + * Lock the given spinlock, bailing out on failure. + * @param[in] lock The spinlock to lock. + */ +DMNSN_INTERNAL void dmnsn_lock_spinlock(pthread_spinlock_t *lock); + +/** + * Unlock the given spinlock, bailing out on failure. + * @param[in] lock The spinlock to unlock. + */ +DMNSN_INTERNAL void dmnsn_unlock_spinlock(pthread_spinlock_t *lock); + +/** + * Destroy a spinlock lock, warning on failure. + * @param[in,out] lock The spinlock to destroy. + */ +DMNSN_INTERNAL void dmnsn_destroy_spinlock(pthread_spinlock_t *lock); + +#endif /* DMNSN_SPINLOCK */ + /** * Initialize a condition variable, bailing out on failure. * @param[out] cond The condition variable to initialize. |