1 | /* Copyright (c) 2001, Stanford University
|
---|
2 | * All rights reserved.
|
---|
3 | *
|
---|
4 | * See the file LICENSE.txt for information on redistributing this software.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #ifndef CR_THREADS_H
|
---|
8 | #define CR_THREADS_H
|
---|
9 |
|
---|
10 | #include <iprt/cdefs.h>
|
---|
11 |
|
---|
12 | #ifdef __cplusplus
|
---|
13 | extern "C" {
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include "chromium.h"
|
---|
17 | #include "cr_bits.h"
|
---|
18 |
|
---|
19 | #ifdef WINDOWS
|
---|
20 | #define WIN32_LEAN_AND_MEAN
|
---|
21 | #include <windows.h>
|
---|
22 | #else
|
---|
23 | #include <pthread.h>
|
---|
24 | #include <semaphore.h>
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | #include "cr_error.h"
|
---|
28 |
|
---|
29 | #include <iprt/asm.h>
|
---|
30 | /*
|
---|
31 | * Handle for Thread-Specific Data
|
---|
32 | */
|
---|
33 | typedef struct {
|
---|
34 | #ifdef WINDOWS
|
---|
35 | DWORD key;
|
---|
36 | #else
|
---|
37 | pthread_key_t key;
|
---|
38 | #endif
|
---|
39 | int initMagic;
|
---|
40 | } CRtsd;
|
---|
41 |
|
---|
42 |
|
---|
43 | extern DECLEXPORT(void) crInitTSD(CRtsd *tsd);
|
---|
44 | extern DECLEXPORT(void) crInitTSDF(CRtsd *tsd, DECLCALLBACKMEMBER(void, destructor)(void *));
|
---|
45 | extern DECLEXPORT(void) crFreeTSD(CRtsd *tsd);
|
---|
46 | extern DECLEXPORT(void) crSetTSD(CRtsd *tsd, void *ptr);
|
---|
47 | extern DECLEXPORT(void *) crGetTSD(CRtsd *tsd);
|
---|
48 | extern DECLEXPORT(unsigned long) crThreadID(void);
|
---|
49 |
|
---|
50 |
|
---|
51 | /* Mutex datatype */
|
---|
52 | #ifdef WINDOWS
|
---|
53 | typedef CRITICAL_SECTION CRmutex;
|
---|
54 | #else
|
---|
55 | typedef pthread_mutex_t CRmutex;
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | extern DECLEXPORT(void) crInitMutex(CRmutex *mutex);
|
---|
59 | extern DECLEXPORT(void) crFreeMutex(CRmutex *mutex);
|
---|
60 | extern DECLEXPORT(void) crLockMutex(CRmutex *mutex);
|
---|
61 | extern DECLEXPORT(void) crUnlockMutex(CRmutex *mutex);
|
---|
62 |
|
---|
63 |
|
---|
64 | /* Condition variable datatype */
|
---|
65 | #ifdef WINDOWS
|
---|
66 | typedef int CRcondition;
|
---|
67 | #else
|
---|
68 | typedef pthread_cond_t CRcondition;
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | extern DECLEXPORT(void) crInitCondition(CRcondition *cond);
|
---|
72 | extern DECLEXPORT(void) crFreeCondition(CRcondition *cond);
|
---|
73 | extern DECLEXPORT(void) crWaitCondition(CRcondition *cond, CRmutex *mutex);
|
---|
74 | extern DECLEXPORT(void) crSignalCondition(CRcondition *cond);
|
---|
75 |
|
---|
76 |
|
---|
77 | /* Barrier datatype */
|
---|
78 | typedef struct {
|
---|
79 | unsigned int count;
|
---|
80 | #ifdef WINDOWS
|
---|
81 | HANDLE hEvents[CR_MAX_CONTEXTS];
|
---|
82 | #else
|
---|
83 | unsigned int waiting;
|
---|
84 | pthread_cond_t cond;
|
---|
85 | pthread_mutex_t mutex;
|
---|
86 | #endif
|
---|
87 | } CRbarrier;
|
---|
88 |
|
---|
89 | extern DECLEXPORT(void) crInitBarrier(CRbarrier *b, unsigned int count);
|
---|
90 | extern DECLEXPORT(void) crFreeBarrier(CRbarrier *b);
|
---|
91 | extern DECLEXPORT(void) crWaitBarrier(CRbarrier *b);
|
---|
92 |
|
---|
93 |
|
---|
94 | /* Semaphores */
|
---|
95 | #ifdef WINDOWS
|
---|
96 | typedef int CRsemaphore;
|
---|
97 | #else
|
---|
98 | typedef sem_t CRsemaphore;
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | extern DECLEXPORT(void) crInitSemaphore(CRsemaphore *s, unsigned int count);
|
---|
102 | extern DECLEXPORT(void) crWaitSemaphore(CRsemaphore *s);
|
---|
103 | extern DECLEXPORT(void) crSignalSemaphore(CRsemaphore *s);
|
---|
104 |
|
---|
105 | #define VBoxTlsRefGetImpl(_tls) (crGetTSD((CRtsd*)(_tls)))
|
---|
106 | #define VBoxTlsRefSetImpl(_tls, _val) (crSetTSD((CRtsd*)(_tls), (_val)))
|
---|
107 | #define VBoxTlsRefAssertImpl CRASSERT
|
---|
108 | #include <VBox/VBoxVideo3D.h>
|
---|
109 |
|
---|
110 | #ifdef __cplusplus
|
---|
111 | }
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | #endif /* CR_THREADS_H */
|
---|