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