aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/wgl
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2015-11-10 14:41:30 -0700
committerBrian Paul <[email protected]>2015-11-12 11:21:25 -0700
commita1c9feafd592d13f8215e7a535c68a03fd84849e (patch)
tree1053a494f58c4a12e9568f7b5e5290958d482154 /src/gallium/state_trackers/wgl
parent166769fe4bf4042ecb2a54ee5c7b23e3b0cd471d (diff)
st/wgl: add some mutex checking code
This would have caught the locking bug that was fixed in the earlier "st/wgl: fix locking issue in stw_st_framebuffer_present_locked()" patch. v2: minor coding style changes by Brian. Reviewed-by: Sinclair Yeh <[email protected]> Reviewed-by: Charmaine Lee <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/wgl')
-rw-r--r--src/gallium/state_trackers/wgl/stw_st.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/wgl/stw_st.c b/src/gallium/state_trackers/wgl/stw_st.c
index ecf4cfcc843..78586db1969 100644
--- a/src/gallium/state_trackers/wgl/stw_st.c
+++ b/src/gallium/state_trackers/wgl/stw_st.c
@@ -52,6 +52,28 @@ stw_st_framebuffer(struct st_framebuffer_iface *stfb)
return (struct stw_st_framebuffer *) stfb;
}
+
+/**
+ * Is the given mutex held by the calling thread?
+ */
+static bool
+own_mutex(const CRITICAL_SECTION *cs)
+{
+ // We can't compare OwningThread with our thread handle/id (see
+ // http://stackoverflow.com/a/12675635 ) but we can compare with the
+ // OwningThread member of a critical section we know we own.
+ CRITICAL_SECTION dummy;
+ InitializeCriticalSection(&dummy);
+ EnterCriticalSection(&dummy);
+ if (0)
+ _debug_printf("%p %p\n", cs->OwningThread, dummy.OwningThread);
+ bool ret = cs->OwningThread == dummy.OwningThread;
+ LeaveCriticalSection(&dummy);
+ DeleteCriticalSection(&dummy);
+ return ret;
+}
+
+
/**
* Remove outdated textures and create the requested ones.
*/
@@ -165,6 +187,8 @@ stw_st_framebuffer_present_locked(HDC hdc,
struct stw_st_framebuffer *stwfb = stw_st_framebuffer(stfb);
struct pipe_resource *resource;
+ assert(own_mutex(&stwfb->fb->mutex));
+
resource = stwfb->textures[statt];
if (resource) {
stw_framebuffer_present_locked(hdc, stwfb->fb, resource);
@@ -173,6 +197,8 @@ stw_st_framebuffer_present_locked(HDC hdc,
stw_framebuffer_unlock(stwfb->fb);
}
+ assert(!own_mutex(&stwfb->fb->mutex));
+
return TRUE;
}