#ifndef __THREADS_H__
#define __THREADS_H__
-typedef struct event {
- int foo;
-} event_t;
-
-
#ifdef HAVE_MINGW
typedef HANDLE thread_t;
typedef CRITICAL_SECTION mutex_t;
typedef pthread_t thread_t;
typedef pthread_mutex_t mutex_t;
-static inline void thread_create(thread_t *tid, void (*func)(void *), void *arg) {
- return !pthread_create(tid, NULL, (void *(*)(void *))func, arg);
+static inline bool thread_create(thread_t *tid, void (*func)(void *), void *arg) {
+ bool result;
+
+ sigset_t old, block;
+ sigfillset(&block);
+ pthread_sigmask(SIG_SETMASK, &block, &old);
+ result = pthread_create(tid, NULL, (void *(*)(void *))func, arg);
+ pthread_sigmask(SIG_SETMASK, &old, NULL);
+ return !result;
}
static inline void thread_destroy(thread_t *tid) {
- pthread_join(tid);
+ pthread_cancel(*tid);
+ pthread_join(*tid, NULL);
}
static inline void mutex_create(mutex_t *mutex) {
pthread_mutex_init(mutex, NULL);
}
+#if 1
+#define mutex_lock(m) logger(LOG_DEBUG, "mutex_lock() at " __FILE__ " line %d", __LINE__); pthread_mutex_lock(m)
+#define mutex_unlock(m) logger(LOG_DEBUG, "mutex_unlock() at " __FILE__ " line %d", __LINE__); pthread_mutex_unlock(m)
+#else
static inline void mutex_lock(mutex_t *mutex) {
pthread_mutex_lock(mutex);
}
pthread_mutex_unlock(mutex);
}
#endif
+#endif
#endif