[Icecast-dev] [PATCH 02/31] introduce thread_cond_init and refrase thread_cond_create.

Niv Sardi nsardi at smartjog.com
Fri Jul 30 07:54:24 PDT 2010


thread_cond_create doesn't actually create a new thread cond (it calls pthread_cond_init).
Make it actually alloc a new cond structure (that will have to be freed with free()), and
add thread_cond_init retaining old behaviour.

Implement change in connection.c

Signed-off-by: Niv Sardi <nsardi at smartjog.com>
---
 src/connection.c    |    2 +-
 src/thread/thread.c |   13 ++++++++++++-
 src/thread/thread.h |    5 +++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 5cc922a..97fe7e9 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -144,7 +144,7 @@ void connection_initialize(void)
     thread_spin_create (&_connection_lock);
     thread_mutex_create(&move_clients_mutex);
     thread_rwlock_create(&_source_shutdown_rwlock);
-    thread_cond_create(&global.shutdown_cond);
+    thread_cond_init(&global.shutdown_cond);
     _req_queue = NULL;
     _req_queue_tail = &_req_queue;
     _con_queue = NULL;
diff --git a/src/thread/thread.c b/src/thread/thread.c
index deeb695..e5e0ac6 100644
--- a/src/thread/thread.c
+++ b/src/thread/thread.c
@@ -493,12 +493,23 @@ void thread_mutex_unlock_c(mutex_t *mutex, int line, char *file)
 #endif /* DEBUG_MUTEXES */
 }
 
-void thread_cond_create_c(cond_t *cond, int line, char *file)
+void thread_cond_init(cond_t *cond)
 {
     pthread_cond_init(&cond->sys_cond, NULL);
     pthread_mutex_init(&cond->cond_mutex, NULL);
 }
 
+cond_t *thread_cond_create(void)
+{
+    cond_t *cond = calloc (1, sizeof(cond_t));
+    if (!cond)
+        return;
+
+    thread_cond_init(cond);
+
+    return cond;
+}
+
 void thread_cond_destroy(cond_t *cond)
 {
     pthread_mutex_destroy(&cond->cond_mutex);
diff --git a/src/thread/thread.h b/src/thread/thread.h
index fe4e4a0..1484ff7 100644
--- a/src/thread/thread.h
+++ b/src/thread/thread.h
@@ -111,7 +111,7 @@ typedef mutex_t spin_t;
 #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_unlock(x) thread_mutex_unlock_c(x,__LINE__,__FILE__)
-#define thread_cond_create(x) thread_cond_create_c(x,__LINE__,__FILE__)
+//#define thread_cond_create() thread_cond_create_c(__LINE__,__FILE__)
 #define thread_cond_signal(x) thread_cond_signal_c(x,__LINE__,__FILE__)
 #define thread_cond_broadcast(x) thread_cond_broadcast_c(x,__LINE__,__FILE__)
 #define thread_cond_wait(x) thread_cond_wait_c(x,__LINE__,__FILE__)
@@ -169,7 +169,8 @@ void thread_mutex_create_c(mutex_t *mutex, int line, char *file);
 void thread_mutex_lock_c(mutex_t *mutex, int line, char *file);
 void thread_mutex_unlock_c(mutex_t *mutex, int line, char *file);
 void thread_mutex_destroy(mutex_t *mutex);
-void thread_cond_create_c(cond_t *cond, int line, char *file);
+void thread_cond_init(cond_t *cond);
+cond_t *thread_cond_create(void);
 void thread_cond_signal_c(cond_t *cond, int line, char *file);
 void thread_cond_broadcast_c(cond_t *cond, int line, char *file);
 void thread_cond_wait_c(cond_t *cond, int line, char *file);
-- 
1.7.1



More information about the Icecast-dev mailing list