VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/x11include/xorg-server-1.11.0/glthread.h@ 61386

最後變更 在這個檔案從61386是 38824,由 vboxsync 提交於 13 年 前

Additions/x11: header files for building X.Org Server 1.11 modules

  • 屬性 svn:eol-style 設為 native
檔案大小: 6.6 KB
 
1/*
2 * Mesa 3-D graphics library
3 * Version: 6.5.2
4 *
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26/*
27 * Thread support for gl dispatch.
28 *
29 * Initial version by John Stone ([email protected]) ([email protected])
30 * and Christoph Poliwoda ([email protected])
31 * Revised by Keith Whitwell
32 * Adapted for new gl dispatcher by Brian Paul
33 *
34 *
35 *
36 * DOCUMENTATION
37 *
38 * This thread module exports the following types:
39 * _glthread_TSD Thread-specific data area
40 * _glthread_Thread Thread datatype
41 * _glthread_Mutex Mutual exclusion lock
42 *
43 * Macros:
44 * _glthread_DECLARE_STATIC_MUTEX(name) Declare a non-local mutex
45 * _glthread_INIT_MUTEX(name) Initialize a mutex
46 * _glthread_LOCK_MUTEX(name) Lock a mutex
47 * _glthread_UNLOCK_MUTEX(name) Unlock a mutex
48 *
49 * Functions:
50 * _glthread_GetID(v) Get integer thread ID
51 * _glthread_InitTSD() Initialize thread-specific data
52 * _glthread_GetTSD() Get thread-specific data
53 * _glthread_SetTSD() Set thread-specific data
54 *
55 */
56
57/*
58 * If this file is accidentally included by a non-threaded build,
59 * it should not cause the build to fail, or otherwise cause problems.
60 * In general, it should only be included when needed however.
61 */
62
63#ifndef GLTHREAD_H
64#define GLTHREAD_H
65
66
67#if defined(USE_MGL_NAMESPACE)
68#define _glapi_Dispatch _mglapi_Dispatch
69#endif
70
71#if (defined(PTHREADS) || defined(WIN32_THREADS)) \
72 && !defined(THREADS)
73# define THREADS
74#endif
75
76#ifdef VMS
77#include <GL/vms_x_fix.h>
78#endif
79
80/*
81 * POSIX threads. This should be your choice in the Unix world
82 * whenever possible. When building with POSIX threads, be sure
83 * to enable any compiler flags which will cause the MT-safe
84 * libc (if one exists) to be used when linking, as well as any
85 * header macros for MT-safe errno, etc. For Solaris, this is the -mt
86 * compiler flag. On Solaris with gcc, use -D_REENTRANT to enable
87 * proper compiling for MT-safe libc etc.
88 */
89#if defined(PTHREADS)
90#include <pthread.h> /* POSIX threads headers */
91
92typedef struct {
93 pthread_key_t key;
94 int initMagic;
95} _glthread_TSD;
96
97typedef pthread_t _glthread_Thread;
98
99typedef pthread_mutex_t _glthread_Mutex;
100
101#define _glthread_DECLARE_STATIC_MUTEX(name) \
102 static _glthread_Mutex name = PTHREAD_MUTEX_INITIALIZER
103
104#define _glthread_INIT_MUTEX(name) \
105 pthread_mutex_init(&(name), NULL)
106
107#define _glthread_DESTROY_MUTEX(name) \
108 pthread_mutex_destroy(&(name))
109
110#define _glthread_LOCK_MUTEX(name) \
111 (void) pthread_mutex_lock(&(name))
112
113#define _glthread_UNLOCK_MUTEX(name) \
114 (void) pthread_mutex_unlock(&(name))
115
116#endif /* PTHREADS */
117
118
119
120
121/*
122 * Solaris threads. Use only up to Solaris 2.4.
123 * Solaris 2.5 and higher provide POSIX threads.
124 * Be sure to compile with -mt on the Solaris compilers, or
125 * use -D_REENTRANT if using gcc.
126 */
127
128
129
130
131/*
132 * Windows threads. Should work with Windows NT and 95.
133 * IMPORTANT: Link with multithreaded runtime library when THREADS are
134 * used!
135 */
136#ifdef WIN32_THREADS
137#include <windows.h>
138
139typedef struct {
140 DWORD key;
141 int initMagic;
142} _glthread_TSD;
143
144typedef HANDLE _glthread_Thread;
145
146typedef CRITICAL_SECTION _glthread_Mutex;
147
148#define _glthread_DECLARE_STATIC_MUTEX(name) /*static*/ _glthread_Mutex name = {0,0,0,0,0,0}
149#define _glthread_INIT_MUTEX(name) InitializeCriticalSection(&name)
150#define _glthread_DESTROY_MUTEX(name) DeleteCriticalSection(&name)
151#define _glthread_LOCK_MUTEX(name) EnterCriticalSection(&name)
152#define _glthread_UNLOCK_MUTEX(name) LeaveCriticalSection(&name)
153
154#endif /* WIN32_THREADS */
155
156/*
157 * BeOS threads. R5.x required.
158 */
159#ifdef BEOS_THREADS
160
161#include <kernel/OS.h>
162#include <support/TLS.h>
163
164typedef struct {
165 int32 key;
166 int initMagic;
167} _glthread_TSD;
168
169typedef thread_id _glthread_Thread;
170
171/* Use Benaphore, aka speeder semaphore */
172typedef struct {
173 int32 lock;
174 sem_id sem;
175} benaphore;
176typedef benaphore _glthread_Mutex;
177
178#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = { 0, 0 }
179#define _glthread_INIT_MUTEX(name) name.sem = create_sem(0, #name"_benaphore"), name.lock = 0
180#define _glthread_DESTROY_MUTEX(name) delete_sem(name.sem), name.lock = 0
181#define _glthread_LOCK_MUTEX(name) if (name.sem == 0) _glthread_INIT_MUTEX(name); \
182 if (atomic_add(&(name.lock), 1) >= 1) acquire_sem(name.sem)
183#define _glthread_UNLOCK_MUTEX(name) if (atomic_add(&(name.lock), -1) > 1) release_sem(name.sem)
184
185#endif /* BEOS_THREADS */
186
187
188
189#ifndef THREADS
190
191/*
192 * THREADS not defined
193 */
194
195typedef int _glthread_TSD;
196
197typedef int _glthread_Thread;
198
199typedef int _glthread_Mutex;
200
201#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0
202
203#define _glthread_INIT_MUTEX(name) (void) name
204
205#define _glthread_DESTROY_MUTEX(name) (void) name
206
207#define _glthread_LOCK_MUTEX(name) (void) name
208
209#define _glthread_UNLOCK_MUTEX(name) (void) name
210
211#endif /* THREADS */
212
213
214
215/*
216 * Platform independent thread specific data API.
217 */
218
219extern unsigned long
220_glthread_GetID(void);
221
222
223extern void
224_glthread_InitTSD(_glthread_TSD *);
225
226
227extern void *
228_glthread_GetTSD(_glthread_TSD *);
229
230
231extern void
232_glthread_SetTSD(_glthread_TSD *, void *);
233
234#if defined(GLX_USE_TLS)
235
236extern TLS struct _glapi_table * _glapi_tls_Dispatch;
237
238#define GET_DISPATCH() _glapi_tls_Dispatch
239
240#elif !defined(GL_CALL)
241# if defined(THREADS)
242# define GET_DISPATCH() \
243 ((__builtin_expect( _glapi_Dispatch != NULL, 1 )) \
244 ? _glapi_Dispatch : _glapi_get_dispatch())
245# else
246# define GET_DISPATCH() _glapi_Dispatch
247# endif /* defined(THREADS) */
248#endif /* ndef GL_CALL */
249
250
251#endif /* THREADS_H */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette