From 6fde2066d9ecbdafb818f23e71b7d4c0b61f5a09 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Wed, 24 Apr 2002 19:21:39 +0000 Subject: [PATCH] Add a simplistic implementation of pthread_once(). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@132 --- coregrind/arch/x86-linux/vg_libpthread.c | 30 ++++++++++++++++++++++++ coregrind/vg_libpthread.c | 30 ++++++++++++++++++++++++ vg_libpthread.c | 30 ++++++++++++++++++++++++ 3 files changed, 90 insertions(+) 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 ------------------------------------------------ */ -- 2.47.3