Commit 3937e807 authored by Karl Heyes's avatar Karl Heyes

Add handlers for spinlocks if available, map to mutexes when not.

svn path=/icecast/trunk/thread/; revision=15614
parent a8048333
......@@ -195,6 +195,7 @@ void thread_shutdown(void)
avl_tree_free(_mutextree, _free_mutex);
#endif
avl_tree_free(_threadtree, _free_thread);
_threadtree = NULL;
}
#ifdef THREAD_DEBUG
......@@ -222,6 +223,7 @@ static void _block_signals(void)
sigdelset(&ss, SIGKILL);
sigdelset(&ss, SIGSTOP);
sigdelset(&ss, SIGSEGV);
sigdelset(&ss, SIGCHLD);
sigdelset(&ss, SIGBUS);
if (pthread_sigmask(SIG_BLOCK, &ss, NULL) != 0) {
#ifdef THREAD_DEBUG
......@@ -594,7 +596,7 @@ void thread_exit_c(long val, int line, char *file)
avl_delete(_threadtree, th, _free_thread);
_mutex_unlock(&_threadtree_mutex);
}
pthread_exit ((void*)val);
}
......@@ -811,3 +813,29 @@ static int _free_thread(void *key)
}
#ifdef HAVE_PTHREAD_SPIN_LOCK
void thread_spin_create (spin_t *spin)
{
int x = pthread_spin_init (&spin->lock, PTHREAD_PROCESS_PRIVATE);
if (x)
abort();
}
void thread_spin_destroy (spin_t *spin)
{
pthread_spin_destroy (&spin->lock);
}
void thread_spin_lock (spin_t *spin)
{
int x = pthread_spin_lock (&spin->lock);
if (x != 0)
abort();
}
void thread_spin_unlock (spin_t *spin)
{
pthread_spin_unlock (&spin->lock);
}
#endif
......@@ -89,6 +89,24 @@ typedef struct {
pthread_rwlock_t sys_rwlock;
} rwlock_t;
#ifdef HAVE_PTHREAD_SPIN_LOCK
typedef struct
{
pthread_spinlock_t lock;
} spin_t;
void thread_spin_create (spin_t *spin);
void thread_spin_destroy (spin_t *spin);
void thread_spin_lock (spin_t *spin);
void thread_spin_unlock (spin_t *spin);
#else
typedef mutex_t spin_t;
#define thread_spin_create(x) thread_mutex_create(x)
#define thread_spin_destroy(x) thread_mutex_destroy(x)
#define thread_spin_lock(x) thread_mutex_lock(x)
#define thread_spin_unlock(x) thread_mutex_unlock(x)
#endif
#define thread_create(n,x,y,z) thread_create_c(n,x,y,z,__LINE__,__FILE__)
#define thread_mutex_create(x) thread_mutex_create_c(x,__LINE__,__FILE__)
#define thread_mutex_lock(x) thread_mutex_lock_c(x,__LINE__,__FILE__)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment