diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index 2db29fd6abb..2f141acae83 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -393,24 +393,24 @@ driReleaseDrawables(struct glx_context *gc) return; if (__glxHashLookup(priv->drawHash, - gc->currentDrawable, (void *) &pdraw) == 0) { + gc->currentDrawable, (void *) &pdraw) == 0) { if (pdraw->drawable == pdraw->xDrawable) { - pdraw->refcount --; - if (pdraw->refcount == 0) { - (*pdraw->destroyDrawable)(pdraw); - __glxHashDelete(priv->drawHash, gc->currentDrawable); - } + pdraw->refcount --; + if (pdraw->refcount == 0) { + (*pdraw->destroyDrawable)(pdraw); + __glxHashDelete(priv->drawHash, gc->currentDrawable); + } } } if (__glxHashLookup(priv->drawHash, - gc->currentReadable, (void *) &pdraw) == 0) { + gc->currentReadable, (void *) &pdraw) == 0) { if (pdraw->drawable == pdraw->xDrawable) { - pdraw->refcount --; - if (pdraw->refcount == 0) { - (*pdraw->destroyDrawable)(pdraw); - __glxHashDelete(priv->drawHash, gc->currentReadable); - } + pdraw->refcount --; + if (pdraw->refcount == 0) { + (*pdraw->destroyDrawable)(pdraw); + __glxHashDelete(priv->drawHash, gc->currentReadable); + } } } diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c index 2b9c708c3ee..60f7d7ed08d 100644 --- a/src/glx/glxcurrent.c +++ b/src/glx/glxcurrent.c @@ -139,6 +139,7 @@ _X_HIDDEN void __glXSetCurrentContextNull(void) { __glXSetCurrentContext(&dummyContext); + fprintf (stderr, "%s \n", __func__); #if defined(GLX_DIRECT_RENDERING) _glapi_set_dispatch(NULL); /* no-op functions */ _glapi_set_context(NULL); diff --git a/src/mapi/glapi/glapi.c b/src/mapi/glapi/glapi.c index 55258a476c7..508888426f2 100644 --- a/src/mapi/glapi/glapi.c +++ b/src/mapi/glapi/glapi.c @@ -51,9 +51,11 @@ _glapi_check_multithread(void) u_current_init(); } +#include "stdio.h" void _glapi_set_context(void *context) { + fprintf (stderr, "%s context: %p \n", __func__, context); u_current_set_context((const void *) context); } diff --git a/src/mapi/mapi_glapi.c b/src/mapi/mapi_glapi.c index 3a376e81bdd..fa4dd7c3913 100644 --- a/src/mapi/mapi_glapi.c +++ b/src/mapi/mapi_glapi.c @@ -56,9 +56,12 @@ _glapi_check_multithread(void) u_current_init(); } +#include "stdio.h" + void _glapi_set_context(void *context) { + fprintf (stderr, "%s context: %p \n", __func__, context); u_current_set_context((const void *) context); } diff --git a/src/mapi/u_current.c b/src/mapi/u_current.c index 1402cea45d5..d0c0f9b26b5 100644 --- a/src/mapi/u_current.c +++ b/src/mapi/u_current.c @@ -220,13 +220,22 @@ u_current_init(void) +#include "stdio.h" + +typedef thrd_t thread_id; +static inline thread_id +get_thread_id(void) +{ + return thrd_current(); +} + /** * 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. */ void -u_current_set_context(const void *ptr) +_u_current_set_context(const void *ptr, const char *func) { u_current_init(); @@ -236,6 +245,7 @@ u_current_set_context(const void *ptr) tss_set(u_current_context_tsd, (void *) ptr); u_current_context = (ThreadSafe) ? NULL : (void *) ptr; #endif + fprintf (stderr, "%s u_current_context: %p from %s id: %#lx \n", __func__, u_current_context, func, get_thread_id()); } /** @@ -247,8 +257,10 @@ void * u_current_get_context_internal(void) { #if defined(GLX_USE_TLS) + fprintf (stderr, "%s tls u_current_context: %p id: %#lx \n", __func__, u_current_context, get_thread_id()); return u_current_context; #else + fprintf (stderr, "%s nottls ThreadSafe: %d u_current_context: %p \n", __func__, ThreadSafe, ThreadSafe ? tss_get(u_current_context_tsd) : u_current_context); return ThreadSafe ? tss_get(u_current_context_tsd) : u_current_context; #endif } diff --git a/src/mapi/u_current.h b/src/mapi/u_current.h index 3c9a414ee84..44c261c6604 100644 --- a/src/mapi/u_current.h +++ b/src/mapi/u_current.h @@ -57,7 +57,10 @@ struct _glapi_table * u_current_get_table_internal(void); void -u_current_set_context(const void *ptr); +_u_current_set_context(const void *ptr, const char *func); + +#define u_current_set_context(ptr) \ + _u_current_set_context(ptr, __func__) void * u_current_get_context_internal(void); diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index ac3a04bceff..9a8850c43c0 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -545,8 +545,33 @@ driCopyContext(__DRIcontext *dest, __DRIcontext *src, unsigned long mask) /*****************************************************************/ /*@{*/ -static void dri_get_drawable(__DRIdrawable *pdp); -static void dri_put_drawable(__DRIdrawable *pdp); +static void _dri_get_drawable(__DRIdrawable *pdp, const char *func) +{ + pdp->refcount++; + + fprintf(stderr, "%s pdp: %p, refcount: %d from: %s \n", + __func__, pdp, pdp ? pdp->refcount : 0, func); +} + +#define dri_get_drawable(pdp) \ + _dri_get_drawable(pdp, __func__) + +static void _dri_put_drawable(__DRIdrawable *pdp, const char *func) +{ + fprintf(stderr, "%s pdp: %p, refcount: %d from: %s \n", + __func__, pdp, pdp ? pdp->refcount - 1 : 0, func); + if (pdp) { + pdp->refcount--; + if (pdp->refcount) + return; + + pdp->driScreenPriv->driver->DestroyBuffer(pdp); + free(pdp); + } +} + +#define dri_put_drawable(pdp) \ + _dri_put_drawable(pdp, __func__) /** * This function takes both a read buffer and a draw buffer. This is needed @@ -647,22 +672,6 @@ static int driUnbindContext(__DRIcontext *pcp) /*@}*/ -static void dri_get_drawable(__DRIdrawable *pdp) -{ - pdp->refcount++; -} - -static void dri_put_drawable(__DRIdrawable *pdp) -{ - if (pdp) { - pdp->refcount--; - if (pdp->refcount) - return; - - pdp->driScreenPriv->driver->DestroyBuffer(pdp); - free(pdp); - } -} static __DRIdrawable * driCreateNewDrawable(__DRIscreen *screen, diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index c3d4784e94c..de5b5fe9126 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -1228,7 +1228,10 @@ intelDestroyContext(__DRIcontext * driContextPriv) GLboolean intelUnbindContext(__DRIcontext * driContextPriv) { - GET_CURRENT_CONTEXT(ctx); + //GET_CURRENT_CONTEXT(ctx); + struct gl_context *ctx = (struct gl_context *) (likely(_glapi_Context) + ? _glapi_Context : _glapi_get_context()); + fprintf (stderr, "%s _glapi_Context: %p \n", __func__, _glapi_Context); _mesa_glthread_finish(ctx); /* Unset current context and dispath table */ diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c index d84793f71f8..cc5c4436263 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.c +++ b/src/mesa/drivers/dri/i965/intel_screen.c @@ -1688,6 +1688,7 @@ static void intelDestroyScreen(__DRIscreen * sPriv) { struct intel_screen *screen = sPriv->driverPrivate; + fprintf(stderr, "meml %s \n", __func__); brw_bufmgr_destroy(screen->bufmgr); driDestroyOptionInfo(&screen->optionCache); @@ -2485,6 +2486,7 @@ __DRIconfig **intelInitScreen2(__DRIscreen *dri_screen) { struct intel_screen *screen; + fprintf(stderr, "meml %s \n", __func__); if (dri_screen->image.loader) { } else if (dri_screen->dri2.loader->base.version <= 2 || dri_screen->dri2.loader->getBuffersWithFormat == NULL) { diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 03d81f1d559..c7b21c3a068 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1718,10 +1718,13 @@ _mesa_make_current( struct gl_context *newCtx, _mesa_reference_framebuffer(&curCtx->WinSysDrawBuffer, NULL); _mesa_reference_framebuffer(&curCtx->WinSysReadBuffer, NULL); } + fprintf (stderr, "%s context: %p \n", __func__, curCtx); _glapi_set_context(NULL); assert(_mesa_get_current_context() == NULL); } else { + fprintf (stderr, "%s context: %p \n", __func__, newCtx); + _glapi_set_context((void *) newCtx); assert(_mesa_get_current_context() == newCtx); _glapi_set_dispatch(newCtx->CurrentClientDispatch); diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c index 145c5199978..76f305f8e7f 100644 --- a/src/mesa/main/glthread.c +++ b/src/mesa/main/glthread.c @@ -62,6 +62,7 @@ glthread_thread_initialization(void *job, int thread_index) struct gl_context *ctx = (struct gl_context*)job; ctx->Driver.SetBackgroundContext(ctx, &ctx->GLThread->stats); + fprintf (stderr, "%s context: %p \n", __func__, ctx); _glapi_set_context(ctx); }