[xiph-commits] r3871 - liboggplay/trunk/src/liboggplay

wiking at svn.annodex.net wiking at svn.annodex.net
Tue Mar 3 03:18:01 PST 2009


Author: wiking
Date: 2009-03-03 03:18:00 -0800 (Tue, 03 Mar 2009)
New Revision: 3871

Modified:
   liboggplay/trunk/src/liboggplay/std_semaphore.h
Log:
MS and Unix-like semaphore handling functions' return value have opposite meaning,
i.e. while in case of MS return value 0 means there was an error, in case
of Unix-like systems it means a successful exectution. Hence for correct
error handling regardless of the OS throughout the library 
the return values needs to be negated of MS semaphore functions.


Modified: liboggplay/trunk/src/liboggplay/std_semaphore.h
===================================================================
--- liboggplay/trunk/src/liboggplay/std_semaphore.h	2009-03-02 22:18:49 UTC (rev 3870)
+++ liboggplay/trunk/src/liboggplay/std_semaphore.h	2009-03-03 11:18:00 UTC (rev 3871)
@@ -34,6 +34,46 @@
 
 #ifndef _STD_SEMAPHORE_H
 #define _STD_SEMAPHORE_H
+
+/**
+ * @def SEM_CREATE(p,s)
+ *
+ * Macro that creates a semaphore.  
+ *
+ * @param p semaphore handle
+ * @param s initial value of the semaphore
+ * @retval 0 on success
+ * @retval non-zero on error 
+ */
+
+/**
+ * @def SEM_SIGNAL(p) 
+ *
+ * The macro increments the given semaphore.
+ * 
+ * @param p semaphore handle.
+ * @retval 0 on success
+ * @retval non-zero on error 
+ */
+
+/**
+ * @def SEM_WAIT(p)
+ *
+ * Macro that decrements (locks) the semaphore.
+ *
+ * @param p semaphore handle
+ */
+
+/**
+ * @def SEM_CLOSE(p)
+ *
+ * Macro that closes a given semaphore.
+ *
+ * @param p semaphore handle
+ * @retval 0 on success
+ * @retval non-zero on error 
+ */
+
 #if defined(linux) || defined(SOLARIS)
 #include <semaphore.h>
 #define SEM_CREATE(p,s) sem_init(&(p), 1, s)
@@ -43,11 +83,10 @@
 typedef sem_t           semaphore;
 #elif defined(WIN32)
 #include <windows.h>
-#define SEM_CREATE(p,s) p = CreateSemaphore(NULL, (long)(s), (long)(s), NULL)
-#define SEM_SIGNAL(p)   ReleaseSemaphore(p, 1, NULL)
+#define SEM_CREATE(p,s) (!(p = CreateSemaphore(NULL, (long)(s), (long)(s), NULL)))
+#define SEM_SIGNAL(p)   (!ReleaseSemaphore(p, 1, NULL))
 #define SEM_WAIT(p)     WaitForSingleObject(p, INFINITE)
-#define SEM_TEST(p,s)   p = WaitForSingleObject(s, 0)
-#define SEM_CLOSE(p)    CloseHandle(p)
+#define SEM_CLOSE(p)    (!CloseHandle(p))
 typedef HANDLE          semaphore;
 #elif defined(__APPLE__)
 #include <Multiprocessing.h>



More information about the commits mailing list