blob: b3b6a93a5db2d26761d50dfda557bb9aa2ef9d9c (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/* Copyright (c) 2001, Stanford University
* All rights reserved.
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#ifndef CR_THREADS_H
#define CR_THREADS_H
#include <iprt/cdefs.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "chromium.h"
#include "cr_bits.h"
#ifdef WINDOWS
#define WIN32_LEAN_AND_MEAN
# ifdef VBOX
# include <iprt/win/windows.h>
# else
#include <windows.h>
# endif
#else
#include <pthread.h>
#include <semaphore.h>
#endif
#include "cr_error.h"
#include <iprt/asm.h>
/*
* Handle for Thread-Specific Data
*/
typedef struct {
#ifdef WINDOWS
DWORD key;
#else
pthread_key_t key;
#endif
int initMagic;
} CRtsd;
extern DECLEXPORT(void) crInitTSD(CRtsd *tsd);
extern DECLEXPORT(void) crInitTSDF(CRtsd *tsd, void (*destructor)(void *));
extern DECLEXPORT(void) crFreeTSD(CRtsd *tsd);
extern DECLEXPORT(void) crSetTSD(CRtsd *tsd, void *ptr);
extern DECLEXPORT(void *) crGetTSD(CRtsd *tsd);
extern DECLEXPORT(unsigned long) crThreadID(void);
/* Mutex datatype */
#ifdef WINDOWS
typedef CRITICAL_SECTION CRmutex;
#else
typedef pthread_mutex_t CRmutex;
#endif
extern DECLEXPORT(void) crInitMutex(CRmutex *mutex);
extern DECLEXPORT(void) crFreeMutex(CRmutex *mutex);
extern DECLEXPORT(void) crLockMutex(CRmutex *mutex);
extern DECLEXPORT(void) crUnlockMutex(CRmutex *mutex);
/* Condition variable datatype */
#ifdef WINDOWS
typedef int CRcondition;
#else
typedef pthread_cond_t CRcondition;
#endif
extern DECLEXPORT(void) crInitCondition(CRcondition *cond);
extern DECLEXPORT(void) crFreeCondition(CRcondition *cond);
extern DECLEXPORT(void) crWaitCondition(CRcondition *cond, CRmutex *mutex);
extern DECLEXPORT(void) crSignalCondition(CRcondition *cond);
/* Barrier datatype */
typedef struct {
unsigned int count;
#ifdef WINDOWS
HANDLE hEvents[CR_MAX_CONTEXTS];
#else
unsigned int waiting;
pthread_cond_t cond;
pthread_mutex_t mutex;
#endif
} CRbarrier;
extern DECLEXPORT(void) crInitBarrier(CRbarrier *b, unsigned int count);
extern DECLEXPORT(void) crFreeBarrier(CRbarrier *b);
extern DECLEXPORT(void) crWaitBarrier(CRbarrier *b);
/* Semaphores */
#ifdef WINDOWS
typedef int CRsemaphore;
#else
typedef sem_t CRsemaphore;
#endif
extern DECLEXPORT(void) crInitSemaphore(CRsemaphore *s, unsigned int count);
extern DECLEXPORT(void) crWaitSemaphore(CRsemaphore *s);
extern DECLEXPORT(void) crSignalSemaphore(CRsemaphore *s);
#define VBoxTlsRefGetImpl(_tls) (crGetTSD((CRtsd*)(_tls)))
#define VBoxTlsRefSetImpl(_tls, _val) (crSetTSD((CRtsd*)(_tls), (_val)))
#define VBoxTlsRefAssertImpl CRASSERT
#include <VBoxVideo3D.h>
#ifdef __cplusplus
}
#endif
#endif /* CR_THREADS_H */
|