From: Julian Seward Date: Wed, 24 Apr 2002 19:21:39 +0000 (+0000) Subject: Add a simplistic implementation of pthread_once(). X-Git-Tag: svn/VALGRIND_1_0_3~319 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fde2066d9ecbdafb818f23e71b7d4c0b61f5a09;p=thirdparty%2Fvalgrind.git Add a simplistic implementation of pthread_once(). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@132 --- diff --git a/coregrind/arch/x86-linux/vg_libpthread.c b/coregrind/arch/x86-linux/vg_libpthread.c index 2ee0140b59..9081c7dfd3 100644 --- a/coregrind/arch/x86-linux/vg_libpthread.c +++ b/coregrind/arch/x86-linux/vg_libpthread.c @@ -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 ------------------------------------------------ */ diff --git a/coregrind/vg_libpthread.c b/coregrind/vg_libpthread.c index 2ee0140b59..9081c7dfd3 100644 --- a/coregrind/vg_libpthread.c +++ b/coregrind/vg_libpthread.c @@ -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 ------------------------------------------------ */ diff --git a/vg_libpthread.c b/vg_libpthread.c index 2ee0140b59..9081c7dfd3 100644 --- a/vg_libpthread.c +++ b/vg_libpthread.c @@ -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 ------------------------------------------------ */