aboutsummaryrefslogtreecommitdiffstats
path: root/cthread.h
blob: c3af6643a84bb41f214fbc906f6a01f1dd8e1538 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef __CTHREAD
#define __CTHREAD

#ifndef EXTERNALPROTO

#ifdef _WINDOWS
typedef void *CThread_thread_t;
typedef DWORD CThread_func_return_t;
typedef LPVOID CThread_func_arg_t;
typedef CRITICAL_SECTION CThread_mutex_t;
typedef HANDLE EVENT;
typedef DWORD EVENT_TIME;
#else

typedef struct {
	pthread_mutex_t mutex;
	pthread_cond_t condition;
	int ready_to_go;
} UNIX_EVENT;

typedef unsigned long EVENT_TIME;
typedef UNIX_EVENT EVENT;
typedef pthread_t CThread_thread_t;
typedef void *CThread_func_return_t;
typedef void *CThread_func_arg_t;
typedef pthread_mutex_t CThread_mutex_t;
#endif
typedef CThread_func_return_t(* CThread_func_t)(CThread_func_arg_t);

typedef struct {
	CThread_thread_t m_ThreadHandle;
	unsigned long m_ThreadIdentifier;
	unsigned char thread_status;
#ifdef _MACOSX
	CFRunLoopRef runLoop;
	unsigned char macInitDone;
#endif
} CThread;

int CThread_create(CThread *cp, CThread_func_t fp, CThread_func_arg_t arg);
int CThread_create_detached(CThread *cp, CThread_func_t fp, CThread_func_arg_t arg);
void CThread_join(CThread *cp);
//void CThread_kill(CThread *cp);
int CThread_is_my_thread(CThread cp);
int CThread_mutex_init(CThread_mutex_t *);
int CThread_mutex_destroy(CThread_mutex_t *mp);
void CThread_mutex_lock(CThread_mutex_t *mp);
void CThread_mutex_unlock(CThread_mutex_t *mp);

void CThread_set_event(EVENT *ev);
void CThread_reset_event(EVENT *ev);
int CThread_wait_on_event(EVENT *ev, EVENT_TIME time);
void CThread_create_event(EVENT *ev);
int CThread_destroy_event(EVENT *ev);

int RegisterLocalDevice(CPhidgetHandle phid);
int StartCentralThread();
int JoinCentralThread();

CThread_func_return_t ReadThreadFunction(CThread_func_arg_t arg);
CThread_func_return_t WriteThreadFunction(CThread_func_arg_t arg);

#endif
#endif