Browse Source

enough with the glib threading nonsense, it's only causing problems. revert to good old pthread stuff

git.mgm/mediaproxy-ng/2.1
Richard Fuchs 14 years ago
parent
commit
a4625fbad9
3 changed files with 47 additions and 52 deletions
  1. +26
    -4
      daemon/aux.c
  2. +20
    -47
      daemon/aux.h
  3. +1
    -1
      daemon/poller.c

+ 26
- 4
daemon/aux.c View File

@ -3,6 +3,7 @@
#include <glib.h> #include <glib.h>
#include <pcre.h> #include <pcre.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h>
#include "aux.h" #include "aux.h"
@ -119,19 +120,24 @@ void g_queue_clear(GQueue *q) {
void thread_join_me() { void thread_join_me() {
pthread_t *me;
me = g_slice_alloc(sizeof(*me));
*me = pthread_self();
mutex_lock(&threads_to_join_lock); mutex_lock(&threads_to_join_lock);
threads_to_join = g_slist_prepend(threads_to_join, g_thread_self());
threads_to_join = g_slist_prepend(threads_to_join, me);
mutex_unlock(&threads_to_join_lock); mutex_unlock(&threads_to_join_lock);
} }
void threads_join_all() { void threads_join_all() {
GThread *t;
pthread_t *t;
mutex_lock(&threads_to_join_lock); mutex_lock(&threads_to_join_lock);
while (threads_to_join) { while (threads_to_join) {
t = threads_to_join->data; t = threads_to_join->data;
g_thread_join(t);
pthread_join(*t, NULL);
threads_to_join = g_slist_delete_link(threads_to_join, threads_to_join); threads_to_join = g_slist_delete_link(threads_to_join, threads_to_join);
g_slice_free1(sizeof(*t), t);
} }
mutex_unlock(&threads_to_join_lock); mutex_unlock(&threads_to_join_lock);
} }
@ -145,6 +151,22 @@ static gpointer thread_detach_func(gpointer d) {
return NULL; return NULL;
} }
int thread_create(void *(*func)(void *), void *arg, int joinable, pthread_t *handle) {
pthread_attr_t att;
pthread_t thr;
int ret;
if (pthread_attr_init(&att))
abort();
if (pthread_attr_setdetachstate(&att, joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED))
abort();
ret = pthread_create(&thr, &att, func, arg);
pthread_attr_destroy(&att);
if (!ret && handle)
*handle = thr;
return ret;
}
void thread_create_detach(void (*f)(void *), void *d) { void thread_create_detach(void (*f)(void *), void *d) {
struct detach_thread *dt; struct detach_thread *dt;
@ -152,6 +174,6 @@ void thread_create_detach(void (*f)(void *), void *d) {
dt->func = f; dt->func = f;
dt->data = d; dt->data = d;
if (!g_thread_create(thread_detach_func, dt, TRUE, NULL))
if (thread_create(thread_detach_func, dt, 1, NULL))
abort(); abort();
} }

+ 20
- 47
daemon/aux.h View File

@ -12,6 +12,7 @@
#include <pcre.h> #include <pcre.h>
#include <stdarg.h> #include <stdarg.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <pthread.h>
@ -146,60 +147,32 @@ static inline int smart_pton(int af, char *src, void *dst) {
#if !GLIB_CHECK_VERSION(2,32,0)
typedef pthread_mutex_t mutex_t;
typedef pthread_rwlock_t rwlock_t;
typedef pthread_cond_t cond_t;
typedef GStaticMutex mutex_t;
typedef GStaticRWLock rwlock_t;
typedef GCond *cond_t;
#define mutex_init(m) pthread_mutex_init(m, NULL)
#define mutex_destroy(m) pthread_mutex_destroy(m)
#define mutex_lock(m) pthread_mutex_lock(m)
#define mutex_trylock(m) pthread_mutex_trylock(m)
#define mutex_unlock(m) pthread_mutex_unlock(m)
#define MUTEX_STATIC_INIT PTHREAD_MUTEX_INITIALIZER
#define mutex_init(m) g_static_mutex_init(m)
#define mutex_destroy(m) g_static_mutex_free(m)
#define mutex_lock(m) g_static_mutex_lock(m)
#define mutex_trylock(m) g_static_mutex_trylock(m)
#define mutex_unlock(m) g_static_mutex_unlock(m)
#define MUTEX_STATIC_INIT G_STATIC_MUTEX_INIT
#define rwlock_init(l) g_static_rw_lock_init(l)
#define rwlock_lock_r(l) g_static_rw_lock_reader_lock(l)
#define rwlock_unlock_r(l) g_static_rw_lock_reader_unlock(l)
#define rwlock_lock_w(l) g_static_rw_lock_writer_lock(l)
#define rwlock_unlock_w(l) g_static_rw_lock_writer_unlock(l)
#define cond_init(c) *(c) = g_cond_new()
#define cond_wait(c,m) g_cond_wait(*(c),m)
#define cond_signal(c) g_cond_signal(*(c))
#define cond_broadcast(c) g_cond_broadcast(*(c))
#else
typedef GMutex mutex_t;
typedef GRWLock rwlock_t;
typedef GCond cond_t;
#define mutex_init(m) g_mutex_init(m)
#define mutex_destroy(m) g_mutex_clear(m)
#define mutex_lock(m) g_mutex_lock(m)
#define mutex_trylock(m) g_mutex_trylock(m)
#define mutex_unlock(m) g_mutex_unlock(m)
#define MUTEX_STATIC_INIT {0}
#define rwlock_init(l) g_rw_lock_init(l)
#define rwlock_lock_r(l) g_rw_lock_reader_lock(l)
#define rwlock_unlock_r(l) g_rw_lock_reader_unlock(l)
#define rwlock_lock_w(l) g_rw_lock_writer_lock(l)
#define rwlock_unlock_w(l) g_rw_lock_writer_unlock(l)
#define cond_init(c) g_cond_init(c)
#define cond_wait(c,m) g_cond_wait(c,m)
#define cond_signal(c) g_cond_signal(c)
#define cond_broadcast(c) g_cond_broadcast(c)
#endif
#define rwlock_init(l) pthread_rwlock_init(l, NULL)
#define rwlock_lock_r(l) pthread_rwlock_rdlock(l)
#define rwlock_unlock_r(l) pthread_rwlock_unlock(l)
#define rwlock_lock_w(l) pthread_rwlock_wrlock(l)
#define rwlock_unlock_w(l) pthread_rwlock_unlock(l)
#define cond_init(c) pthread_cond_init(c, NULL)
#define cond_wait(c,m) pthread_cond_wait(c,m)
#define cond_signal(c) pthread_cond_signal(c)
#define cond_broadcast(c) pthread_cond_broadcast(c)
void thread_join_me(); void thread_join_me();
void threads_join_all(); void threads_join_all();
int thread_create(void *(*)(void *), void *, int, pthread_t *);
void thread_create_detach(void (*)(void *), void *); void thread_create_detach(void (*)(void *), void *);


+ 1
- 1
daemon/poller.c View File

@ -459,7 +459,7 @@ static int poller_timer_link(struct poller *p, GSList **lp, void (*f)(void *), s
mutex_lock(&p->timers_add_del_lock); mutex_lock(&p->timers_add_del_lock);
*lp = g_slist_prepend(*lp, i); *lp = g_slist_prepend(*lp, i);
if (mutex_trylock(&p->timers_lock)) {
if (!mutex_trylock(&p->timers_lock)) {
poller_timers_mod(p); poller_timers_mod(p);
mutex_unlock(&p->timers_lock); mutex_unlock(&p->timers_lock);
} }


Loading…
Cancel
Save