mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2025-04-18 00:48:43 -04:00
Add handlers for spinlocks if available, map to mutexes when not.
svn path=/icecast/trunk/icecast/; revision=15614
This commit is contained in:
parent
add7342a14
commit
ed58514eaa
@ -103,7 +103,7 @@ typedef struct
|
|||||||
avl_tree *contents;
|
avl_tree *contents;
|
||||||
} cache_file_contents;
|
} cache_file_contents;
|
||||||
|
|
||||||
static mutex_t _connection_mutex;
|
static spin_t _connection_lock;
|
||||||
static volatile unsigned long _current_id = 0;
|
static volatile unsigned long _current_id = 0;
|
||||||
static int _initialized = 0;
|
static int _initialized = 0;
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ void connection_initialize(void)
|
|||||||
{
|
{
|
||||||
if (_initialized) return;
|
if (_initialized) return;
|
||||||
|
|
||||||
thread_mutex_create(&_connection_mutex);
|
thread_spin_create (&_connection_lock);
|
||||||
thread_mutex_create(&move_clients_mutex);
|
thread_mutex_create(&move_clients_mutex);
|
||||||
thread_rwlock_create(&_source_shutdown_rwlock);
|
thread_rwlock_create(&_source_shutdown_rwlock);
|
||||||
thread_cond_create(&global.shutdown_cond);
|
thread_cond_create(&global.shutdown_cond);
|
||||||
@ -171,7 +171,7 @@ void connection_shutdown(void)
|
|||||||
|
|
||||||
thread_cond_destroy(&global.shutdown_cond);
|
thread_cond_destroy(&global.shutdown_cond);
|
||||||
thread_rwlock_destroy(&_source_shutdown_rwlock);
|
thread_rwlock_destroy(&_source_shutdown_rwlock);
|
||||||
thread_mutex_destroy(&_connection_mutex);
|
thread_spin_destroy (&_connection_lock);
|
||||||
thread_mutex_destroy(&move_clients_mutex);
|
thread_mutex_destroy(&move_clients_mutex);
|
||||||
|
|
||||||
_initialized = 0;
|
_initialized = 0;
|
||||||
@ -181,9 +181,9 @@ static unsigned long _next_connection_id(void)
|
|||||||
{
|
{
|
||||||
unsigned long id;
|
unsigned long id;
|
||||||
|
|
||||||
thread_mutex_lock(&_connection_mutex);
|
thread_spin_lock (&_connection_lock);
|
||||||
id = _current_id++;
|
id = _current_id++;
|
||||||
thread_mutex_unlock(&_connection_mutex);
|
thread_spin_unlock (&_connection_lock);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
40
src/fserve.c
40
src/fserve.c
@ -66,10 +66,10 @@
|
|||||||
|
|
||||||
#define BUFSIZE 4096
|
#define BUFSIZE 4096
|
||||||
|
|
||||||
static fserve_t *active_list = NULL;
|
fserve_t *active_list = NULL;
|
||||||
static volatile fserve_t *pending_list = NULL;
|
fserve_t *pending_list = NULL;
|
||||||
|
|
||||||
static mutex_t pending_lock;
|
static spin_t pending_lock;
|
||||||
static avl_tree *mimetypes = NULL;
|
static avl_tree *mimetypes = NULL;
|
||||||
|
|
||||||
static volatile int run_fserv = 0;
|
static volatile int run_fserv = 0;
|
||||||
@ -97,7 +97,9 @@ void fserve_initialize(void)
|
|||||||
ice_config_t *config = config_get_config();
|
ice_config_t *config = config_get_config();
|
||||||
|
|
||||||
mimetypes = NULL;
|
mimetypes = NULL;
|
||||||
thread_mutex_create (&pending_lock);
|
active_list = NULL;
|
||||||
|
pending_list = NULL;
|
||||||
|
thread_spin_create (&pending_lock);
|
||||||
|
|
||||||
fserve_recheck_mime_types (config);
|
fserve_recheck_mime_types (config);
|
||||||
config_release_config();
|
config_release_config();
|
||||||
@ -108,7 +110,7 @@ void fserve_initialize(void)
|
|||||||
|
|
||||||
void fserve_shutdown(void)
|
void fserve_shutdown(void)
|
||||||
{
|
{
|
||||||
thread_mutex_lock (&pending_lock);
|
thread_spin_lock (&pending_lock);
|
||||||
run_fserv = 0;
|
run_fserv = 0;
|
||||||
while (pending_list)
|
while (pending_list)
|
||||||
{
|
{
|
||||||
@ -127,8 +129,8 @@ void fserve_shutdown(void)
|
|||||||
if (mimetypes)
|
if (mimetypes)
|
||||||
avl_tree_free (mimetypes, _delete_mapping);
|
avl_tree_free (mimetypes, _delete_mapping);
|
||||||
|
|
||||||
thread_mutex_unlock (&pending_lock);
|
thread_spin_unlock (&pending_lock);
|
||||||
thread_mutex_destroy (&pending_lock);
|
thread_spin_destroy (&pending_lock);
|
||||||
INFO0("file serving stopped");
|
INFO0("file serving stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,9 +157,9 @@ int fserve_client_waiting (void)
|
|||||||
}
|
}
|
||||||
if (!ufds)
|
if (!ufds)
|
||||||
{
|
{
|
||||||
thread_mutex_lock (&pending_lock);
|
thread_spin_lock (&pending_lock);
|
||||||
run_fserv = 0;
|
run_fserv = 0;
|
||||||
thread_mutex_unlock (&pending_lock);
|
thread_spin_unlock (&pending_lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (poll(ufds, fserve_clients, 200) > 0)
|
else if (poll(ufds, fserve_clients, 200) > 0)
|
||||||
@ -196,9 +198,9 @@ int fserve_client_waiting (void)
|
|||||||
/* hack for windows, select needs at least 1 descriptor */
|
/* hack for windows, select needs at least 1 descriptor */
|
||||||
if (fd_max == SOCK_ERROR)
|
if (fd_max == SOCK_ERROR)
|
||||||
{
|
{
|
||||||
thread_mutex_lock (&pending_lock);
|
thread_spin_lock (&pending_lock);
|
||||||
run_fserv = 0;
|
run_fserv = 0;
|
||||||
thread_mutex_unlock (&pending_lock);
|
thread_spin_unlock (&pending_lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -236,7 +238,7 @@ static int wait_for_fds(void)
|
|||||||
/* add any new clients here */
|
/* add any new clients here */
|
||||||
if (pending_list)
|
if (pending_list)
|
||||||
{
|
{
|
||||||
thread_mutex_lock (&pending_lock);
|
thread_spin_lock (&pending_lock);
|
||||||
|
|
||||||
fclient = (fserve_t*)pending_list;
|
fclient = (fserve_t*)pending_list;
|
||||||
while (fclient)
|
while (fclient)
|
||||||
@ -249,7 +251,7 @@ static int wait_for_fds(void)
|
|||||||
fserve_clients++;
|
fserve_clients++;
|
||||||
}
|
}
|
||||||
pending_list = NULL;
|
pending_list = NULL;
|
||||||
thread_mutex_unlock (&pending_lock);
|
thread_spin_unlock (&pending_lock);
|
||||||
}
|
}
|
||||||
/* drop out of here if someone is ready */
|
/* drop out of here if someone is ready */
|
||||||
ret = fserve_client_waiting();
|
ret = fserve_client_waiting();
|
||||||
@ -338,7 +340,7 @@ char *fserve_content_type (const char *path)
|
|||||||
void *result;
|
void *result;
|
||||||
char *type;
|
char *type;
|
||||||
|
|
||||||
thread_mutex_lock (&pending_lock);
|
thread_spin_lock (&pending_lock);
|
||||||
if (mimetypes && !avl_get_by_key (mimetypes, &exttype, &result))
|
if (mimetypes && !avl_get_by_key (mimetypes, &exttype, &result))
|
||||||
{
|
{
|
||||||
mime_type *mime = result;
|
mime_type *mime = result;
|
||||||
@ -367,7 +369,7 @@ char *fserve_content_type (const char *path)
|
|||||||
else
|
else
|
||||||
type = strdup ("application/octet-stream");
|
type = strdup ("application/octet-stream");
|
||||||
}
|
}
|
||||||
thread_mutex_unlock (&pending_lock);
|
thread_spin_unlock (&pending_lock);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,7 +624,7 @@ fail:
|
|||||||
*/
|
*/
|
||||||
static void fserve_add_pending (fserve_t *fclient)
|
static void fserve_add_pending (fserve_t *fclient)
|
||||||
{
|
{
|
||||||
thread_mutex_lock (&pending_lock);
|
thread_spin_lock (&pending_lock);
|
||||||
fclient->next = (fserve_t *)pending_list;
|
fclient->next = (fserve_t *)pending_list;
|
||||||
pending_list = fclient;
|
pending_list = fclient;
|
||||||
if (run_fserv == 0)
|
if (run_fserv == 0)
|
||||||
@ -631,7 +633,7 @@ static void fserve_add_pending (fserve_t *fclient)
|
|||||||
DEBUG0 ("fserve handler waking up");
|
DEBUG0 ("fserve handler waking up");
|
||||||
thread_create("File Serving Thread", fserv_thread_function, NULL, THREAD_DETACHED);
|
thread_create("File Serving Thread", fserv_thread_function, NULL, THREAD_DETACHED);
|
||||||
}
|
}
|
||||||
thread_mutex_unlock (&pending_lock);
|
thread_spin_unlock (&pending_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -758,10 +760,10 @@ void fserve_recheck_mime_types (ice_config_t *config)
|
|||||||
}
|
}
|
||||||
fclose(mimefile);
|
fclose(mimefile);
|
||||||
|
|
||||||
thread_mutex_lock (&pending_lock);
|
thread_spin_lock (&pending_lock);
|
||||||
if (mimetypes)
|
if (mimetypes)
|
||||||
avl_tree_free (mimetypes, _delete_mapping);
|
avl_tree_free (mimetypes, _delete_mapping);
|
||||||
mimetypes = new_mimetypes;
|
mimetypes = new_mimetypes;
|
||||||
thread_mutex_unlock (&pending_lock);
|
thread_spin_unlock (&pending_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,6 +195,7 @@ void thread_shutdown(void)
|
|||||||
avl_tree_free(_mutextree, _free_mutex);
|
avl_tree_free(_mutextree, _free_mutex);
|
||||||
#endif
|
#endif
|
||||||
avl_tree_free(_threadtree, _free_thread);
|
avl_tree_free(_threadtree, _free_thread);
|
||||||
|
_threadtree = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef THREAD_DEBUG
|
#ifdef THREAD_DEBUG
|
||||||
@ -222,6 +223,7 @@ static void _block_signals(void)
|
|||||||
sigdelset(&ss, SIGKILL);
|
sigdelset(&ss, SIGKILL);
|
||||||
sigdelset(&ss, SIGSTOP);
|
sigdelset(&ss, SIGSTOP);
|
||||||
sigdelset(&ss, SIGSEGV);
|
sigdelset(&ss, SIGSEGV);
|
||||||
|
sigdelset(&ss, SIGCHLD);
|
||||||
sigdelset(&ss, SIGBUS);
|
sigdelset(&ss, SIGBUS);
|
||||||
if (pthread_sigmask(SIG_BLOCK, &ss, NULL) != 0) {
|
if (pthread_sigmask(SIG_BLOCK, &ss, NULL) != 0) {
|
||||||
#ifdef THREAD_DEBUG
|
#ifdef THREAD_DEBUG
|
||||||
@ -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;
|
pthread_rwlock_t sys_rwlock;
|
||||||
} rwlock_t;
|
} 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_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_create(x) thread_mutex_create_c(x,__LINE__,__FILE__)
|
||||||
#define thread_mutex_lock(x) thread_mutex_lock_c(x,__LINE__,__FILE__)
|
#define thread_mutex_lock(x) thread_mutex_lock_c(x,__LINE__,__FILE__)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user