[xiph-commits] r10022 - icecast/branches/kh/thread

karl at svn.xiph.org karl at svn.xiph.org
Fri Sep 16 15:04:47 PDT 2005


Author: karl
Date: 2005-09-16 15:04:44 -0700 (Fri, 16 Sep 2005)
New Revision: 10022

Modified:
   icecast/branches/kh/thread/thread.c
   icecast/branches/kh/thread/thread.h
Log:
checkin compile conditional work, reduce stack allocations to keep in sync with trunk


Modified: icecast/branches/kh/thread/thread.c
===================================================================
--- icecast/branches/kh/thread/thread.c	2005-09-16 21:29:49 UTC (rev 10021)
+++ icecast/branches/kh/thread/thread.c	2005-09-16 22:04:44 UTC (rev 10022)
@@ -28,15 +28,12 @@
 #include <time.h>
 #include <sys/types.h>
 
-#include <pthread.h>
-
 #ifndef _WIN32
 #include <unistd.h>
 #include <sys/time.h>
 #else
 #include <windows.h>
 #include <winbase.h>
-#include <implement.h>
 #endif
 
 #include <signal.h>
@@ -68,6 +65,7 @@
 #define LOG_INFO5(y, z1, z2, z3, z4, z5) log_write(_logid, 3, CATMODULE "/", __FUNCTION__, y, z1, z2, z3, z4, z5)
 
 #define LOG_DEBUG(y) log_write(_logid, 4, CATMODULE "/", __FUNCTION__, y)
+#define LOG_DEBUG1(y, z1) log_write(_logid, 4, CATMODULE "/", __FUNCTION__, y, z1)
 #define LOG_DEBUG2(y, z1, z2) log_write(_logid, 4, CATMODULE "/", __FUNCTION__, y, z1, z2)
 #define LOG_DEBUG3(y, z1, z2, z3) log_write(_logid, 4, CATMODULE "/", __FUNCTION__, y, z1, z2, z3)
 #define LOG_DEBUG4(y, z1, z2, z3, z4) log_write(_logid, 4, CATMODULE "/", __FUNCTION__, y, z1, z2, z3, z4)
@@ -112,12 +110,9 @@
 static long _next_mutex_id = 0;
 static avl_tree *_mutextree = NULL;
 
-static mutex_t _threadtree_mutex = { -1, "unset", MUTEX_STATE_UNINIT,
-    (unsigned long long)0, NULL, -1, PTHREAD_MUTEX_INITIALIZER};
-static mutex_t _mutextree_mutex = { -1, "unset", MUTEX_STATE_UNINIT,
-    (unsigned long long)0, NULL, -1, PTHREAD_MUTEX_INITIALIZER};
-static mutex_t _library_mutex = { -1, NULL, MUTEX_STATE_UNINIT,
-    (unsigned long long)0, NULL, -1, PTHREAD_MUTEX_INITIALIZER};
+static mutex_t _threadtree_mutex;
+static mutex_t _mutextree_mutex;
+static mutex_t _library_mutex;
 
 static int _compare_mutexes(void *compare_arg, void *a, void *b);
 static int _free_mutex(void *key);
@@ -301,6 +296,7 @@
         start->arg = arg;
         start->thread = thread;
 
+        pthread_attr_setstacksize (&attr, 512*1024);
         pthread_attr_setinheritsched (&attr, PTHREAD_INHERIT_SCHED);
         if (detached)
         {
@@ -363,10 +359,10 @@
     pthread_mutex_destroy(&mutex->sys_mutex);
 
 #ifdef THREAD_DEBUG
-    free (mutex->file);
     _mutex_lock(&_mutextree_mutex);
     avl_delete(_mutextree, mutex, _free_mutex);
     _mutex_unlock(&_mutextree_mutex);
+    free (mutex->name);
 #endif
 }
 
@@ -435,29 +431,46 @@
     pthread_mutex_unlock(&cond->cond_mutex);
 }
 
-void thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file)
+void thread_rwlock_create_c(const char *name, rwlock_t *rwlock, int line, const char *file)
 {
     pthread_rwlock_init(&rwlock->sys_rwlock, NULL);
+#ifdef THREAD_DEBUG
+    rwlock->name = strdup (name);
+    LOG_DEBUG3 ("rwlock %s created (%s:%d)", rwlock->name, file, line);
+#endif
 }
 
 void thread_rwlock_destroy(rwlock_t *rwlock)
 {
     pthread_rwlock_destroy(&rwlock->sys_rwlock);
+#ifdef THREAD_DEBUG
+    LOG_DEBUG1 ("rwlock %s destroyed", rwlock->name);
+    free (rwlock->name);
+#endif
 }
 
-void thread_rwlock_rlock_c(rwlock_t *rwlock, int line, char *file)
+void thread_rwlock_rlock_c(rwlock_t *rwlock, int line, const char *file)
 {
+#ifdef THREAD_DEBUG
+    LOG_DEBUG3("rLock on %s requested at %s:%d", rwlock->name, file, line);
+#endif
     pthread_rwlock_rdlock(&rwlock->sys_rwlock);
 }
 
-void thread_rwlock_wlock_c(rwlock_t *rwlock, int line, char *file)
+void thread_rwlock_wlock_c(rwlock_t *rwlock, int line, const char *file)
 {
+#ifdef THREAD_DEBUG
+    LOG_DEBUG3("wLock on %s requested at %s:%d", rwlock->name, file, line);
+#endif
     pthread_rwlock_wrlock(&rwlock->sys_rwlock);
 }
 
-void thread_rwlock_unlock_c(rwlock_t *rwlock, int line, char *file)
+void thread_rwlock_unlock_c(rwlock_t *rwlock, int line, const char *file)
 {
     pthread_rwlock_unlock(&rwlock->sys_rwlock);
+#ifdef THREAD_DEBUG
+    LOG_DEBUG3 ("rwlock %s, at %s:%d", rwlock->name, file, line);
+#endif
 }
 
 void thread_exit_c(long val, int line, char *file)
@@ -487,7 +500,7 @@
     }
 #endif
 #ifdef __OpenBSD__
-    thread->running = 0;
+    th->running = 0;
 #endif
 
     if (th && th->detached)
@@ -563,7 +576,7 @@
     (start_routine)(real_arg);
 
 #ifdef __OpenBSD__
-    thread->running = 0;
+    th->running = 0;
 #endif
 
     if (thread->detached)

Modified: icecast/branches/kh/thread/thread.h
===================================================================
--- icecast/branches/kh/thread/thread.h	2005-09-16 21:29:49 UTC (rev 10021)
+++ icecast/branches/kh/thread/thread.h	2005-09-16 22:04:44 UTC (rev 10022)
@@ -91,6 +91,9 @@
     long thread_id;
     char *file;
     int line;
+
+    /* time the lock was taken */
+    unsigned long long lock_start;
 #endif
 
     pthread_rwlock_t sys_rwlock;
@@ -105,7 +108,7 @@
 #define thread_cond_broadcast(x) thread_cond_broadcast_c(x,__LINE__,__FILE__)
 #define thread_cond_wait(x) thread_cond_wait_c(x,__LINE__,__FILE__)
 #define thread_cond_timedwait(x,t) thread_cond_wait_c(x,t,__LINE__,__FILE__)
-#define thread_rwlock_create(x) thread_rwlock_create_c(x,__LINE__,__FILE__)
+#define thread_rwlock_create(x) thread_rwlock_create_c(__FILE__,(x),__LINE__,__FILE__)
 #define thread_rwlock_rlock(x) thread_rwlock_rlock_c(x,__LINE__,__FILE__)
 #define thread_rwlock_wlock(x) thread_rwlock_wlock_c(x,__LINE__,__FILE__)
 #define thread_rwlock_unlock(x) thread_rwlock_unlock_c(x,__LINE__,__FILE__)
@@ -164,10 +167,10 @@
 void thread_cond_wait_c(cond_t *cond, int line, char *file);
 void thread_cond_timedwait_c(cond_t *cond, int millis, int line, char *file);
 void thread_cond_destroy(cond_t *cond);
-void thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file);
-void thread_rwlock_rlock_c(rwlock_t *rwlock, int line, char *file);
-void thread_rwlock_wlock_c(rwlock_t *rwlock, int line, char *file);
-void thread_rwlock_unlock_c(rwlock_t *rwlock, int line, char *file);
+void thread_rwlock_create_c(const char *name, rwlock_t *rwlock, int line, const char *file);
+void thread_rwlock_rlock_c(rwlock_t *rwlock, int line, const char *file);
+void thread_rwlock_wlock_c(rwlock_t *rwlock, int line, const char *file);
+void thread_rwlock_unlock_c(rwlock_t *rwlock, int line, const char *file);
 void thread_rwlock_destroy(rwlock_t *rwlock);
 void thread_exit_c(long val, int line, char *file);
 



More information about the commits mailing list