diff options
author | Chia-I Wu <[email protected]> | 2010-04-23 16:06:26 +0800 |
---|---|---|
committer | Chia-I Wu <[email protected]> | 2010-05-07 10:41:11 +0800 |
commit | a73c6540d9a7f6e26d8568ba2fc522cb865f0a6c (patch) | |
tree | edeb695b6ed24d3cb0016fbabadea48931de779f /src/mapi/glapi | |
parent | 296adbd545b8efd38c9ed508166b2de2764a444b (diff) |
mapi: Add mapi and share the code with glapi.
Specifically, move all or most of
glapi/glapi.c to mapi/u_current.c,
glapi/glapi_execmem.c to mapi/u_execmem.c,
glapi/glthread.[ch] to mapi/u_thread.[ch]
and remove their dependencies on core Mesa headers.
Diffstat (limited to 'src/mapi/glapi')
-rw-r--r-- | src/mapi/glapi/Makefile | 31 | ||||
-rw-r--r-- | src/mapi/glapi/SConscript | 12 | ||||
-rw-r--r-- | src/mapi/glapi/glapi.c | 293 | ||||
-rw-r--r-- | src/mapi/glapi/glapi.h | 112 | ||||
-rw-r--r-- | src/mapi/glapi/glapi_entrypoint.c | 5 | ||||
-rw-r--r-- | src/mapi/glapi/glapi_execmem.c | 128 | ||||
-rw-r--r-- | src/mapi/glapi/glapi_getproc.c | 8 | ||||
-rw-r--r-- | src/mapi/glapi/glapi_priv.h | 6 | ||||
-rw-r--r-- | src/mapi/glapi/glthread.c | 262 | ||||
-rw-r--r-- | src/mapi/glapi/glthread.h | 258 | ||||
-rw-r--r-- | src/mapi/glapi/sources.mak | 2 |
11 files changed, 70 insertions, 1047 deletions
diff --git a/src/mapi/glapi/Makefile b/src/mapi/glapi/Makefile index 13c8c54de21..ca9381d4253 100644 --- a/src/mapi/glapi/Makefile +++ b/src/mapi/glapi/Makefile @@ -3,19 +3,29 @@ TOP = ../../.. include $(TOP)/configs/current +TARGET = glapi + +MAPI = $(TOP)/src/mapi/mapi + include sources.mak GLAPI_OBJECTS = $(GLAPI_SOURCES:.c=.o) GLAPI_ASM_OBJECTS = $(GLAPI_ASM_SOURCES:.S=.o) +include $(MAPI)/sources.mak +MAPI_GLAPI_OBJECTS := $(MAPI_GLAPI_SOURCES:.c=.o) +MAPI_GLAPI_SOURCES := $(addprefix $(MAPI)/, $(MAPI_GLAPI_SOURCES)) + +TARGET_OBJECTS = $(GLAPI_OBJECTS) $(GLAPI_ASM_OBJECTS) $(MAPI_GLAPI_OBJECTS) + INCLUDE_DIRS = \ -I$(TOP)/include \ -I$(TOP)/src/mapi \ -I$(TOP)/src/mesa -default: depend libglapi.a +default: depend lib$(TARGET).a -libglapi.a: $(GLAPI_OBJECTS) $(GLAPI_ASM_OBJECTS) - @ $(MKLIB) -o glapi -static $(GLAPI_OBJECTS) $(GLAPI_ASM_OBJECTS) +lib$(TARGET).a: $(TARGET_OBJECTS) + @$(MKLIB) -o $(TARGET) -static $(TARGET_OBJECTS) $(GLAPI_OBJECTS): %.o: %.c $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ @@ -23,16 +33,21 @@ $(GLAPI_OBJECTS): %.o: %.c $(GLAPI_ASM_OBJECTS): %.o: %.S $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ +$(MAPI_GLAPI_OBJECTS): %.o: $(MAPI)/%.c + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) -DMAPI_GLAPI_CURRENT $< -o $@ + install: clean: - -rm -f $(GLAPI_OBJECTS) $(GLAPI_ASM_OBJECTS) - -rm -f depend depend.bak libglapi.a + -rm -f $(TARGET_OBJECTS) + -rm -f lib$(TARGET).a + -rm -f depend depend.bak -depend: $(GLAPI_SOURCES) +depend: $(GLAPI_SOURCES) $(MAPI_GLAPI_SOURCES) @ echo "running $(MKDEP)" @ touch depend - @$(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) $(GLAPI_SOURCES) \ - > /dev/null 2>/dev/null + @$(MKDEP) $(MKDEP_OPTIONS) -f- $(DEFINES) $(INCLUDE_DIRS) \ + -DMAPI_GLAPI_CURRENT $(GLAPI_SOURCES) $(MAPI_GLAPI_SOURCES) \ + 2>/dev/null | sed -e 's,^$(MAPI)/,,' > depend -include depend diff --git a/src/mapi/glapi/SConscript b/src/mapi/glapi/SConscript index 1ace2e6b2cd..15c08255c39 100644 --- a/src/mapi/glapi/SConscript +++ b/src/mapi/glapi/SConscript @@ -8,21 +8,29 @@ if env['platform'] != 'winddk': env = env.Clone() + env.Append(CPPDEFINES = [ + 'MAPI_GLAPI_CURRENT', + ]) + env.Append(CPPPATH = [ '#/src/mapi', '#/src/mesa', ]) glapi_sources = [ - 'glapi.c', 'glapi_dispatch.c', 'glapi_entrypoint.c', - 'glapi_execmem.c', 'glapi_getproc.c', 'glapi_nop.c', 'glthread.c', ] + glapi_sources += [ + '../mapi/u_current.c', + '../mapi/u_execmem.c', + '../mapi/u_thread.c', + ] + # # Assembly sources # diff --git a/src/mapi/glapi/glapi.c b/src/mapi/glapi/glapi.c deleted file mode 100644 index ce85cf6a87b..00000000000 --- a/src/mapi/glapi/glapi.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.1 - * - * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* - * This file manages the OpenGL API dispatch layer. - * The dispatch table (struct _glapi_table) is basically just a list - * of function pointers. - * There are functions to set/get the current dispatch table for the - * current thread and to manage registration/dispatch of dynamically - * added extension functions. - * - * It's intended that this file and the other glapi*.[ch] files are - * flexible enough to be reused in several places: XFree86, DRI- - * based libGL.so, and perhaps the SGI SI. - * - * NOTE: There are no dependencies on Mesa in this code. - * - * Versions (API changes): - * 2000/02/23 - original version for Mesa 3.3 and XFree86 4.0 - * 2001/01/16 - added dispatch override feature for Mesa 3.5 - * 2002/06/28 - added _glapi_set_warning_func(), Mesa 4.1. - * 2002/10/01 - _glapi_get_proc_address() will now generate new entrypoints - * itself (using offset ~0). _glapi_add_entrypoint() can be - * called afterward and it'll fill in the correct dispatch - * offset. This allows DRI libGL to avoid probing for DRI - * drivers! No changes to the public glapi interface. - */ - - - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#include "glapi/mesa.h" -#else -#include "main/glheader.h" -#include "main/compiler.h" -#endif - -#include "glapi/glapi.h" -#include "glapi/glapi_priv.h" - -extern _glapi_proc __glapi_noop_table[]; - - -/** - * \name Current dispatch and current context control variables - * - * Depending on whether or not multithreading is support, and the type of - * support available, several variables are used to store the current context - * pointer and the current dispatch table pointer. In the non-threaded case, - * the variables \c _glapi_Dispatch and \c _glapi_Context are used for this - * purpose. - * - * In the "normal" threaded case, the variables \c _glapi_Dispatch and - * \c _glapi_Context will be \c NULL if an application is detected as being - * multithreaded. Single-threaded applications will use \c _glapi_Dispatch - * and \c _glapi_Context just like the case without any threading support. - * When \c _glapi_Dispatch and \c _glapi_Context are \c NULL, the thread state - * data \c _gl_DispatchTSD and \c ContextTSD are used. Drivers and the - * static dispatch functions access these variables via \c _glapi_get_dispatch - * and \c _glapi_get_context. - * - * There is a race condition in setting \c _glapi_Dispatch to \c NULL. It is - * possible for the original thread to be setting it at the same instant a new - * thread, perhaps running on a different processor, is clearing it. Because - * of that, \c ThreadSafe, which can only ever be changed to \c GL_TRUE, is - * used to determine whether or not the application is multithreaded. - * - * In the TLS case, the variables \c _glapi_Dispatch and \c _glapi_Context are - * hardcoded to \c NULL. Instead the TLS variables \c _glapi_tls_Dispatch and - * \c _glapi_tls_Context are used. Having \c _glapi_Dispatch and - * \c _glapi_Context be hardcoded to \c NULL maintains binary compatability - * between TLS enabled loaders and non-TLS DRI drivers. - */ -/*@{*/ -#if defined(GLX_USE_TLS) - -PUBLIC __thread struct _glapi_table * _glapi_tls_Dispatch - __attribute__((tls_model("initial-exec"))) - = (struct _glapi_table *) __glapi_noop_table; - -PUBLIC __thread void * _glapi_tls_Context - __attribute__((tls_model("initial-exec"))); - -PUBLIC const struct _glapi_table *_glapi_Dispatch = NULL; - -PUBLIC const void *_glapi_Context = NULL; - -#else - -#if defined(THREADS) - -static GLboolean ThreadSafe = GL_FALSE; /**< In thread-safe mode? */ - -_glthread_TSD _gl_DispatchTSD; /**< Per-thread dispatch pointer */ - -static _glthread_TSD ContextTSD; /**< Per-thread context pointer */ - -#endif /* defined(THREADS) */ - -PUBLIC struct _glapi_table *_glapi_Dispatch = (struct _glapi_table *) __glapi_noop_table; - -PUBLIC void *_glapi_Context = NULL; - -#endif /* defined(GLX_USE_TLS) */ -/*@}*/ - - - -#if defined(THREADS) && !defined(GLX_USE_TLS) - -void -_glapi_init_multithread(void) -{ - _glthread_InitTSD(&_gl_DispatchTSD); - _glthread_InitTSD(&ContextTSD); -} - -void -_glapi_destroy_multithread(void) -{ -#ifdef WIN32_THREADS - _glthread_DestroyTSD(&_gl_DispatchTSD); - _glthread_DestroyTSD(&ContextTSD); -#endif -} - -/** - * Mutex for multithread check. - */ -#ifdef WIN32_THREADS -/* _glthread_DECLARE_STATIC_MUTEX is broken on windows. There will be race! */ -#define CHECK_MULTITHREAD_LOCK() -#define CHECK_MULTITHREAD_UNLOCK() -#else -_glthread_DECLARE_STATIC_MUTEX(ThreadCheckMutex); -#define CHECK_MULTITHREAD_LOCK() _glthread_LOCK_MUTEX(ThreadCheckMutex) -#define CHECK_MULTITHREAD_UNLOCK() _glthread_UNLOCK_MUTEX(ThreadCheckMutex) -#endif - -/** - * We should call this periodically from a function such as glXMakeCurrent - * in order to test if multiple threads are being used. - */ -PUBLIC void -_glapi_check_multithread(void) -{ - static unsigned long knownID; - static GLboolean firstCall = GL_TRUE; - - if (ThreadSafe) - return; - - CHECK_MULTITHREAD_LOCK(); - if (firstCall) { - _glapi_init_multithread(); - - knownID = _glthread_GetID(); - firstCall = GL_FALSE; - } - else if (knownID != _glthread_GetID()) { - ThreadSafe = GL_TRUE; - _glapi_set_dispatch(NULL); - _glapi_set_context(NULL); - } - CHECK_MULTITHREAD_UNLOCK(); -} - -#else - -void -_glapi_init_multithread(void) { } - -void -_glapi_destroy_multithread(void) { } - -PUBLIC void -_glapi_check_multithread(void) { } - -#endif - - - -/** - * Set the current context pointer for this thread. - * The context pointer is an opaque type which should be cast to - * void from the real context pointer type. - */ -PUBLIC void -_glapi_set_context(void *context) -{ -#if defined(GLX_USE_TLS) - _glapi_tls_Context = context; -#elif defined(THREADS) - _glthread_SetTSD(&ContextTSD, context); - _glapi_Context = (ThreadSafe) ? NULL : context; -#else - _glapi_Context = context; -#endif -} - - - -/** - * Get the current context pointer for this thread. - * The context pointer is an opaque type which should be cast from - * void to the real context pointer type. - */ -PUBLIC void * -_glapi_get_context(void) -{ -#if defined(GLX_USE_TLS) - return _glapi_tls_Context; -#elif defined(THREADS) - return (ThreadSafe) ? _glthread_GetTSD(&ContextTSD) : _glapi_Context; -#else - return _glapi_Context; -#endif -} - - - -/** - * Set the global or per-thread dispatch table pointer. - * If the dispatch parameter is NULL we'll plug in the no-op dispatch - * table (__glapi_noop_table). - */ -PUBLIC void -_glapi_set_dispatch(struct _glapi_table *dispatch) -{ - init_glapi_relocs_once(); - - if (dispatch == NULL) { - /* use the no-op functions */ - dispatch = (struct _glapi_table *) __glapi_noop_table; - } -#ifdef DEBUG - else { - _glapi_check_table_not_null(dispatch); - _glapi_check_table(dispatch); - } -#endif - -#if defined(GLX_USE_TLS) - _glapi_tls_Dispatch = dispatch; -#elif defined(THREADS) - _glthread_SetTSD(&_gl_DispatchTSD, (void *) dispatch); - _glapi_Dispatch = (ThreadSafe) ? NULL : dispatch; -#else - _glapi_Dispatch = dispatch; -#endif -} - - - -/** - * Return pointer to current dispatch table for calling thread. - */ -PUBLIC struct _glapi_table * -_glapi_get_dispatch(void) -{ -#if defined(GLX_USE_TLS) - return _glapi_tls_Dispatch; -#elif defined(THREADS) - return (ThreadSafe) - ? (struct _glapi_table *) _glthread_GetTSD(&_gl_DispatchTSD) - : _glapi_Dispatch; -#else - return _glapi_Dispatch; -#endif -} diff --git a/src/mapi/glapi/glapi.h b/src/mapi/glapi/glapi.h index 7dcf2e8910b..a74884d595a 100644 --- a/src/mapi/glapi/glapi.h +++ b/src/mapi/glapi/glapi.h @@ -44,15 +44,11 @@ #ifndef _GLAPI_H #define _GLAPI_H -#include "glthread.h" - - -struct _glapi_table; - -typedef void (*_glapi_proc)(void); /* generic function pointer */ - +#ifndef MAPI_GLAPI_CURRENT +#define MAPI_GLAPI_CURRENT +#endif -#if defined(USE_MGL_NAMESPACE) +#ifdef USE_MGL_NAMESPACE #define _glapi_set_dispatch _mglapi_set_dispatch #define _glapi_get_dispatch _mglapi_get_dispatch #define _glapi_set_context _mglapi_set_context @@ -61,111 +57,31 @@ typedef void (*_glapi_proc)(void); /* generic function pointer */ #define _glapi_Context _mglapi_Context #endif +#include "mapi/u_current.h" +#include "glapi/glthread.h" -#if defined(__GNUC__) -# define likely(x) __builtin_expect(!!(x), 1) -# define unlikely(x) __builtin_expect(!!(x), 0) -#else -# define likely(x) (x) -# define unlikely(x) (x) -#endif - - -/** - ** Define the GET_DISPATCH() and GET_CURRENT_CONTEXT() macros. - ** - ** \param C local variable which will hold the current context. - **/ -#if defined (GLX_USE_TLS) - -extern const struct _glapi_table *_glapi_Dispatch; - -extern const void *_glapi_Context; - -extern __thread struct _glapi_table * _glapi_tls_Dispatch - __attribute__((tls_model("initial-exec"))); - -extern __thread void * _glapi_tls_Context - __attribute__((tls_model("initial-exec"))); - -# define GET_DISPATCH() _glapi_tls_Dispatch - -# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) _glapi_tls_Context - -#else - -extern struct _glapi_table *_glapi_Dispatch; - -extern void *_glapi_Context; - -# ifdef THREADS - -# define GET_DISPATCH() \ - (likely(_glapi_Dispatch) ? _glapi_Dispatch : _glapi_get_dispatch()) - -# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) \ - (likely(_glapi_Context) ? _glapi_Context : _glapi_get_context()) - -# else - -# define GET_DISPATCH() _glapi_Dispatch - -# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) _glapi_Context - -# endif - -#endif /* defined (GLX_USE_TLS) */ - - -/** - ** GL API public functions - **/ - -extern void -_glapi_init_multithread(void); - - -extern void -_glapi_destroy_multithread(void); - - -extern void -_glapi_check_multithread(void); - - -extern void -_glapi_set_context(void *context); - - -extern void * -_glapi_get_context(void); - - -extern void -_glapi_set_dispatch(struct _glapi_table *dispatch); - - -extern struct _glapi_table * -_glapi_get_dispatch(void); +typedef void (*_glapi_proc)(void); +#define GET_DISPATCH() ((struct _glapi_table *) u_current_get()) +#define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) u_current_get_user() -extern unsigned int +PUBLIC unsigned int _glapi_get_dispatch_table_size(void); -extern int +PUBLIC int _glapi_add_dispatch( const char * const * function_names, const char * parameter_signature ); -extern int +PUBLIC int _glapi_get_proc_offset(const char *funcName); -extern _glapi_proc +PUBLIC _glapi_proc _glapi_get_proc_address(const char *funcName); -extern const char * +PUBLIC const char * _glapi_get_proc_name(unsigned int offset); diff --git a/src/mapi/glapi/glapi_entrypoint.c b/src/mapi/glapi/glapi_entrypoint.c index 239780e7539..82c68c27c8b 100644 --- a/src/mapi/glapi/glapi_entrypoint.c +++ b/src/mapi/glapi/glapi_entrypoint.c @@ -39,6 +39,7 @@ #include "glapi/glapi.h" #include "glapi/glapi_priv.h" +#include "mapi/u_execmem.h" #ifdef USE_X86_ASM @@ -105,7 +106,7 @@ generate_entrypoint(unsigned int functionOffset) */ const GLubyte * const template_func = gl_dispatch_functions_start + (DISPATCH_FUNCTION_SIZE * 32); - GLubyte * const code = (GLubyte *) _glapi_exec_malloc(DISPATCH_FUNCTION_SIZE); + GLubyte * const code = (GLubyte *) u_execmem_alloc(DISPATCH_FUNCTION_SIZE); if ( code != NULL ) { @@ -288,7 +289,7 @@ generate_entrypoint(GLuint functionOffset) extern unsigned int __glapi_sparc_pthread_stub; unsigned long call_dest = (unsigned long ) &__glapi_sparc_pthread_stub; #endif - unsigned int *code = (unsigned int *) _glapi_exec_malloc(sizeof(template)); + unsigned int *code = (unsigned int *) u_execmem_alloc(sizeof(template)); if (code) { code[0] = template[0] | (functionOffset & 0x3fffff); code[1] = template[1]; diff --git a/src/mapi/glapi/glapi_execmem.c b/src/mapi/glapi/glapi_execmem.c deleted file mode 100644 index 57f00be8dcc..00000000000 --- a/src/mapi/glapi/glapi_execmem.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5 - * - * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -/** - * \file glapi_execmem.c - * - * Function for allocating executable memory for dispatch stubs. - * - * Copied from main/execmem.c and simplified for dispatch stubs. - */ - - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#include "glapi/mesa.h" -#else -#include "main/compiler.h" -#endif - -#include "glapi/glthread.h" -#include "glapi/glapi_priv.h" - - -#if defined(__linux__) || defined(__OpenBSD__) || defined(_NetBSD__) || defined(__sun) - -#include <unistd.h> -#include <sys/mman.h> - -#ifdef MESA_SELINUX -#include <selinux/selinux.h> -#endif - - -#ifndef MAP_ANONYMOUS -#define MAP_ANONYMOUS MAP_ANON -#endif - - -#define EXEC_MAP_SIZE (4*1024) - -_glthread_DECLARE_STATIC_MUTEX(exec_mutex); - -static unsigned int head = 0; - -static unsigned char *exec_mem = NULL; - - -/* - * Dispatch stubs are of fixed size and never freed. Thus, we do not need to - * overlay a heap, we just mmap a page and manage through an index. - */ - -static int -init_map(void) -{ -#ifdef MESA_SELINUX - if (is_selinux_enabled()) { - if (!security_get_boolean_active("allow_execmem") || - !security_get_boolean_pending("allow_execmem")) - return 0; - } -#endif - - if (!exec_mem) - exec_mem = mmap(NULL, EXEC_MAP_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - - return (exec_mem != MAP_FAILED); -} - - -void * -_glapi_exec_malloc(unsigned int size) -{ - void *addr = NULL; - - _glthread_LOCK_MUTEX(exec_mutex); - - if (!init_map()) - goto bail; - - /* free space check, assumes no integer overflow */ - if (head + size > EXEC_MAP_SIZE) - goto bail; - - /* allocation, assumes proper addr and size alignement */ - addr = exec_mem + head; - head += size; - -bail: - _glthread_UNLOCK_MUTEX(exec_mutex); - - return addr; -} - - -#else - -void * -_glapi_exec_malloc(unsigned int size) -{ - return malloc(size); -} - - -#endif diff --git a/src/mapi/glapi/glapi_getproc.c b/src/mapi/glapi/glapi_getproc.c index c73e8dd3b04..3c134f929d6 100644 --- a/src/mapi/glapi/glapi_getproc.c +++ b/src/mapi/glapi/glapi_getproc.c @@ -387,7 +387,7 @@ set_entry_info( struct _glapi_function * entry, const char * signature, unsigned * the parameter signature of a static function. */ -PUBLIC int +int _glapi_add_dispatch( const char * const * function_names, const char * parameter_signature ) { @@ -501,7 +501,7 @@ _glapi_add_dispatch( const char * const * function_names, /** * Return offset of entrypoint for named function within dispatch table. */ -PUBLIC GLint +GLint _glapi_get_proc_offset(const char *funcName) { GLint offset; @@ -522,7 +522,7 @@ _glapi_get_proc_offset(const char *funcName) * in the name of static functions, try generating a new API entrypoint on * the fly with assembly language. */ -PUBLIC _glapi_proc +_glapi_proc _glapi_get_proc_address(const char *funcName) { _glapi_proc func; @@ -598,7 +598,7 @@ _glapi_get_proc_name(GLuint offset) * Return size of dispatch table struct as number of functions (or * slots). */ -PUBLIC GLuint +GLuint _glapi_get_dispatch_table_size(void) { return DISPATCH_TABLE_SIZE; diff --git a/src/mapi/glapi/glapi_priv.h b/src/mapi/glapi/glapi_priv.h index da6fee63fe7..1c2a7042113 100644 --- a/src/mapi/glapi/glapi_priv.h +++ b/src/mapi/glapi/glapi_priv.h @@ -41,12 +41,6 @@ extern void _glapi_check_table(const struct _glapi_table *table); -/* execmem */ - -extern void * -_glapi_exec_malloc(unsigned int size); - - /* entrypoint */ extern void diff --git a/src/mapi/glapi/glthread.c b/src/mapi/glapi/glthread.c index f365d17bdda..9dbc0e9a56f 100644 --- a/src/mapi/glapi/glthread.c +++ b/src/mapi/glapi/glthread.c @@ -1,263 +1,7 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5.1 - * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ +#include "glthread.h" - -/* - * XXX There's probably some work to do in order to make this file - * truly reusable outside of Mesa. First, the glheader.h include must go. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#include "glapi/mesa.h" -#else -#include "main/compiler.h" -#endif - -#include "glapi/glthread.h" - - -/* - * This file should still compile even when THREADS is not defined. - * This is to make things easier to deal with on the makefile scene.. - */ -#ifdef THREADS -#include <errno.h> - -/* - * Error messages - */ -#define INIT_TSD_ERROR "_glthread_: failed to allocate key for thread specific data" -#define GET_TSD_ERROR "_glthread_: failed to get thread specific data" -#define SET_TSD_ERROR "_glthread_: thread failed to set thread specific data" - - -/* - * Magic number to determine if a TSD object has been initialized. - * Kind of a hack but there doesn't appear to be a better cross-platform - * solution. - */ -#define INIT_MAGIC 0xff8adc98 - - - -/* - * POSIX Threads -- The best way to go if your platform supports them. - * Solaris >= 2.5 have POSIX threads, IRIX >= 6.4 reportedly - * has them, and many of the free Unixes now have them. - * Be sure to use appropriate -mt or -D_REENTRANT type - * compile flags when building. - */ -#ifdef PTHREADS - -PUBLIC unsigned long -_glthread_GetID(void) -{ - return (unsigned long) pthread_self(); -} - - -void -_glthread_InitTSD(_glthread_TSD *tsd) -{ - if (pthread_key_create(&tsd->key, NULL/*free*/) != 0) { - perror(INIT_TSD_ERROR); - exit(-1); - } - tsd->initMagic = INIT_MAGIC; -} - - -void * -_glthread_GetTSD(_glthread_TSD *tsd) -{ - if (tsd->initMagic != (int) INIT_MAGIC) { - _glthread_InitTSD(tsd); - } - return pthread_getspecific(tsd->key); -} - - -void -_glthread_SetTSD(_glthread_TSD *tsd, void *ptr) -{ - if (tsd->initMagic != (int) INIT_MAGIC) { - _glthread_InitTSD(tsd); - } - if (pthread_setspecific(tsd->key, ptr) != 0) { - perror(SET_TSD_ERROR); - exit(-1); - } -} - -#endif /* PTHREADS */ - - - -/* - * Win32 Threads. The only available option for Windows 95/NT. - * Be sure that you compile using the Multithreaded runtime, otherwise - * bad things will happen. - */ -#ifdef WIN32_THREADS - -static void InsteadOf_exit(int nCode) -{ - DWORD dwErr = GetLastError(); -} - -PUBLIC unsigned long -_glthread_GetID(void) -{ - return GetCurrentThreadId(); -} - - -void -_glthread_InitTSD(_glthread_TSD *tsd) -{ - tsd->key = TlsAlloc(); - if (tsd->key == TLS_OUT_OF_INDEXES) { - perror(INIT_TSD_ERROR); - InsteadOf_exit(-1); - } - tsd->initMagic = INIT_MAGIC; -} - - -void -_glthread_DestroyTSD(_glthread_TSD *tsd) -{ - if (tsd->initMagic != INIT_MAGIC) { - return; - } - TlsFree(tsd->key); - tsd->initMagic = 0x0; -} - - -void * -_glthread_GetTSD(_glthread_TSD *tsd) -{ - if (tsd->initMagic != INIT_MAGIC) { - _glthread_InitTSD(tsd); - } - return TlsGetValue(tsd->key); -} - - -void -_glthread_SetTSD(_glthread_TSD *tsd, void *ptr) -{ - /* the following code assumes that the _glthread_TSD has been initialized - to zero at creation */ - if (tsd->initMagic != INIT_MAGIC) { - _glthread_InitTSD(tsd); - } - if (TlsSetValue(tsd->key, ptr) == 0) { - perror(SET_TSD_ERROR); - InsteadOf_exit(-1); - } -} - -#endif /* WIN32_THREADS */ - -/* - * BeOS threads - */ -#ifdef BEOS_THREADS - -PUBLIC unsigned long +unsigned long _glthread_GetID(void) { - return (unsigned long) find_thread(NULL); + return u_thread_self(); } - -void -_glthread_InitTSD(_glthread_TSD *tsd) -{ - tsd->key = tls_allocate(); - tsd->initMagic = INIT_MAGIC; -} - -void * -_glthread_GetTSD(_glthread_TSD *tsd) -{ - if (tsd->initMagic != (int) INIT_MAGIC) { - _glthread_InitTSD(tsd); - } - return tls_get(tsd->key); -} - -void -_glthread_SetTSD(_glthread_TSD *tsd, void *ptr) -{ - if (tsd->initMagic != (int) INIT_MAGIC) { - _glthread_InitTSD(tsd); - } - tls_set(tsd->key, ptr); -} - -#endif /* BEOS_THREADS */ - - - -#else /* THREADS */ - - -/* - * no-op functions - */ - -PUBLIC unsigned long -_glthread_GetID(void) -{ - return 0; -} - - -void -_glthread_InitTSD(_glthread_TSD *tsd) -{ - (void) tsd; -} - - -void * -_glthread_GetTSD(_glthread_TSD *tsd) -{ - (void) tsd; - return NULL; -} - - -void -_glthread_SetTSD(_glthread_TSD *tsd, void *ptr) -{ - (void) tsd; - (void) ptr; -} - - -#endif /* THREADS */ diff --git a/src/mapi/glapi/glthread.h b/src/mapi/glapi/glthread.h index 4fe99284a8c..54292706acf 100644 --- a/src/mapi/glapi/glthread.h +++ b/src/mapi/glapi/glthread.h @@ -1,255 +1,23 @@ -/* - * Mesa 3-D graphics library - * Version: 6.5.2 - * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* - * Thread support for gl dispatch. - * - * Initial version by John Stone ([email protected]) ([email protected]) - * and Christoph Poliwoda ([email protected]) - * Revised by Keith Whitwell - * Adapted for new gl dispatcher by Brian Paul - * - * - * - * DOCUMENTATION - * - * This thread module exports the following types: - * _glthread_TSD Thread-specific data area - * _glthread_Thread Thread datatype - * _glthread_Mutex Mutual exclusion lock - * - * Macros: - * _glthread_DECLARE_STATIC_MUTEX(name) Declare a non-local mutex - * _glthread_INIT_MUTEX(name) Initialize a mutex - * _glthread_LOCK_MUTEX(name) Lock a mutex - * _glthread_UNLOCK_MUTEX(name) Unlock a mutex - * - * Functions: - * _glthread_GetID(v) Get integer thread ID - * _glthread_InitTSD() Initialize thread-specific data - * _glthread_GetTSD() Get thread-specific data - * _glthread_SetTSD() Set thread-specific data - * - */ - -/* - * If this file is accidentally included by a non-threaded build, - * it should not cause the build to fail, or otherwise cause problems. - * In general, it should only be included when needed however. - */ - #ifndef GLTHREAD_H #define GLTHREAD_H +#include "mapi/u_thread.h" -#if defined(PTHREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS) -#ifndef THREADS -#define THREADS -#endif -#endif - - -/* - * POSIX threads. This should be your choice in the Unix world - * whenever possible. When building with POSIX threads, be sure - * to enable any compiler flags which will cause the MT-safe - * libc (if one exists) to be used when linking, as well as any - * header macros for MT-safe errno, etc. For Solaris, this is the -mt - * compiler flag. On Solaris with gcc, use -D_REENTRANT to enable - * proper compiling for MT-safe libc etc. - */ -#if defined(PTHREADS) -#include <pthread.h> /* POSIX threads headers */ - -typedef struct { - pthread_key_t key; - int initMagic; -} _glthread_TSD; - -typedef pthread_t _glthread_Thread; - -typedef pthread_mutex_t _glthread_Mutex; - -#define _glthread_DECLARE_STATIC_MUTEX(name) \ - static _glthread_Mutex name = PTHREAD_MUTEX_INITIALIZER - -#define _glthread_INIT_MUTEX(name) \ - pthread_mutex_init(&(name), NULL) - -#define _glthread_DESTROY_MUTEX(name) \ - pthread_mutex_destroy(&(name)) - -#define _glthread_LOCK_MUTEX(name) \ - (void) pthread_mutex_lock(&(name)) - -#define _glthread_UNLOCK_MUTEX(name) \ - (void) pthread_mutex_unlock(&(name)) - -#endif /* PTHREADS */ - - -/* - * Windows threads. Should work with Windows NT and 95. - * IMPORTANT: Link with multithreaded runtime library when THREADS are - * used! - */ -#ifdef WIN32_THREADS -#include <windows.h> - -typedef struct { - DWORD key; - int initMagic; -} _glthread_TSD; - -typedef HANDLE _glthread_Thread; - -typedef CRITICAL_SECTION _glthread_Mutex; - -#define _glthread_DECLARE_STATIC_MUTEX(name) \ - /* static */ _glthread_Mutex name = { 0, 0, 0, 0, 0, 0 } - -#define _glthread_INIT_MUTEX(name) \ - InitializeCriticalSection(&name) - -#define _glthread_DESTROY_MUTEX(name) \ - DeleteCriticalSection(&name) - -#define _glthread_LOCK_MUTEX(name) \ - EnterCriticalSection(&name) - -#define _glthread_UNLOCK_MUTEX(name) \ - LeaveCriticalSection(&name) - -#endif /* WIN32_THREADS */ - - -/* - * BeOS threads. R5.x required. - */ -#ifdef BEOS_THREADS - -/* Problem with OS.h and this file on haiku */ -#ifndef __HAIKU__ -#include <kernel/OS.h> -#endif - -#include <support/TLS.h> - -/* The only two typedefs required here - * this is cause of the OS.h problem - */ -#ifdef __HAIKU__ -typedef int32 thread_id; -typedef int32 sem_id; -#endif +#define _glthread_DECLARE_STATIC_MUTEX(name) u_mutex_declare_static(name) +#define _glthread_INIT_MUTEX(name) u_mutex_init(name) +#define _glthread_DESTROY_MUTEX(name) u_mutex_destroy(name) +#define _glthread_LOCK_MUTEX(name) u_mutex_lock(name) +#define _glthread_UNLOCK_MUTEX(name) u_mutex_unlock(name) -typedef struct { - int32 key; - int initMagic; -} _glthread_TSD; +#define _glthread_InitTSD(tsd) u_tsd_init(tsd); +#define _glthread_DestroyTSD(tsd) u_tsd_destroy(tsd); +#define _glthread_GetTSD(tsd) u_tsd_get(tsd); +#define _glthread_SetTSD(tsd, ptr) u_tsd_set(tsd, ptr); -typedef thread_id _glthread_Thread; +typedef struct u_tsd _glthread_TSD; +typedef u_mutex _glthread_Mutex; -/* Use Benaphore, aka speeder semaphore */ -typedef struct { - int32 lock; - sem_id sem; -} benaphore; -typedef benaphore _glthread_Mutex; - -#define _glthread_DECLARE_STATIC_MUTEX(name) \ - static _glthread_Mutex name = { 0, 0 } - -#define _glthread_INIT_MUTEX(name) \ - name.sem = create_sem(0, #name"_benaphore"), \ - name.lock = 0 - -#define _glthread_DESTROY_MUTEX(name) \ - delete_sem(name.sem), \ - name.lock = 0 - -#define _glthread_LOCK_MUTEX(name) \ - if (name.sem == 0) \ - _glthread_INIT_MUTEX(name); \ - if (atomic_add(&(name.lock), 1) >= 1) \ - acquire_sem(name.sem) - -#define _glthread_UNLOCK_MUTEX(name) \ - if (atomic_add(&(name.lock), -1) > 1) \ - release_sem(name.sem) - -#endif /* BEOS_THREADS */ - - -/* - * THREADS not defined - */ -#ifndef THREADS - -typedef unsigned _glthread_TSD; - -typedef unsigned _glthread_Thread; - -typedef unsigned _glthread_Mutex; - -#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0 - -#define _glthread_INIT_MUTEX(name) (void) name - -#define _glthread_DESTROY_MUTEX(name) (void) name - -#define _glthread_LOCK_MUTEX(name) (void) name - -#define _glthread_UNLOCK_MUTEX(name) (void) name - -#endif /* THREADS */ - - - -/* - * Platform independent thread specific data API. - */ - -extern unsigned long +PUBLIC unsigned long _glthread_GetID(void); - -extern void -_glthread_InitTSD(_glthread_TSD *); - - -extern void -_glthread_DestroyTSD(_glthread_TSD *); /* WIN32 only */ - - -extern void * -_glthread_GetTSD(_glthread_TSD *); - - -extern void -_glthread_SetTSD(_glthread_TSD *, void *); - - #endif /* THREADS_H */ diff --git a/src/mapi/glapi/sources.mak b/src/mapi/glapi/sources.mak index 8e1e82f359a..cdcfa36e51f 100644 --- a/src/mapi/glapi/sources.mak +++ b/src/mapi/glapi/sources.mak @@ -1,10 +1,8 @@ # src/mapi/glapi/sources.mak GLAPI_SOURCES = \ - glapi.c \ glapi_dispatch.c \ glapi_entrypoint.c \ - glapi_execmem.c \ glapi_getproc.c \ glapi_nop.c \ glthread.c |