[xiph-cvs] cvs commit: thread thread.c thread.h
Michael Smith
msmith at xiph.org
Tue Mar 4 07:31:34 PST 2003
msmith 03/03/04 10:31:34
Modified: . thread.c thread.h
Log:
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.
Revision Changes Path
1.20 +29 -5 thread/thread.c
Index: thread.c
===================================================================
RCS file: /usr/local/cvsroot/thread/thread.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- thread.c 17 Jan 2003 09:01:04 -0000 1.19
+++ thread.c 4 Mar 2003 15:31:34 -0000 1.20
@@ -84,26 +84,44 @@
pthread_t sys_thread;
} thread_start_t;
-static int _logid = -1;
static long _next_thread_id = 0;
static int _initialized = 0;
static avl_tree *_threadtree = NULL;
+
+#ifdef DEBUG_MUTEXES
static mutex_t _threadtree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
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 avl_tree *_mutextree = NULL;
static mutex_t _mutextree_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
PTHREAD_MUTEX_INITIALIZER};
+#endif
+
+#ifdef DEBUG_MUTEXES
static mutex_t _library_mutex = { -1, NULL, MUTEX_STATE_UNINIT, NULL, -1,
PTHREAD_MUTEX_INITIALIZER};
+#else
+static mutex_t _library_mutex = { PTHREAD_MUTEX_INITIALIZER };
+#endif
/* INTERNAL FUNCTIONS */
/* avl tree functions */
+#ifdef DEBUG_MUTEXES
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);
+#endif
+
+static int _compare_threads(void *compare_arg, void *a, void *b);
static int _free_thread(void *key);
static int _free_thread_if_detached(void *key);
@@ -131,6 +149,7 @@
log_set_level(_logid, THREAD_DEBUG);
#endif
+#ifdef DEBUG_MUTEXES
/* create all the internal mutexes, and initialize the mutex tree */
_mutextree = avl_tree_new(_compare_mutexes, NULL);
@@ -140,7 +159,6 @@
*/
_mutex_create(&_mutextree_mutex);
-#ifdef DEBUG_MUTEXES
_mutextree_mutex.mutex_id = _next_mutex_id++;
avl_insert(_mutextree, (void *)&_mutextree_mutex);
#endif
@@ -173,9 +191,11 @@
if (_initialized == 1) {
thread_mutex_destroy(&_library_mutex);
thread_mutex_destroy(&_threadtree_mutex);
+#ifdef THREAD_DEBUG
thread_mutex_destroy(&_mutextree_mutex);
avl_tree_free(_mutextree, _free_mutex);
+#endif
avl_tree_free(_threadtree, _free_thread);
}
@@ -290,8 +310,10 @@
*/
static void _mutex_create(mutex_t *mutex)
{
+#ifdef DEBUG_MUTEXES
mutex->thread_id = MUTEX_STATE_NEVERLOCKED;
mutex->line = -1;
+#endif
pthread_mutex_init(&mutex->sys_mutex, NULL);
}
@@ -497,8 +519,6 @@
pthread_mutex_unlock(&cond->cond_mutex);
}
-static int rwlocknum = 0;
-
void thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file)
{
pthread_rwlock_init(&rwlock->sys_rwlock, NULL);
@@ -719,6 +739,7 @@
/* AVL tree functions */
+#ifdef DEBUG_MUTEXES
static int _compare_mutexes(void *compare_arg, void *a, void *b)
{
mutex_t *m1, *m2;
@@ -732,6 +753,7 @@
return -1;
return 0;
}
+#endif
static int _compare_threads(void *compare_arg, void *a, void *b)
{
@@ -747,6 +769,7 @@
return 0;
}
+#ifdef DEBUG_MUTEXES
static int _free_mutex(void *key)
{
mutex_t *m;
@@ -762,6 +785,7 @@
return 1;
}
+#endif
static int _free_thread(void *key)
{
<p><p>1.9 +7 -0 thread/thread.h
Index: thread.h
===================================================================
RCS file: /usr/local/cvsroot/thread/thread.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- thread.h 29 Dec 2002 09:55:50 -0000 1.8
+++ thread.h 4 Mar 2003 15:31:34 -0000 1.9
@@ -46,6 +46,7 @@
} thread_type;
typedef struct mutex_tag {
+#ifdef DEBUG_MUTEXES
/* the local id and name of the mutex */
long mutex_id;
char *name;
@@ -57,19 +58,24 @@
char *file;
int line;
+#endif
+
/* the system specific mutex */
pthread_mutex_t sys_mutex;
} mutex_t;
typedef struct cond_tag {
+#ifdef THREAD_DEBUG
long cond_id;
char *name;
+#endif
pthread_mutex_t cond_mutex;
pthread_cond_t sys_cond;
} cond_t;
typedef struct rwlock_tag {
+#ifdef THREAD_DEBUG
long rwlock_id;
char *name;
@@ -79,6 +85,7 @@
long thread_id;
char *file;
int line;
+#endif
pthread_rwlock_t sys_rwlock;
} rwlock_t;
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list