2014-03-27 01:32:26 +00:00
|
|
|
#ifndef R_TH_H
|
|
|
|
#define R_TH_H
|
2009-07-21 11:13:24 +00:00
|
|
|
|
|
|
|
#include "r_types.h"
|
|
|
|
|
|
|
|
#define HAVE_PTHREAD 1
|
|
|
|
|
2010-01-15 12:02:54 +00:00
|
|
|
#if __WINDOWS__
|
2009-07-21 11:13:24 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
2010-01-15 12:02:54 +00:00
|
|
|
|
2010-03-25 09:18:59 +00:00
|
|
|
#undef HAVE_PTHREAD
|
|
|
|
#define HAVE_PTHREAD 0
|
2009-07-21 11:13:24 +00:00
|
|
|
#define R_TH_TID HANDLE
|
2010-03-25 09:18:59 +00:00
|
|
|
#define R_TH_LOCK_T PCRITICAL_SECTION
|
|
|
|
//HANDLE
|
2009-07-21 11:13:24 +00:00
|
|
|
|
2010-01-15 12:02:54 +00:00
|
|
|
#elif HAVE_PTHREAD
|
|
|
|
#define __GNU
|
|
|
|
#include <pthread.h>
|
|
|
|
#define R_TH_TID pthread_t
|
|
|
|
#define R_TH_LOCK_T pthread_mutex_t
|
|
|
|
|
2009-07-21 11:13:24 +00:00
|
|
|
#else
|
|
|
|
#error Threading library only supported for ptrace and w32
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define R_TH_FUNCTION(x) int (*x)(struct r_th_t *)
|
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
typedef struct r_th_lock_t {
|
2009-07-21 11:13:24 +00:00
|
|
|
int refs;
|
|
|
|
R_TH_LOCK_T lock;
|
2010-01-26 00:28:33 +00:00
|
|
|
} RThreadLock;
|
2009-07-21 11:13:24 +00:00
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
typedef struct r_th_t {
|
2010-01-15 12:02:54 +00:00
|
|
|
R_TH_TID tid;
|
2010-06-23 15:30:16 +00:00
|
|
|
RThreadLock *lock;
|
2009-07-21 11:13:24 +00:00
|
|
|
R_TH_FUNCTION(fun);
|
|
|
|
void *user; // user pointer
|
|
|
|
int running;
|
|
|
|
int breaked; // thread aims to be interruped
|
|
|
|
int delay; // delay the startup of the thread N seconds
|
|
|
|
int ready; // thread is properly setup
|
2010-01-26 00:28:33 +00:00
|
|
|
} RThread;
|
2009-07-21 11:13:24 +00:00
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
typedef struct r_th_pool_t {
|
2009-07-21 11:13:24 +00:00
|
|
|
int size;
|
2010-06-23 15:30:16 +00:00
|
|
|
RThread **threads;
|
2010-01-26 00:28:33 +00:00
|
|
|
} RThreadPool;
|
2009-07-21 11:13:24 +00:00
|
|
|
|
2009-12-24 02:17:53 +00:00
|
|
|
#ifdef R_API
|
2010-06-23 15:30:16 +00:00
|
|
|
R_API RThread *r_th_new(R_TH_FUNCTION(fun), void *user, int delay);
|
|
|
|
R_API int r_th_start(RThread *th, int enable);
|
|
|
|
R_API int r_th_wait(RThread *th);
|
|
|
|
R_API int r_th_wait_async(RThread *th);
|
|
|
|
R_API void r_th_break(RThread *th);
|
|
|
|
R_API int r_th_wait(RThread *th);
|
|
|
|
R_API void *r_th_free(RThread *th);
|
2009-07-21 11:13:24 +00:00
|
|
|
|
2010-06-23 15:30:16 +00:00
|
|
|
R_API RThreadLock *r_th_lock_new();
|
|
|
|
R_API int r_th_lock_wait(RThreadLock *th);
|
|
|
|
R_API int r_th_lock_check(RThreadLock *thl);
|
|
|
|
R_API int r_th_lock_enter(RThreadLock *thl);
|
|
|
|
R_API int r_th_lock_leave(RThreadLock *thl);
|
|
|
|
R_API void *r_th_lock_free(RThreadLock *thl);
|
2009-12-24 02:17:53 +00:00
|
|
|
#endif
|
2009-07-21 11:13:24 +00:00
|
|
|
|
2013-06-18 10:09:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-07-21 11:13:24 +00:00
|
|
|
#endif
|