Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenglthread.h
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 6.5.2 00004 * 00005 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a 00008 * copy of this software and associated documentation files (the "Software"), 00009 * to deal in the Software without restriction, including without limitation 00010 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 * and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00018 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00021 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 00026 /* 00027 * Thread support for gl dispatch. 00028 * 00029 * Initial version by John Stone (j.stone@acm.org) (johns@cs.umr.edu) 00030 * and Christoph Poliwoda (poliwoda@volumegraphics.com) 00031 * Revised by Keith Whitwell 00032 * Adapted for new gl dispatcher by Brian Paul 00033 * 00034 * 00035 * 00036 * DOCUMENTATION 00037 * 00038 * This thread module exports the following types: 00039 * _glthread_TSD Thread-specific data area 00040 * _glthread_Thread Thread datatype 00041 * _glthread_Mutex Mutual exclusion lock 00042 * 00043 * Macros: 00044 * _glthread_DECLARE_STATIC_MUTEX(name) Declare a non-local mutex 00045 * _glthread_INIT_MUTEX(name) Initialize a mutex 00046 * _glthread_LOCK_MUTEX(name) Lock a mutex 00047 * _glthread_UNLOCK_MUTEX(name) Unlock a mutex 00048 * 00049 * Functions: 00050 * _glthread_GetID(v) Get integer thread ID 00051 * _glthread_InitTSD() Initialize thread-specific data 00052 * _glthread_GetTSD() Get thread-specific data 00053 * _glthread_SetTSD() Set thread-specific data 00054 * 00055 */ 00056 00057 /* 00058 * If this file is accidentally included by a non-threaded build, 00059 * it should not cause the build to fail, or otherwise cause problems. 00060 * In general, it should only be included when needed however. 00061 */ 00062 00063 #ifndef GLTHREAD_H 00064 #define GLTHREAD_H 00065 00066 00067 #if defined(USE_MGL_NAMESPACE) 00068 #define _glapi_Dispatch _mglapi_Dispatch 00069 #endif 00070 00071 00072 00073 #if (defined(PTHREADS) || defined(SOLARIS_THREADS) ||\ 00074 defined(WIN32_THREADS) || defined(USE_XTHREADS) || defined(BEOS_THREADS)) \ 00075 && !defined(THREADS) 00076 # define THREADS 00077 #endif 00078 00079 #ifdef VMS 00080 #include <GL/vms_x_fix.h> 00081 #endif 00082 00083 /* 00084 * POSIX threads. This should be your choice in the Unix world 00085 * whenever possible. When building with POSIX threads, be sure 00086 * to enable any compiler flags which will cause the MT-safe 00087 * libc (if one exists) to be used when linking, as well as any 00088 * header macros for MT-safe errno, etc. For Solaris, this is the -mt 00089 * compiler flag. On Solaris with gcc, use -D_REENTRANT to enable 00090 * proper compiling for MT-safe libc etc. 00091 */ 00092 #if defined(PTHREADS) 00093 #include <pthread.h> /* POSIX threads headers */ 00094 00095 typedef struct { 00096 pthread_key_t key; 00097 int initMagic; 00098 } _glthread_TSD; 00099 00100 typedef pthread_t _glthread_Thread; 00101 00102 typedef pthread_mutex_t _glthread_Mutex; 00103 00104 #define _glthread_DECLARE_STATIC_MUTEX(name) \ 00105 static _glthread_Mutex name = PTHREAD_MUTEX_INITIALIZER 00106 00107 #define _glthread_INIT_MUTEX(name) \ 00108 pthread_mutex_init(&(name), NULL) 00109 00110 #define _glthread_DESTROY_MUTEX(name) \ 00111 pthread_mutex_destroy(&(name)) 00112 00113 #define _glthread_LOCK_MUTEX(name) \ 00114 (void) pthread_mutex_lock(&(name)) 00115 00116 #define _glthread_UNLOCK_MUTEX(name) \ 00117 (void) pthread_mutex_unlock(&(name)) 00118 00119 #endif /* PTHREADS */ 00120 00121 00122 00123 00124 /* 00125 * Solaris threads. Use only up to Solaris 2.4. 00126 * Solaris 2.5 and higher provide POSIX threads. 00127 * Be sure to compile with -mt on the Solaris compilers, or 00128 * use -D_REENTRANT if using gcc. 00129 */ 00130 #ifdef SOLARIS_THREADS 00131 #include <thread.h> 00132 00133 typedef struct { 00134 thread_key_t key; 00135 mutex_t keylock; 00136 int initMagic; 00137 } _glthread_TSD; 00138 00139 typedef thread_t _glthread_Thread; 00140 00141 typedef mutex_t _glthread_Mutex; 00142 00143 /* XXX need to really implement mutex-related macros */ 00144 #define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0 00145 #define _glthread_INIT_MUTEX(name) (void) name 00146 #define _glthread_DESTROY_MUTEX(name) (void) name 00147 #define _glthread_LOCK_MUTEX(name) (void) name 00148 #define _glthread_UNLOCK_MUTEX(name) (void) name 00149 00150 #endif /* SOLARIS_THREADS */ 00151 00152 00153 00154 00155 /* 00156 * Windows threads. Should work with Windows NT and 95. 00157 * IMPORTANT: Link with multithreaded runtime library when THREADS are 00158 * used! 00159 */ 00160 #ifdef WIN32_THREADS 00161 #include <windows.h> 00162 00163 typedef struct { 00164 DWORD key; 00165 int initMagic; 00166 } _glthread_TSD; 00167 00168 typedef HANDLE _glthread_Thread; 00169 00170 typedef CRITICAL_SECTION _glthread_Mutex; 00171 00172 #define _glthread_DECLARE_STATIC_MUTEX(name) /*static*/ _glthread_Mutex name = {0,0,0,0,0,0} 00173 #define _glthread_INIT_MUTEX(name) InitializeCriticalSection(&name) 00174 #define _glthread_DESTROY_MUTEX(name) DeleteCriticalSection(&name) 00175 #define _glthread_LOCK_MUTEX(name) EnterCriticalSection(&name) 00176 #define _glthread_UNLOCK_MUTEX(name) LeaveCriticalSection(&name) 00177 00178 #endif /* WIN32_THREADS */ 00179 00180 00181 00182 00183 /* 00184 * XFree86 has its own thread wrapper, Xthreads.h 00185 * We wrap it again for GL. 00186 */ 00187 #ifdef USE_XTHREADS 00188 #include <X11/Xthreads.h> 00189 00190 typedef struct { 00191 xthread_key_t key; 00192 int initMagic; 00193 } _glthread_TSD; 00194 00195 typedef xthread_t _glthread_Thread; 00196 00197 typedef xmutex_rec _glthread_Mutex; 00198 00199 #ifdef XMUTEX_INITIALIZER 00200 #define _glthread_DECLARE_STATIC_MUTEX(name) \ 00201 static _glthread_Mutex name = XMUTEX_INITIALIZER 00202 #else 00203 #define _glthread_DECLARE_STATIC_MUTEX(name) \ 00204 static _glthread_Mutex name 00205 #endif 00206 00207 #define _glthread_INIT_MUTEX(name) \ 00208 xmutex_init(&(name)) 00209 00210 #define _glthread_DESTROY_MUTEX(name) \ 00211 xmutex_clear(&(name)) 00212 00213 #define _glthread_LOCK_MUTEX(name) \ 00214 (void) xmutex_lock(&(name)) 00215 00216 #define _glthread_UNLOCK_MUTEX(name) \ 00217 (void) xmutex_unlock(&(name)) 00218 00219 #endif /* USE_XTHREADS */ 00220 00221 00222 00223 /* 00224 * BeOS threads. R5.x required. 00225 */ 00226 #ifdef BEOS_THREADS 00227 00228 /* Problem with OS.h and this file on haiku */ 00229 #ifndef __HAIKU__ 00230 #include <kernel/OS.h> 00231 #endif 00232 00233 #include <support/TLS.h> 00234 00235 /* The only two typedefs required here 00236 * this is cause of the OS.h problem 00237 */ 00238 #ifdef __HAIKU__ 00239 typedef int32 thread_id; 00240 typedef int32 sem_id; 00241 #endif 00242 00243 typedef struct { 00244 int32 key; 00245 int initMagic; 00246 } _glthread_TSD; 00247 00248 typedef thread_id _glthread_Thread; 00249 00250 /* Use Benaphore, aka speeder semaphore */ 00251 typedef struct { 00252 int32 lock; 00253 sem_id sem; 00254 } benaphore; 00255 typedef benaphore _glthread_Mutex; 00256 00257 #define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = { 0, 0 } 00258 #define _glthread_INIT_MUTEX(name) name.sem = create_sem(0, #name"_benaphore"), name.lock = 0 00259 #define _glthread_DESTROY_MUTEX(name) delete_sem(name.sem), name.lock = 0 00260 #define _glthread_LOCK_MUTEX(name) if (name.sem == 0) _glthread_INIT_MUTEX(name); \ 00261 if (atomic_add(&(name.lock), 1) >= 1) acquire_sem(name.sem) 00262 #define _glthread_UNLOCK_MUTEX(name) if (atomic_add(&(name.lock), -1) > 1) release_sem(name.sem) 00263 00264 #endif /* BEOS_THREADS */ 00265 00266 00267 00268 #ifndef THREADS 00269 00270 /* 00271 * THREADS not defined 00272 */ 00273 00274 typedef int _glthread_TSD; 00275 00276 typedef int _glthread_Thread; 00277 00278 typedef int _glthread_Mutex; 00279 00280 #define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0 00281 00282 #define _glthread_INIT_MUTEX(name) (void) name 00283 00284 #define _glthread_DESTROY_MUTEX(name) (void) name 00285 00286 #define _glthread_LOCK_MUTEX(name) (void) name 00287 00288 #define _glthread_UNLOCK_MUTEX(name) (void) name 00289 00290 #endif /* THREADS */ 00291 00292 00293 00294 /* 00295 * Platform independent thread specific data API. 00296 */ 00297 00298 extern unsigned long 00299 _glthread_GetID(void); 00300 00301 00302 extern void 00303 _glthread_InitTSD(_glthread_TSD *); 00304 00305 00306 extern void * 00307 _glthread_GetTSD(_glthread_TSD *); 00308 00309 00310 extern void 00311 _glthread_SetTSD(_glthread_TSD *, void *); 00312 00313 #if !defined __GNUC__ || __GNUC__ < 3 00314 # define __builtin_expect(x, y) x 00315 #endif 00316 00317 #if defined(GLX_USE_TLS) 00318 00319 extern __thread struct _glapi_table * _glapi_tls_Dispatch 00320 __attribute__((tls_model("initial-exec"))); 00321 00322 #define GET_DISPATCH() _glapi_tls_Dispatch 00323 00324 #elif !defined(GL_CALL) 00325 # if defined(THREADS) 00326 # define GET_DISPATCH() \ 00327 ((__builtin_expect( _glapi_Dispatch != NULL, 1 )) \ 00328 ? _glapi_Dispatch : _glapi_get_dispatch()) 00329 # else 00330 # define GET_DISPATCH() _glapi_Dispatch 00331 # endif /* defined(THREADS) */ 00332 #endif /* ndef GL_CALL */ 00333 00334 00335 #endif /* THREADS_H */ Generated on Fri May 25 2012 04:18:14 for ReactOS by
1.7.6.1
|