#ifndef THREAD_H #define THREAD_H /*#include */ #define THREAD_IDLE 0 #define THREAD_RUN 1 #define THREAD_DONE 2 #ifdef __cplusplus extern "C" { #endif typedef struct lock_ lock; typedef struct thread_pool_ thread_pool; extern lock *lock_create(void); extern void lock_lock(lock *l); extern void lock_unlock(lock *l); extern void lock_destroy(lock *l); #ifndef _WIN32 int lock_trylock(lock *l); #endif extern int atomic_inc(int *v); // return pre-value extern int atomic_dec(int *v); // return post-value extern int atomic_dec_and_zero(int *v, int *v2); /*extern int64_t atomic_add64(int64_t *v, int n); // return pre-value*/ /*extern uint64_t atomic_addu64(uint64_t *v, int n); // return pre-value*/ // Run a supplied function as a one-off detached thread. The // thread will be destroyed after this single use. extern void * thread_run(void * (*f)(void*), void *data); extern int thread_exit(int * status, int timeout); extern void thread_stop(int * status); extern int thread_join(void * handle, int * status, int timeout); extern int thread_join_with_cond(void * handle, void * cond, int * status, int timeout); // Run a supplied function from a pool of threads. The thread // will be returned to the pool for fast re-use when needed. extern thread_pool *tpool_create(int threads); extern int tpool_start(thread_pool *tp, void * (*f)(void*), void *data); extern void tpool_destroy(thread_pool *tp); void * thread_create_cond(); void thread_release_cond(void * handle); int thread_send_signal(void * handle); int thread_wait_signal(void * handle); #ifdef __cplusplus } #endif #endif