From: Brian Paul Date: Fri, 17 Dec 1999 12:21:38 +0000 (+0000) Subject: fixed thread problems X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c633693a28caa6ba09bb04e283b485f54f4d498e;p=mesa.git fixed thread problems --- diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 0d756de63e9..1e192f589fc 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1,4 +1,4 @@ -/* $Id: context.c,v 1.27 1999/12/10 19:09:21 brianp Exp $ */ +/* $Id: context.c,v 1.28 1999/12/17 12:21:38 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -25,15 +25,6 @@ */ -/* - * If multi-threading is enabled (-DTHREADS) then each thread has it's - * own rendering context. A thread obtains the pointer to its GLcontext - * with the gl_get_thread_context() function. Otherwise, the global - * pointer, CC, points to the current context used by all threads in - * the address space. - */ - - #ifdef PC_HEADER #include "all.h" #else @@ -94,10 +85,13 @@ #ifdef THREADS -#include "mthreads.h" -static MesaTSD mesa_ctx_tsd; -static void mesa_ctx_thread_init() { - MesaInitTSD(&mesa_ctx_tsd); +#include "glthread.h" + +static _glthread_TSD ContextTSD; + +static void ctx_thread_init() +{ + _glthread_InitTSD(&ContextTSD); } #else @@ -1275,14 +1269,6 @@ GLcontext *gl_create_context( GLvisual *visual, } - /* Fill in some driver defaults now. - */ -#if 0 - ctx->Driver.AllocDepthBuffer = gl_alloc_depth_buffer; - ctx->Driver.ReadDepthSpanFloat = gl_read_depth_span_float; - ctx->Driver.ReadDepthSpanInt = gl_read_depth_span_int; -#endif - #ifdef PROFILE init_timings( ctx ); #endif @@ -1323,6 +1309,11 @@ void gl_destroy_context( GLcontext *ctx ) GLuint i; struct gl_shine_tab *s, *tmps; + /* if we're destroying the current context, unbind it first */ + if (ctx == gl_get_current_context()) { + gl_make_current(NULL, NULL); + } + #ifdef PROFILE if (getenv("MESA_PROFILE")) { print_timings( ctx ); @@ -1410,14 +1401,6 @@ void gl_destroy_context( GLcontext *ctx ) gl_extensions_dtr(ctx); FREE( (void *) ctx ); - -#ifndef THREADS - if (ctx == _mesa_current_context) { - _mesa_current_context = NULL; - CURRENT_INPUT = NULL; - } -#endif - } } @@ -1524,36 +1507,39 @@ void gl_make_current( GLcontext *newCtx, GLframebuffer *buffer ) void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer, GLframebuffer *readBuffer ) { - GET_CURRENT_CONTEXT(oldCtx); +#if 0 + GLcontext *oldCtx = gl_get_current_context(); /* Flush the old context */ if (oldCtx) { ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(oldCtx, "gl_make_current"); - } - /* unbind frame buffers from context */ - if (oldCtx && oldCtx->DrawBuffer) { - oldCtx->DrawBuffer = NULL; - } - if (oldCtx && oldCtx->ReadBuffer) { - oldCtx->ReadBuffer = NULL; + /* unbind frame buffers from context */ + if (oldCtx->DrawBuffer) { + oldCtx->DrawBuffer = NULL; + } + if (oldCtx->ReadBuffer) { + oldCtx->ReadBuffer = NULL; + } } +#endif + + _glapi_check_multithread(); #ifdef THREADS - /* TODO: unbind old buffer from context? */ - MesaSetTSD(&mesa_ctx_tsd, (void *) newCtx, mesa_ctx_thread_init); + _glthread_SetTSD(&ContextTSD, (void *) newCtx, ctx_thread_init); + ASSERT(gl_get_current_context() == newCtx); #else _mesa_current_context = newCtx; #endif if (newCtx) { SET_IMMEDIATE(newCtx, newCtx->input); - } - - if (newCtx) _glapi_set_dispatch(newCtx->CurrentDispatch); - else + } + else { _glapi_set_dispatch(NULL); /* none current */ + } if (MESA_VERBOSE) fprintf(stderr, "gl_make_current()\n"); @@ -1589,7 +1575,8 @@ void gl_make_current2( GLcontext *newCtx, GLframebuffer *drawBuffer, GLcontext *gl_get_current_context( void ) { #ifdef THREADS - return (GLcontext *) MesaGetTSD(&mesa_ctx_tsd); + GLcontext *c = (GLcontext *) _glthread_GetTSD(&ContextTSD); + return c; #else return _mesa_current_context; #endif diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h index 32dd613c140..76ac1bb327a 100644 --- a/src/mesa/main/context.h +++ b/src/mesa/main/context.h @@ -1,4 +1,4 @@ -/* $Id: context.h,v 1.5 1999/12/10 19:09:22 brianp Exp $ */ +/* $Id: context.h,v 1.6 1999/12/17 12:21:39 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -116,27 +116,25 @@ extern GLcontext *gl_get_current_context(void); #ifdef THREADS - /* - * A seperate GLcontext for each thread - */ - - #define GET_CURRENT_CONTEXT(C) GLcontext *C = gl_get_current_context() +/* + * A seperate GLcontext for each thread + */ +#define GET_CURRENT_CONTEXT(C) GLcontext *C = gl_get_current_context() #define GET_IMMEDIATE struct immediate *IM = (gl_get_current_context())->input; #define SET_IMMEDIATE(ctx, im) \ do { \ ctx->input = im; \ } while (0) - #else - /* - * All threads use same pointer to current context. - */ - extern GLcontext *_mesa_current_context; - extern struct immediate *CURRENT_INPUT; - #define GET_CURRENT_CONTEXT(C) GLcontext *C = _mesa_current_context +/* + * All threads use same pointer to current context. + */ +extern GLcontext *_mesa_current_context; +extern struct immediate *CURRENT_INPUT; +#define GET_CURRENT_CONTEXT(C) GLcontext *C = _mesa_current_context #define GET_IMMEDIATE struct immediate *IM = CURRENT_INPUT #define SET_IMMEDIATE(ctx, im) \ do { \ @@ -144,7 +142,6 @@ do { \ CURRENT_INPUT = im; \ } while (0) - #endif