[Mesa-dev] [PATCH 1/5] os: Implement pipe_condvar on win32

nobled nobled at dreamwidth.org
Sat Jul 3 13:48:49 PDT 2010


Or at least a little of it. This version will sleep
for a fixed amount of time instead of just deadlocking,
which is a slight improvement.

Also do the same thing on any unrecognized platform.
---
 src/gallium/auxiliary/os/os_thread.h |   34 +++++++++++++++++++++++++++-------
 1 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/os/os_thread.h
b/src/gallium/auxiliary/os/os_thread.h
index 0238308..40cfa41 100644
--- a/src/gallium/auxiliary/os/os_thread.h
+++ b/src/gallium/auxiliary/os/os_thread.h
@@ -170,17 +170,28 @@ typedef CRITICAL_SECTION pipe_mutex;


 /* pipe_condvar (XXX FIX THIS)
+ * See http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
+ * for potential pitfalls in implementation.
  */
-typedef unsigned pipe_condvar;
+typedef DWORD pipe_condvar;
+
+#define pipe_static_condvar(cond) \
+   /*static*/ pipe_condvar cond = 1

 #define pipe_condvar_init(cond) \
-   (void) cond
+   (void) (cond = 1)

 #define pipe_condvar_destroy(cond) \
    (void) cond

+/* Poor man's pthread_cond_wait():
+   Just release the mutex and sleep for one millisecond.
+   The caller's while() loop does all the work. */
 #define pipe_condvar_wait(cond, mutex) \
-   (void) cond; (void) mutex
+   do { pipe_mutex_unlock(mutex); \
+        Sleep(cond); \
+        pipe_mutex_lock(mutex); \
+   } while (0)

 #define pipe_condvar_signal(cond) \
    (void) cond
@@ -191,6 +202,8 @@ typedef unsigned pipe_condvar;

 #else

+#include "os/os_time.h"
+
 /** Dummy definitions */

 typedef unsigned pipe_thread;
@@ -214,7 +227,6 @@ static INLINE int pipe_thread_destroy( pipe_thread thread )
 }

 typedef unsigned pipe_mutex;
-typedef unsigned pipe_condvar;

 #define pipe_static_mutex(mutex) \
    static pipe_mutex mutex = 0
@@ -231,17 +243,25 @@ typedef unsigned pipe_condvar;
 #define pipe_mutex_unlock(mutex) \
    (void) mutex

+typedef int64_t pipe_condvar;
+
 #define pipe_static_condvar(condvar) \
-   static unsigned condvar = 0
+   static pipe_condvar condvar = 1000

 #define pipe_condvar_init(condvar) \
-   (void) condvar
+   (void) (condvar = 1000)

 #define pipe_condvar_destroy(condvar) \
    (void) condvar

+/* Poor man's pthread_cond_wait():
+   Just release the mutex and sleep for one millisecond.
+   The caller's while() loop does all the work. */
 #define pipe_condvar_wait(condvar, mutex) \
-   (void) condvar
+   do { pipe_mutex_unlock(mutex); \
+        os_time_sleep(condvar); \
+        pipe_mutex_lock(mutex); \
+   } while (0)

 #define pipe_condvar_signal(condvar) \
    (void) condvar
-- 
1.5.4.3


More information about the mesa-dev mailing list