VirtualBox

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

最後變更 在這個檔案從62425是 45134,由 vboxsync 提交於 12 年 前

Additions/X11: build vboxvideo_drv.so for X.Org Server 1.14.

  • 屬性 svn:eol-style 設為 native
檔案大小: 6.7 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 * Thread support for gl dispatch.
27 *
28 * Initial version by John Stone ([email protected]) ([email protected])
29 * and Christoph Poliwoda ([email protected])
30 * Revised by Keith Whitwell
31 * Adapted for new gl dispatcher by Brian Paul
32 *
33 *
34 *
35 * DOCUMENTATION
36 *
37 * This thread module exports the following types:
38 * _glthread_TSD Thread-specific data area
39 * _glthread_Thread Thread datatype
40 * _glthread_Mutex Mutual exclusion lock
41 *
42 * Macros:
43 * _glthread_DECLARE_STATIC_MUTEX(name) Declare a non-local mutex
44 * _glthread_INIT_MUTEX(name) Initialize a mutex
45 * _glthread_LOCK_MUTEX(name) Lock a mutex
46 * _glthread_UNLOCK_MUTEX(name) Unlock a mutex
47 *
48 * Functions:
49 * _glthread_GetID(v) Get integer thread ID
50 * _glthread_InitTSD() Initialize thread-specific data
51 * _glthread_GetTSD() Get thread-specific data
52 * _glthread_SetTSD() Set thread-specific data
53 *
54 */
55
56/*
57 * If this file is accidentally included by a non-threaded build,
58 * it should not cause the build to fail, or otherwise cause problems.
59 * In general, it should only be included when needed however.
60 */
61
62#ifndef GLTHREAD_H
63#define GLTHREAD_H
64
65#if defined(USE_MGL_NAMESPACE)
66#define _glapi_Dispatch _mglapi_Dispatch
67#endif
68
69#if (defined(PTHREADS) || defined(WIN32_THREADS)) \
70 && !defined(THREADS)
71#define THREADS
72#endif
73
74#ifdef VMS
75#include <GL/vms_x_fix.h>
76#endif
77
78/*
79 * POSIX threads. This should be your choice in the Unix world
80 * whenever possible. When building with POSIX threads, be sure
81 * to enable any compiler flags which will cause the MT-safe
82 * libc (if one exists) to be used when linking, as well as any
83 * header macros for MT-safe errno, etc. For Solaris, this is the -mt
84 * compiler flag. On Solaris with gcc, use -D_REENTRANT to enable
85 * proper compiling for MT-safe libc etc.
86 */
87#if defined(PTHREADS)
88#include <pthread.h> /* POSIX threads headers */
89
90typedef struct {
91 pthread_key_t key;
92 int initMagic;
93} _glthread_TSD;
94
95typedef pthread_t _glthread_Thread;
96
97typedef pthread_mutex_t _glthread_Mutex;
98
99#define _glthread_DECLARE_STATIC_MUTEX(name) \
100 static _glthread_Mutex name = PTHREAD_MUTEX_INITIALIZER
101
102#define _glthread_INIT_MUTEX(name) \
103 pthread_mutex_init(&(name), NULL)
104
105#define _glthread_DESTROY_MUTEX(name) \
106 pthread_mutex_destroy(&(name))
107
108#define _glthread_LOCK_MUTEX(name) \
109 (void) pthread_mutex_lock(&(name))
110
111#define _glthread_UNLOCK_MUTEX(name) \
112 (void) pthread_mutex_unlock(&(name))
113
114#endif /* PTHREADS */
115
116/*
117 * Solaris threads. Use only up to Solaris 2.4.
118 * Solaris 2.5 and higher provide POSIX threads.
119 * Be sure to compile with -mt on the Solaris compilers, or
120 * use -D_REENTRANT if using gcc.
121 */
122
123/*
124 * Windows threads. Should work with Windows NT and 95.
125 * IMPORTANT: Link with multithreaded runtime library when THREADS are
126 * used!
127 */
128#ifdef WIN32_THREADS
129#include <windows.h>
130
131typedef struct {
132 DWORD key;
133 int initMagic;
134} _glthread_TSD;
135
136typedef HANDLE _glthread_Thread;
137
138typedef CRITICAL_SECTION _glthread_Mutex;
139
140#define _glthread_DECLARE_STATIC_MUTEX(name) /*static*/ _glthread_Mutex name = {0,0,0,0,0,0}
141#define _glthread_INIT_MUTEX(name) InitializeCriticalSection(&name)
142#define _glthread_DESTROY_MUTEX(name) DeleteCriticalSection(&name)
143#define _glthread_LOCK_MUTEX(name) EnterCriticalSection(&name)
144#define _glthread_UNLOCK_MUTEX(name) LeaveCriticalSection(&name)
145
146#endif /* WIN32_THREADS */
147
148/*
149 * BeOS threads. R5.x required.
150 */
151#ifdef BEOS_THREADS
152
153#include <kernel/OS.h>
154#include <support/TLS.h>
155
156typedef struct {
157 int32 key;
158 int initMagic;
159} _glthread_TSD;
160
161typedef thread_id _glthread_Thread;
162
163/* Use Benaphore, aka speeder semaphore */
164typedef struct {
165 int32 lock;
166 sem_id sem;
167} benaphore;
168typedef benaphore _glthread_Mutex;
169
170#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = { 0, 0 }
171#define _glthread_INIT_MUTEX(name) name.sem = create_sem(0, #name"_benaphore"), name.lock = 0
172#define _glthread_DESTROY_MUTEX(name) delete_sem(name.sem), name.lock = 0
173#define _glthread_LOCK_MUTEX(name) if (name.sem == 0) _glthread_INIT_MUTEX(name); \
174 if (atomic_add(&(name.lock), 1) >= 1) acquire_sem(name.sem)
175#define _glthread_UNLOCK_MUTEX(name) if (atomic_add(&(name.lock), -1) > 1) release_sem(name.sem)
176
177#endif /* BEOS_THREADS */
178
179#ifndef THREADS
180
181/*
182 * THREADS not defined
183 */
184
185typedef int _glthread_TSD;
186
187typedef int _glthread_Thread;
188
189typedef int _glthread_Mutex;
190
191#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0
192
193#define _glthread_INIT_MUTEX(name) (void) name
194
195#define _glthread_DESTROY_MUTEX(name) (void) name
196
197#define _glthread_LOCK_MUTEX(name) (void) name
198
199#define _glthread_UNLOCK_MUTEX(name) (void) name
200
201#endif /* THREADS */
202
203/*
204 * Platform independent thread specific data API.
205 */
206
207extern unsigned long
208 _glthread_GetID(void);
209
210extern void
211 _glthread_InitTSD(_glthread_TSD *);
212
213extern void *_glthread_GetTSD(_glthread_TSD *);
214
215extern void
216 _glthread_SetTSD(_glthread_TSD *, void *);
217
218#if defined(GLX_USE_TLS)
219
220extern TLS struct _glapi_table *_glapi_tls_Dispatch;
221
222#define GET_DISPATCH() _glapi_tls_Dispatch
223
224#elif !defined(GL_CALL)
225#if defined(THREADS)
226#define GET_DISPATCH() \
227 ((__builtin_expect( _glapi_Dispatch != NULL, 1 )) \
228 ? _glapi_Dispatch : _glapi_get_dispatch())
229#else
230#define GET_DISPATCH() _glapi_Dispatch
231#endif /* defined(THREADS) */
232#endif /* ndef GL_CALL */
233
234#endif /* THREADS_H */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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