]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a simplistic implementation of pthread_once().
authorJulian Seward <jseward@acm.org>
Wed, 24 Apr 2002 19:21:39 +0000 (19:21 +0000)
committerJulian Seward <jseward@acm.org>
Wed, 24 Apr 2002 19:21:39 +0000 (19:21 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@132

coregrind/arch/x86-linux/vg_libpthread.c
coregrind/vg_libpthread.c
vg_libpthread.c

index 2ee0140b59556d7d02cb1904de42dac29097ff25..9081c7dfd3f1e99e2879bd6f53e5e33dee211ae2 100644 (file)
@@ -546,6 +546,36 @@ void * pthread_getspecific(pthread_key_t key)
 }
 
 
+/* ---------------------------------------------------
+   ONCEry
+   ------------------------------------------------ */
+
+static pthread_mutex_t once_masterlock = PTHREAD_MUTEX_INITIALIZER;
+
+
+int pthread_once ( pthread_once_t *once_control, 
+                   void (*init_routine) (void) )
+{
+   int res;
+   ensure_valgrind("pthread_once");
+
+   res = pthread_mutex_lock(&once_masterlock);
+
+   if (res != 0)
+      barf("pthread_once: Looks like your program's "
+           "init routine calls back to pthread_once() ?!");
+
+   if (*once_control == 0) {
+      *once_control = 1;
+      init_routine();
+   }
+
+   pthread_mutex_unlock(&once_masterlock);
+
+   return 0;
+}
+
+
 /* ---------------------------------------------------
    MISC
    ------------------------------------------------ */
index 2ee0140b59556d7d02cb1904de42dac29097ff25..9081c7dfd3f1e99e2879bd6f53e5e33dee211ae2 100644 (file)
@@ -546,6 +546,36 @@ void * pthread_getspecific(pthread_key_t key)
 }
 
 
+/* ---------------------------------------------------
+   ONCEry
+   ------------------------------------------------ */
+
+static pthread_mutex_t once_masterlock = PTHREAD_MUTEX_INITIALIZER;
+
+
+int pthread_once ( pthread_once_t *once_control, 
+                   void (*init_routine) (void) )
+{
+   int res;
+   ensure_valgrind("pthread_once");
+
+   res = pthread_mutex_lock(&once_masterlock);
+
+   if (res != 0)
+      barf("pthread_once: Looks like your program's "
+           "init routine calls back to pthread_once() ?!");
+
+   if (*once_control == 0) {
+      *once_control = 1;
+      init_routine();
+   }
+
+   pthread_mutex_unlock(&once_masterlock);
+
+   return 0;
+}
+
+
 /* ---------------------------------------------------
    MISC
    ------------------------------------------------ */
index 2ee0140b59556d7d02cb1904de42dac29097ff25..9081c7dfd3f1e99e2879bd6f53e5e33dee211ae2 100644 (file)
@@ -546,6 +546,36 @@ void * pthread_getspecific(pthread_key_t key)
 }
 
 
+/* ---------------------------------------------------
+   ONCEry
+   ------------------------------------------------ */
+
+static pthread_mutex_t once_masterlock = PTHREAD_MUTEX_INITIALIZER;
+
+
+int pthread_once ( pthread_once_t *once_control, 
+                   void (*init_routine) (void) )
+{
+   int res;
+   ensure_valgrind("pthread_once");
+
+   res = pthread_mutex_lock(&once_masterlock);
+
+   if (res != 0)
+      barf("pthread_once: Looks like your program's "
+           "init routine calls back to pthread_once() ?!");
+
+   if (*once_control == 0) {
+      *once_control = 1;
+      init_routine();
+   }
+
+   pthread_mutex_unlock(&once_masterlock);
+
+   return 0;
+}
+
+
 /* ---------------------------------------------------
    MISC
    ------------------------------------------------ */