#include "pipe/p_compiler.h"
-#include "os/os_thread.h"
#include "util/u_handle_table.h"
#include "stw_icd.h"
#include "stw_pixelformat.h"
for (fb = stw_dev->fb_head; fb != NULL; fb = fb->next)
if (fb->hWnd == hwnd) {
- pipe_mutex_lock(fb->mutex);
+ stw_framebuffer_lock(fb);
return fb;
}
/* check the reference count */
fb->refcnt--;
if (fb->refcnt) {
- pipe_mutex_unlock( fb->mutex );
+ stw_framebuffer_release(fb);
return;
}
stw_st_destroy_framebuffer_locked(fb->stfb);
- pipe_mutex_unlock( fb->mutex );
+ stw_framebuffer_release(fb);
- pipe_mutex_destroy( fb->mutex );
+ DeleteCriticalSection(&fb->mutex);
FREE( fb );
}
-/**
- * Unlock the given stw_framebuffer object.
- */
-void
-stw_framebuffer_release(struct stw_framebuffer *fb)
-{
- assert(fb);
- pipe_mutex_unlock( fb->mutex );
-}
-
-
/**
* Query the size of the given framebuffer's on-screen window and update
* the stw_framebuffer's width/height.
stw_framebuffer_get_size(fb);
- pipe_mutex_init( fb->mutex );
+ InitializeCriticalSection(&fb->mutex);
/* This is the only case where we lock the stw_framebuffer::mutex before
* stw_dev::fb_mutex, since no other thread can know about this framebuffer
* and we must prevent any other thread from destroying it before we return.
*/
- pipe_mutex_lock( fb->mutex );
+ stw_framebuffer_lock(fb);
stw_lock_framebuffers(stw_dev);
fb->next = stw_dev->fb_head;
if (old_fb) {
stw_lock_framebuffers(stw_dev);
- pipe_mutex_lock(old_fb->mutex);
+ stw_framebuffer_lock(old_fb);
stw_framebuffer_destroy_locked(old_fb);
stw_unlock_framebuffers(stw_dev);
while (fb) {
next = fb->next;
- pipe_mutex_lock(fb->mutex);
+ stw_framebuffer_lock(fb);
stw_framebuffer_destroy_locked(fb);
fb = next;
#include <windows.h>
-#include "os/os_thread.h"
+#include "util/u_debug.h"
+
struct pipe_resource;
struct st_framebuffer_iface;
* This mutex has two purposes:
* - protect the access to the mutable data members below
* - prevent the framebuffer from being deleted while being accessed.
- *
- * It is OK to lock this mutex while holding the stw_device::fb_mutex lock,
- * but the opposite must never happen.
+ *
+ * Note: if both this mutex and the stw_device::fb_mutex need to be locked,
+ * the stw_device::fb_mutex needs to be locked first.
*/
- pipe_mutex mutex;
+ CRITICAL_SECTION mutex;
/*
* Immutable members.
void
stw_framebuffer_update(struct stw_framebuffer *fb);
+
+static inline void
+stw_framebuffer_lock(struct stw_framebuffer *fb)
+{
+ assert(fb);
+ EnterCriticalSection(&fb->mutex);
+}
+
+
/**
* Release stw_framebuffer::mutex lock. This framebuffer must not be accessed
* after calling this function, as it may have been deleted by another thread
* in the meanwhile.
*/
-void
-stw_framebuffer_release(struct stw_framebuffer *fb);
+static inline void
+stw_framebuffer_release(struct stw_framebuffer *fb)
+{
+ assert(fb);
+ LeaveCriticalSection(&fb->mutex);
+}
+
/**
* Cleanup any existing framebuffers when exiting application.
for (i = 0; i < count; i++)
statt_mask |= 1 << statts[i];
- pipe_mutex_lock(stwfb->fb->mutex);
+ stw_framebuffer_lock(stwfb->fb);
if (stwfb->fb->must_resize || (statt_mask & ~stwfb->texture_mask)) {
stw_st_framebuffer_validate_locked(&stwfb->base,
boolean ret;
HDC hDC;
- pipe_mutex_lock(stwfb->fb->mutex);
+ stw_framebuffer_lock(stwfb->fb);
/* We must not cache HDCs anywhere, as they can be invalidated by the
* application, or screen resolution changes. */