summaryrefslogtreecommitdiffstats
path: root/libdimension/threads.h
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension/threads.h')
-rw-r--r--libdimension/threads.h64
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.