/
Threads.h
80 lines (65 loc) · 3.14 KB
/
Threads.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Declarations for abstract thread support in BASIClib.
*
* Copyright (c) 1999 Ryan C. Gordon and Gregory S. Read.
*/
#ifndef _INCLUDE_STDBASIC_H_
# include "StdBasic.h"
#else
# ifndef _INCLUDE_THREADS_H_
# define _INCLUDE_THREADS_H_
# ifdef SINGLE_THREADED
typedef unsigned long ThreadLock;
typedef ThreadLock *PThreadLock;
# define __terminateCurrentThread vbp_end()
# define __terminateThread(tidx)
# define __waitForThreadToDie(tidx)
# define __spinThread(fn, args) -1
# define __getThreadCount 1
# define __getHighestThreadIndex 0
# define __getCurrentThreadIndex 0
# define __threadTimeslice
# define __createThreadLock(pLock) pLock = NULL
# define __destroyThreadLock(pLock)
# define __obtainThreadLock(pLock)
# define __releaseThreadLock(pLock)
# else /* multithreaded support... */
# ifndef _REENTRANT
# error _REENTRANT not defined for multithread compile!
# error Please put -D_REENTRANT on the command line.
# error otherwise, the C library is NOT thread-safe!
# endif /* _REENTRANT */
# include <pthread.h>
typedef pthread_mutex_t ThreadLock;
typedef pthread_mutex_t *PThreadLock;
void __terminateCurrentThread_f(void);
void __terminateThread_f(int tidx);
void __waitForThreadToDie_f(int tidx);
int __spinThread_f(void (*_fn)(void *x), void *_args);
int __getThreadCount_f(void);
int __getHighestThreadIndex_f(void);
int __getCurrentThreadIndex_f(void);
void __threadTimeslice_f(void);
void __createThreadLock_f(PThreadLock pThreadLock);
void __destroyThreadLock_f(PThreadLock pThreadLock);
void __obtainThreadLock_f(PThreadLock pThreadLock);
void __releaseThreadLock_f(PThreadLock pThreadLock);
# define __terminateCurrentThread __terminateCurrentThread_f()
# define __terminateThread(tidx) __terminateThread_f(tidx)
# define __waitForThreadToDie(tidx) __waitForThreadToDie_f(tidx)
# define __spinThread(fn, args) __spinThread_f(fn, args)
# define __getThreadCount __getThreadCount_f()
# define __getHighestThreadIndex __getHighestThreadIndex_f()
# define __getCurrentThreadIndex __getCurrentThreadIndex_f()
# define __threadTimeslice __threadTimeslice_f()
# define __createThreadLock(pLock) __createThreadLock_f(pLock)
# define __destroyThreadLock(pLock) __destroyThreadLock_f(pLock)
# define __obtainThreadLock(pLock) __obtainThreadLock_f(pLock)
# define __releaseThreadLock(pLock) __releaseThreadLock_f(pLock)
# endif /* (!) SINGLE_THREADED */
/* These exist in multi and single thread mode... */
void __initThreads(void);
void __deinitThreads(void);
# endif /* _INCLUDE_THREADS_H_ */
#endif /* _INCLUDE_STDBASIC_H_ */
/* end of Threads.h ... */