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