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 | # ifdef VBOX
|
---|
22 | # include <iprt/win/windows.h>
|
---|
23 | # else
|
---|
24 | #include <windows.h>
|
---|
25 | # endif
|
---|
26 | #else
|
---|
27 | #include <pthread.h>
|
---|
28 | #include <semaphore.h>
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #include "cr_error.h"
|
---|
32 |
|
---|
33 | #include <iprt/asm.h>
|
---|
34 | /*
|
---|
35 | * Handle for Thread-Specific Data
|
---|
36 | */
|
---|
37 | typedef struct {
|
---|
38 | #ifdef WINDOWS
|
---|
39 | DWORD key;
|
---|
40 | #else
|
---|
41 | pthread_key_t key;
|
---|
42 | #endif
|
---|
43 | int initMagic;
|
---|
44 | } CRtsd;
|
---|
45 |
|
---|
46 |
|
---|
47 | extern DECLEXPORT(void) crInitTSD(CRtsd *tsd);
|
---|
48 | extern DECLEXPORT(void) crInitTSDF(CRtsd *tsd, void (*destructor)(void *));
|
---|
49 | extern DECLEXPORT(void) crFreeTSD(CRtsd *tsd);
|
---|
50 | extern DECLEXPORT(void) crSetTSD(CRtsd *tsd, void *ptr);
|
---|
51 | extern DECLEXPORT(void *) crGetTSD(CRtsd *tsd);
|
---|
52 | extern DECLEXPORT(unsigned long) crThreadID(void);
|
---|
53 |
|
---|
54 |
|
---|
55 | /* Mutex datatype */
|
---|
56 | #ifdef WINDOWS
|
---|
57 | typedef CRITICAL_SECTION CRmutex;
|
---|
58 | #else
|
---|
59 | typedef pthread_mutex_t CRmutex;
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | extern DECLEXPORT(void) crInitMutex(CRmutex *mutex);
|
---|
63 | extern DECLEXPORT(void) crFreeMutex(CRmutex *mutex);
|
---|
64 | extern DECLEXPORT(void) crLockMutex(CRmutex *mutex);
|
---|
65 | extern DECLEXPORT(void) crUnlockMutex(CRmutex *mutex);
|
---|
66 |
|
---|
67 |
|
---|
68 | /* Condition variable datatype */
|
---|
69 | #ifdef WINDOWS
|
---|
70 | typedef int CRcondition;
|
---|
71 | #else
|
---|
72 | typedef pthread_cond_t CRcondition;
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | extern DECLEXPORT(void) crInitCondition(CRcondition *cond);
|
---|
76 | extern DECLEXPORT(void) crFreeCondition(CRcondition *cond);
|
---|
77 | extern DECLEXPORT(void) crWaitCondition(CRcondition *cond, CRmutex *mutex);
|
---|
78 | extern DECLEXPORT(void) crSignalCondition(CRcondition *cond);
|
---|
79 |
|
---|
80 |
|
---|
81 | /* Barrier datatype */
|
---|
82 | typedef struct {
|
---|
83 | unsigned int count;
|
---|
84 | #ifdef WINDOWS
|
---|
85 | HANDLE hEvents[CR_MAX_CONTEXTS];
|
---|
86 | #else
|
---|
87 | unsigned int waiting;
|
---|
88 | pthread_cond_t cond;
|
---|
89 | pthread_mutex_t mutex;
|
---|
90 | #endif
|
---|
91 | } CRbarrier;
|
---|
92 |
|
---|
93 | extern DECLEXPORT(void) crInitBarrier(CRbarrier *b, unsigned int count);
|
---|
94 | extern DECLEXPORT(void) crFreeBarrier(CRbarrier *b);
|
---|
95 | extern DECLEXPORT(void) crWaitBarrier(CRbarrier *b);
|
---|
96 |
|
---|
97 |
|
---|
98 | /* Semaphores */
|
---|
99 | #ifdef WINDOWS
|
---|
100 | typedef int CRsemaphore;
|
---|
101 | #else
|
---|
102 | typedef sem_t CRsemaphore;
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | extern DECLEXPORT(void) crInitSemaphore(CRsemaphore *s, unsigned int count);
|
---|
106 | extern DECLEXPORT(void) crWaitSemaphore(CRsemaphore *s);
|
---|
107 | extern DECLEXPORT(void) crSignalSemaphore(CRsemaphore *s);
|
---|
108 |
|
---|
109 | #define VBoxTlsRefGetImpl(_tls) (crGetTSD((CRtsd*)(_tls)))
|
---|
110 | #define VBoxTlsRefSetImpl(_tls, _val) (crSetTSD((CRtsd*)(_tls), (_val)))
|
---|
111 | #define VBoxTlsRefAssertImpl CRASSERT
|
---|
112 | #include <VBoxVideo3D.h>
|
---|
113 |
|
---|
114 | #ifdef __cplusplus
|
---|
115 | }
|
---|
116 | #endif
|
---|
117 |
|
---|
118 | #endif /* CR_THREADS_H */
|
---|