summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2015-11-10 14:10:45 -0700
committerBrian Paul <[email protected]>2015-11-12 11:21:24 -0700
commitfa30de7643ca6c70ac2661684b22f7b220a40b0b (patch)
treef8d727bb6bdc8e8369d70fae2022eab308d45893
parenta02385cd691df9dd35844a727350db72b17f586b (diff)
st/wgl: re-implement stw_device::ctx_mutex with CRITICAL_SECTION
This is Windows-only code so we can use the native Win32 functions for critical sections. This will also allow us to (cleanly) add some mutex check/debug code in subsequent patches. Reviewed-by: Sinclair Yeh <[email protected]> Reviewed-by: Charmaine Lee <[email protected]>
-rw-r--r--src/gallium/state_trackers/wgl/stw_context.c29
-rw-r--r--src/gallium/state_trackers/wgl/stw_device.c8
-rw-r--r--src/gallium/state_trackers/wgl/stw_device.h16
3 files changed, 34 insertions, 19 deletions
diff --git a/src/gallium/state_trackers/wgl/stw_context.c b/src/gallium/state_trackers/wgl/stw_context.c
index 0f859649217..229fdfd1625 100644
--- a/src/gallium/state_trackers/wgl/stw_context.c
+++ b/src/gallium/state_trackers/wgl/stw_context.c
@@ -70,7 +70,7 @@ DrvCopyContext(DHGLRC dhrcSource, DHGLRC dhrcDest, UINT fuMask)
if (!stw_dev)
return FALSE;
- pipe_mutex_lock( stw_dev->ctx_mutex );
+ stw_lock_contexts(stw_dev);
src = stw_lookup_context_locked( dhrcSource );
dst = stw_lookup_context_locked( dhrcDest );
@@ -83,7 +83,7 @@ DrvCopyContext(DHGLRC dhrcSource, DHGLRC dhrcDest, UINT fuMask)
(void) fuMask;
}
- pipe_mutex_unlock( stw_dev->ctx_mutex );
+ stw_unlock_contexts(stw_dev);
return ret;
}
@@ -99,7 +99,7 @@ DrvShareLists(DHGLRC dhglrc1, DHGLRC dhglrc2)
if (!stw_dev)
return FALSE;
- pipe_mutex_lock( stw_dev->ctx_mutex );
+ stw_lock_contexts(stw_dev);
ctx1 = stw_lookup_context_locked( dhglrc1 );
ctx2 = stw_lookup_context_locked( dhglrc2 );
@@ -107,7 +107,7 @@ DrvShareLists(DHGLRC dhglrc1, DHGLRC dhglrc2)
if (ctx1 && ctx2 && ctx2->st->share)
ret = ctx2->st->share(ctx2->st, ctx1->st);
- pipe_mutex_unlock( stw_dev->ctx_mutex );
+ stw_unlock_contexts(stw_dev);
return ret;
}
@@ -173,9 +173,9 @@ stw_create_context_attribs(HDC hdc, INT iLayerPlane, DHGLRC hShareContext,
pfi = stw_pixelformat_get_info( iPixelFormat );
if (hShareContext != 0) {
- pipe_mutex_lock( stw_dev->ctx_mutex );
+ stw_lock_contexts(stw_dev);
shareCtx = stw_lookup_context_locked( hShareContext );
- pipe_mutex_unlock( stw_dev->ctx_mutex );
+ stw_unlock_contexts(stw_dev);
}
ctx = CALLOC_STRUCT( stw_context );
@@ -250,7 +250,7 @@ stw_create_context_attribs(HDC hdc, INT iLayerPlane, DHGLRC hShareContext,
ctx->hud = hud_create(ctx->st->pipe, ctx->st->cso_context);
}
- pipe_mutex_lock( stw_dev->ctx_mutex );
+ stw_lock_contexts(stw_dev);
if (handle) {
/* We're replacing the context data for this handle. See the
* wglCreateContextAttribsARB() function.
@@ -276,7 +276,8 @@ stw_create_context_attribs(HDC hdc, INT iLayerPlane, DHGLRC hShareContext,
ctx->dhglrc = handle;
- pipe_mutex_unlock( stw_dev->ctx_mutex );
+ stw_unlock_contexts(stw_dev);
+
if (!ctx->dhglrc)
goto no_hglrc;
@@ -303,10 +304,10 @@ DrvDeleteContext(DHGLRC dhglrc)
if (!stw_dev)
return FALSE;
- pipe_mutex_lock( stw_dev->ctx_mutex );
+ stw_lock_contexts(stw_dev);
ctx = stw_lookup_context_locked(dhglrc);
handle_table_remove(stw_dev->ctx_table, dhglrc);
- pipe_mutex_unlock( stw_dev->ctx_mutex );
+ stw_unlock_contexts(stw_dev);
if (ctx) {
struct stw_context *curctx = stw_current_context();
@@ -337,9 +338,9 @@ DrvReleaseContext(DHGLRC dhglrc)
if (!stw_dev)
return FALSE;
- pipe_mutex_lock( stw_dev->ctx_mutex );
+ stw_lock_contexts(stw_dev);
ctx = stw_lookup_context_locked( dhglrc );
- pipe_mutex_unlock( stw_dev->ctx_mutex );
+ stw_unlock_contexts(stw_dev);
if (!ctx)
return FALSE;
@@ -408,9 +409,9 @@ stw_make_current(HDC hdc, DHGLRC dhglrc)
}
if (dhglrc) {
- pipe_mutex_lock( stw_dev->ctx_mutex );
+ stw_lock_contexts(stw_dev);
ctx = stw_lookup_context_locked( dhglrc );
- pipe_mutex_unlock( stw_dev->ctx_mutex );
+ stw_unlock_contexts(stw_dev);
if (!ctx) {
goto fail;
}
diff --git a/src/gallium/state_trackers/wgl/stw_device.c b/src/gallium/state_trackers/wgl/stw_device.c
index 25b6341ecad..2f51fdb1cbf 100644
--- a/src/gallium/state_trackers/wgl/stw_device.c
+++ b/src/gallium/state_trackers/wgl/stw_device.c
@@ -106,7 +106,7 @@ stw_init(const struct stw_winsys *stw_winsys)
screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS);
stw_dev->max_2d_length = 1 << (stw_dev->max_2d_levels - 1);
- pipe_mutex_init( stw_dev->ctx_mutex );
+ InitializeCriticalSection(&stw_dev->ctx_mutex);
pipe_mutex_init( stw_dev->fb_mutex );
stw_dev->ctx_table = handle_table_create();
@@ -156,9 +156,9 @@ stw_cleanup(void)
* Abort cleanup if there are still active contexts. In some situations
* this DLL may be unloaded before the DLL that is using GL contexts is.
*/
- pipe_mutex_lock( stw_dev->ctx_mutex );
+ stw_lock_contexts(stw_dev);
dhglrc = handle_table_get_first_handle(stw_dev->ctx_table);
- pipe_mutex_unlock( stw_dev->ctx_mutex );
+ stw_unlock_contexts(stw_dev);
if (dhglrc) {
debug_printf("%s: contexts still active -- cleanup aborted\n", __FUNCTION__);
stw_dev = NULL;
@@ -170,7 +170,7 @@ stw_cleanup(void)
stw_framebuffer_cleanup();
pipe_mutex_destroy( stw_dev->fb_mutex );
- pipe_mutex_destroy( stw_dev->ctx_mutex );
+ DeleteCriticalSection(&stw_dev->ctx_mutex);
FREE(stw_dev->smapi);
stw_dev->stapi->destroy(stw_dev->stapi);
diff --git a/src/gallium/state_trackers/wgl/stw_device.h b/src/gallium/state_trackers/wgl/stw_device.h
index e35a4b94036..f271762f6b1 100644
--- a/src/gallium/state_trackers/wgl/stw_device.h
+++ b/src/gallium/state_trackers/wgl/stw_device.h
@@ -65,7 +65,7 @@ struct stw_device
GLCALLBACKTABLE callbacks;
- pipe_mutex ctx_mutex;
+ CRITICAL_SECTION ctx_mutex;
struct handle_table *ctx_table;
pipe_mutex fb_mutex;
@@ -89,4 +89,18 @@ stw_lookup_context_locked( DHGLRC dhglrc )
}
+static inline void
+stw_lock_contexts(struct stw_device *stw_dev)
+{
+ EnterCriticalSection(&stw_dev->ctx_mutex);
+}
+
+
+static inline void
+stw_unlock_contexts(struct stw_device *stw_dev)
+{
+ LeaveCriticalSection(&stw_dev->ctx_mutex);
+}
+
+
#endif /* STW_DEVICE_H_ */