mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-12-04 14:46:30 -05:00
Make various thread structures omit the bits only used in debug mode.
Some of these are pretty heavily used, so saving 10-20 bytes each can be quite significant. No functional differences. svn path=/trunk/thread/; revision=4401
This commit is contained in:
parent
81f9551da0
commit
4c08a155c7
@ -84,26 +84,44 @@ typedef struct thread_start_tag {
|
|||||||
pthread_t sys_thread;
|
pthread_t sys_thread;
|
||||||
} thread_start_t;
|
} thread_start_t;
|
||||||
|
|
||||||
static int _logid = -1;
|
|
||||||
static long _next_thread_id = 0;
|
static long _next_thread_id = 0;
|
||||||
static int _initialized = 0;
|
static int _initialized = 0;
|
||||||
static avl_tree *_threadtree = NULL;
|
static avl_tree *_threadtree = NULL;
|
||||||
|
|
||||||
|
#ifdef DEBUG_MUTEXES
|
||||||
static mutex_t _threadtree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
|
static mutex_t _threadtree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
|
||||||
PTHREAD_MUTEX_INITIALIZER};
|
PTHREAD_MUTEX_INITIALIZER};
|
||||||
|
#else
|
||||||
|
static mutex_t _threadtree_mutex = { PTHREAD_MUTEX_INITIALIZER };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEBUG_MUTEXES
|
||||||
|
static int _logid = -1;
|
||||||
static long _next_mutex_id = 0;
|
static long _next_mutex_id = 0;
|
||||||
|
|
||||||
static avl_tree *_mutextree = NULL;
|
static avl_tree *_mutextree = NULL;
|
||||||
static mutex_t _mutextree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
|
static mutex_t _mutextree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
|
||||||
PTHREAD_MUTEX_INITIALIZER};
|
PTHREAD_MUTEX_INITIALIZER};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG_MUTEXES
|
||||||
static mutex_t _library_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
|
static mutex_t _library_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
|
||||||
PTHREAD_MUTEX_INITIALIZER};
|
PTHREAD_MUTEX_INITIALIZER};
|
||||||
|
#else
|
||||||
|
static mutex_t _library_mutex = { PTHREAD_MUTEX_INITIALIZER };
|
||||||
|
#endif
|
||||||
|
|
||||||
/* INTERNAL FUNCTIONS */
|
/* INTERNAL FUNCTIONS */
|
||||||
|
|
||||||
/* avl tree functions */
|
/* avl tree functions */
|
||||||
|
#ifdef DEBUG_MUTEXES
|
||||||
static int _compare_mutexes(void *compare_arg, void *a, void *b);
|
static int _compare_mutexes(void *compare_arg, void *a, void *b);
|
||||||
static int _compare_threads(void *compare_arg, void *a, void *b);
|
|
||||||
static int _free_mutex(void *key);
|
static int _free_mutex(void *key);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int _compare_threads(void *compare_arg, void *a, void *b);
|
||||||
static int _free_thread(void *key);
|
static int _free_thread(void *key);
|
||||||
static int _free_thread_if_detached(void *key);
|
static int _free_thread_if_detached(void *key);
|
||||||
|
|
||||||
@ -131,6 +149,7 @@ void thread_initialize(void)
|
|||||||
log_set_level(_logid, THREAD_DEBUG);
|
log_set_level(_logid, THREAD_DEBUG);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG_MUTEXES
|
||||||
/* create all the internal mutexes, and initialize the mutex tree */
|
/* create all the internal mutexes, and initialize the mutex tree */
|
||||||
|
|
||||||
_mutextree = avl_tree_new(_compare_mutexes, NULL);
|
_mutextree = avl_tree_new(_compare_mutexes, NULL);
|
||||||
@ -140,7 +159,6 @@ void thread_initialize(void)
|
|||||||
*/
|
*/
|
||||||
_mutex_create(&_mutextree_mutex);
|
_mutex_create(&_mutextree_mutex);
|
||||||
|
|
||||||
#ifdef DEBUG_MUTEXES
|
|
||||||
_mutextree_mutex.mutex_id = _next_mutex_id++;
|
_mutextree_mutex.mutex_id = _next_mutex_id++;
|
||||||
avl_insert(_mutextree, (void *)&_mutextree_mutex);
|
avl_insert(_mutextree, (void *)&_mutextree_mutex);
|
||||||
#endif
|
#endif
|
||||||
@ -173,9 +191,11 @@ void thread_shutdown(void)
|
|||||||
if (_initialized == 1) {
|
if (_initialized == 1) {
|
||||||
thread_mutex_destroy(&_library_mutex);
|
thread_mutex_destroy(&_library_mutex);
|
||||||
thread_mutex_destroy(&_threadtree_mutex);
|
thread_mutex_destroy(&_threadtree_mutex);
|
||||||
|
#ifdef THREAD_DEBUG
|
||||||
thread_mutex_destroy(&_mutextree_mutex);
|
thread_mutex_destroy(&_mutextree_mutex);
|
||||||
|
|
||||||
avl_tree_free(_mutextree, _free_mutex);
|
avl_tree_free(_mutextree, _free_mutex);
|
||||||
|
#endif
|
||||||
avl_tree_free(_threadtree, _free_thread);
|
avl_tree_free(_threadtree, _free_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,8 +310,10 @@ thread_type *thread_create_c(char *name, void *(*start_routine)(void *),
|
|||||||
*/
|
*/
|
||||||
static void _mutex_create(mutex_t *mutex)
|
static void _mutex_create(mutex_t *mutex)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_MUTEXES
|
||||||
mutex->thread_id = MUTEX_STATE_NEVERLOCKED;
|
mutex->thread_id = MUTEX_STATE_NEVERLOCKED;
|
||||||
mutex->line = -1;
|
mutex->line = -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
pthread_mutex_init(&mutex->sys_mutex, NULL);
|
pthread_mutex_init(&mutex->sys_mutex, NULL);
|
||||||
}
|
}
|
||||||
@ -497,8 +519,6 @@ void thread_cond_wait_c(cond_t *cond, int line, char *file)
|
|||||||
pthread_mutex_unlock(&cond->cond_mutex);
|
pthread_mutex_unlock(&cond->cond_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rwlocknum = 0;
|
|
||||||
|
|
||||||
void thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file)
|
void thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file)
|
||||||
{
|
{
|
||||||
pthread_rwlock_init(&rwlock->sys_rwlock, NULL);
|
pthread_rwlock_init(&rwlock->sys_rwlock, NULL);
|
||||||
@ -719,6 +739,7 @@ void thread_join(thread_type *thread)
|
|||||||
|
|
||||||
/* AVL tree functions */
|
/* AVL tree functions */
|
||||||
|
|
||||||
|
#ifdef DEBUG_MUTEXES
|
||||||
static int _compare_mutexes(void *compare_arg, void *a, void *b)
|
static int _compare_mutexes(void *compare_arg, void *a, void *b)
|
||||||
{
|
{
|
||||||
mutex_t *m1, *m2;
|
mutex_t *m1, *m2;
|
||||||
@ -732,6 +753,7 @@ static int _compare_mutexes(void *compare_arg, void *a, void *b)
|
|||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int _compare_threads(void *compare_arg, void *a, void *b)
|
static int _compare_threads(void *compare_arg, void *a, void *b)
|
||||||
{
|
{
|
||||||
@ -747,6 +769,7 @@ static int _compare_threads(void *compare_arg, void *a, void *b)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_MUTEXES
|
||||||
static int _free_mutex(void *key)
|
static int _free_mutex(void *key)
|
||||||
{
|
{
|
||||||
mutex_t *m;
|
mutex_t *m;
|
||||||
@ -762,6 +785,7 @@ static int _free_mutex(void *key)
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int _free_thread(void *key)
|
static int _free_thread(void *key)
|
||||||
{
|
{
|
||||||
|
@ -46,6 +46,7 @@ typedef struct thread_tag {
|
|||||||
} thread_type;
|
} thread_type;
|
||||||
|
|
||||||
typedef struct mutex_tag {
|
typedef struct mutex_tag {
|
||||||
|
#ifdef DEBUG_MUTEXES
|
||||||
/* the local id and name of the mutex */
|
/* the local id and name of the mutex */
|
||||||
long mutex_id;
|
long mutex_id;
|
||||||
char *name;
|
char *name;
|
||||||
@ -57,19 +58,24 @@ typedef struct mutex_tag {
|
|||||||
char *file;
|
char *file;
|
||||||
int line;
|
int line;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* the system specific mutex */
|
/* the system specific mutex */
|
||||||
pthread_mutex_t sys_mutex;
|
pthread_mutex_t sys_mutex;
|
||||||
} mutex_t;
|
} mutex_t;
|
||||||
|
|
||||||
typedef struct cond_tag {
|
typedef struct cond_tag {
|
||||||
|
#ifdef THREAD_DEBUG
|
||||||
long cond_id;
|
long cond_id;
|
||||||
char *name;
|
char *name;
|
||||||
|
#endif
|
||||||
|
|
||||||
pthread_mutex_t cond_mutex;
|
pthread_mutex_t cond_mutex;
|
||||||
pthread_cond_t sys_cond;
|
pthread_cond_t sys_cond;
|
||||||
} cond_t;
|
} cond_t;
|
||||||
|
|
||||||
typedef struct rwlock_tag {
|
typedef struct rwlock_tag {
|
||||||
|
#ifdef THREAD_DEBUG
|
||||||
long rwlock_id;
|
long rwlock_id;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
@ -79,6 +85,7 @@ typedef struct rwlock_tag {
|
|||||||
long thread_id;
|
long thread_id;
|
||||||
char *file;
|
char *file;
|
||||||
int line;
|
int line;
|
||||||
|
#endif
|
||||||
|
|
||||||
pthread_rwlock_t sys_rwlock;
|
pthread_rwlock_t sys_rwlock;
|
||||||
} rwlock_t;
|
} rwlock_t;
|
||||||
|
Loading…
Reference in New Issue
Block a user