thread safety fixes from trunk

This commit is contained in:
Brian Paul 2006-03-15 21:02:52 +00:00
parent 427bf0171d
commit b87f9f6056
2 changed files with 51 additions and 66 deletions

View file

@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
* 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"),
@ -54,7 +54,6 @@
#include "glapi.h"
#include "glapioffsets.h"
#include "glapitable.h"
#include "glthread.h"
/***** BEGIN NO-OP DISPATCH *****/
@ -287,14 +286,14 @@ _glapi_get_context(void)
/**
* 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)
{
#if defined(PTHREADS) || defined(GLX_USE_TLS)
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
pthread_once( & once_control, init_glapi_relocs );
#endif
@ -327,7 +326,6 @@ PUBLIC struct _glapi_table *
_glapi_get_dispatch(void)
{
struct _glapi_table * api;
#if defined(GLX_USE_TLS)
api = _glapi_tls_Dispatch;
#elif defined(THREADS)
@ -337,13 +335,17 @@ _glapi_get_dispatch(void)
#else
api = _glapi_Dispatch;
#endif
assert( api != NULL );
return api;
}
#if !defined( USE_X86_ASM ) && !defined( XFree86Server )
/***
*** The rest of this file is pretty much concerned with GetProcAddress
*** functionality.
***/
#if !defined( USE_X86_ASM ) && !defined( XFree86Server ) && !defined ( XGLServer )
#define NEED_FUNCTION_POINTER
#endif
@ -359,13 +361,10 @@ static const glprocs_table_t *
find_entry( const char * n )
{
GLuint i;
for (i = 0; static_functions[i].Name_offset >= 0; i++) {
const char * test_name;
test_name = gl_string_table + static_functions[i].Name_offset;
if (strcmp(test_name, n) == 0) {
return & static_functions[i];
const char *testName = gl_string_table + static_functions[i].Name_offset;
if (strcmp(testName, n) == 0) {
return &static_functions[i];
}
}
return NULL;
@ -380,15 +379,14 @@ static GLint
get_static_proc_offset(const char *funcName)
{
const glprocs_table_t * const f = find_entry( funcName );
if ( f != NULL ) {
if (f) {
return f->Offset;
}
return -1;
}
#if !defined( XFree86Server )
#if !defined(XFree86Server) && !defined(XGLServer)
#ifdef USE_X86_ASM
#if defined( GLX_USE_TLS )
@ -404,42 +402,33 @@ extern const GLubyte gl_dispatch_functions_start[];
# define X86_DISPATCH_FUNCTION_SIZE 16
# endif
#endif /* USE_X86_ASM */
/**
* Return dispatch function address the named static (built-in) function.
* Return dispatch function address for the named static (built-in) function.
* Return NULL if function not found.
*/
static const _glapi_proc
get_static_proc_address(const char *funcName)
{
const glprocs_table_t * const f = find_entry( funcName );
if ( f != NULL ) {
if (f) {
#ifdef USE_X86_ASM
return (_glapi_proc) (gl_dispatch_functions_start
+ (X86_DISPATCH_FUNCTION_SIZE * f->Offset));
#else
return f->Address;
#endif
}
else {
return NULL;
}
}
#else
#endif /* !defined(XFree86Server) && !defined(XGLServer) */
/**
* Return pointer to the named static (built-in) function.
* \return NULL if function not found.
*/
static const _glapi_proc
get_static_proc_address(const char *funcName)
{
const glprocs_table_t * const f = find_entry( funcName );
return ( f != NULL ) ? f->Address : NULL;
}
#endif /* USE_X86_ASM */
#endif /* !defined( XFree86Server ) */
/**
* Return the name of the function at the given offset in the dispatch
@ -449,7 +438,6 @@ static const char *
get_static_proc_name( GLuint offset )
{
GLuint i;
for (i = 0; static_functions[i].Name_offset >= 0; i++) {
if (static_functions[i].Offset == offset) {
return gl_string_table + static_functions[i].Name_offset;
@ -579,7 +567,7 @@ generate_entrypoint(GLuint functionOffset)
0x81c0c000, /* jmpl %g3, %g0 */
0x01000000 /* nop */
};
#endif
#endif /* __arch64__ */
unsigned int *code = (unsigned int *) malloc(sizeof(insn_template));
unsigned long glapi_addr = (unsigned long) &_glapi_Dispatch;
if (code) {
@ -601,7 +589,7 @@ generate_entrypoint(GLuint functionOffset)
__glapi_sparc_icache_flush(&code[0]);
code[2] |= (functionOffset * 4);
__glapi_sparc_icache_flush(&code[2]);
#endif
#endif /* __arch64__ */
}
return (_glapi_proc) code;
#else
@ -621,7 +609,6 @@ fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset)
#if defined(USE_X86_ASM)
GLubyte * const code = (GLubyte *) entrypoint;
#if X86_DISPATCH_FUNCTION_SIZE == 32
*((unsigned int *)(code + 11)) = 4 * offset;
*((unsigned int *)(code + 22)) = 4 * offset;
@ -763,14 +750,8 @@ _glapi_add_dispatch( const char * const * function_names,
/* Do some trivial validation on the name of the function.
*/
#ifdef MANGLE
if (!function_names[i] || function_names[i][0] != 'm' || function_names[i][1] != 'g' || function_names[i][2] != 'l')
return GL_FALSE;
#else
if (!function_names[i] || function_names[i][0] != 'g' || function_names[i][1] != 'l')
return GL_FALSE;
#endif
/* Determine if the named function already exists. If the function does
* exist, it must have the same parameter signature as the function
@ -817,13 +798,11 @@ _glapi_add_dispatch( const char * const * function_names,
}
}
if (offset == ~0) {
offset = next_dynamic_offset;
next_dynamic_offset++;
}
for ( i = 0 ; function_names[i] != NULL ; i++ ) {
if (! is_static[i] ) {
if (entry[i] == NULL) {
@ -835,7 +814,6 @@ _glapi_add_dispatch( const char * const * function_names,
}
}
entry[i]->parameter_signature = str_dup(real_sig);
fill_in_entrypoint_offset(entry[i]->dispatch_stub, offset);
entry[i]->dispatch_offset = offset;
@ -859,7 +837,6 @@ _glapi_get_proc_offset(const char *funcName)
return ExtEntryTable[i].dispatch_offset;
}
}
/* search static functions */
return get_static_proc_offset(funcName);
}
@ -892,7 +869,7 @@ _glapi_get_proc_address(const char *funcName)
}
}
#if !defined( XFree86Server )
#if !defined( XFree86Server ) && !defined( XGLServer )
/* search static functions */
{
const _glapi_proc func = get_static_proc_address(funcName);

View file

@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
* 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"),
@ -47,10 +47,26 @@
#include "GL/gl.h"
#include "glapitable.h"
#include "glthread.h"
typedef void (*_glapi_warning_func)(void *ctx, const char *str, ...);
#if defined(USE_MGL_NAMESPACE)
#define _glapi_set_dispatch _mglapi_set_dispatch
#define _glapi_get_dispatch _mglapi_get_dispatch
#define _glapi_set_context _mglapi_set_context
#define _glapi_get_context _mglapi_get_context
#define _glapi_Context _mglapi_Context
#define _glapi_Dispatch _mglapi_Dispatch
#endif
/**
** Define the GET_CURRENT_CONTEXT() macro.
** \param C local variable which will hold the current context.
**/
#if defined (GLX_USE_TLS)
const extern void *_glapi_Context;
@ -66,19 +82,6 @@ extern __thread void * _glapi_tls_Context
extern void *_glapi_Context;
extern struct _glapi_table *_glapi_Dispatch;
/**
* Macro for declaration and fetching the current context.
*
* \param C local variable which will hold the current context.
*
* It should be used in the variable declaration area of a function:
* \code
* ...
* {
* GET_CURRENT_CONTEXT(ctx);
* ...
* \endcode
*/
# ifdef THREADS
# define GET_CURRENT_CONTEXT(C) GLcontext *C = (GLcontext *) (_glapi_Context ? _glapi_Context : _glapi_get_context())
# else
@ -87,6 +90,11 @@ extern struct _glapi_table *_glapi_Dispatch;
#endif /* defined (GLX_USE_TLS) */
/**
** GL API public functions
**/
extern void
_glapi_noop_enable_warnings(GLboolean enable);