]> granicus.if.org Git - libvpx/commitdiff
vpx_once: implement once() for OS/2
authorKO Myung-Hun <komh@chollian.net>
Sat, 26 Jul 2014 05:53:59 +0000 (14:53 +0900)
committerJames Zern <jzern@google.com>
Wed, 30 Jul 2014 00:36:39 +0000 (17:36 -0700)
Change-Id: I9f736f299490464bbdbb6cd24ee6f5b46ad45ec6

vpx_ports/vpx_once.h

index 182892acfaa1b7703ae0282301fe6f973e104f70..bd9eebd643bdccf6e30299650f1375d827d4787f 100644 (file)
@@ -73,6 +73,33 @@ static void once(void (*func)(void))
 }
 
 
+#elif CONFIG_MULTITHREAD && defined(__OS2__)
+#define INCL_DOS
+#include <os2.h>
+static void once(void (*func)(void))
+{
+    static int done;
+
+    /* If the initialization is complete, return early. */
+    if(done)
+        return;
+
+    /* Causes all other threads in the process to block themselves
+     * and give up their time slice.
+     */
+    DosEnterCritSec();
+
+    if (!done)
+    {
+        func();
+        done = 1;
+    }
+
+    /* Restores normal thread dispatching for the current process. */
+    DosExitCritSec();
+}
+
+
 #elif CONFIG_MULTITHREAD && HAVE_PTHREAD_H
 #include <pthread.h>
 static void once(void (*func)(void))