From f8217c1241c570ab4b529f81f86573df27a93c1f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 2 Oct 2007 21:03:19 +0000 Subject: remove once.[ch] git-svn-id: file:///home/lennart/svn/public/libsydney/trunk@40 9ba3c220-e4d3-45a2-8aa3-73fcc9aff6ce --- src/once.c | 58 ---------------------------------------------------------- src/once.h | 17 ----------------- 2 files changed, 75 deletions(-) delete mode 100644 src/once.c delete mode 100644 src/once.h (limited to 'src') diff --git a/src/once.c b/src/once.c deleted file mode 100644 index 5dc9764..0000000 --- a/src/once.c +++ /dev/null @@ -1,58 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include "once.h" -#include "mutex.h" -#include "malloc.h" -#include "macro.h" - -static sa_mutex_t *global_mutex; -static pthread_once_t global_mutex_once = PTHREAD_ONCE_INIT; - -static void global_mutex_once_func(void) { - global_mutex = sa_mutex_new(0); -} - -int sa_once(sa_once_t *control, sa_once_func_t func) { - int r; - - assert(control); - assert(func); - - /* Create the global mutex */ - sa_assert_success(pthread_once(&global_mutex_once, global_mutex_once_func)); - - if (!global_mutex) - return -1; - - r = 0; - - /* Create the local mutex */ - sa_mutex_lock(global_mutex); - if (!control->mutex) { - if (!(control->mutex = sa_mutex_new(1))) - r = -1; - } - sa_mutex_unlock(global_mutex); - - if (r) - return -1; - - /* Execute function */ - sa_mutex_lock(control->mutex); - if (!control->once_value) { - control->once_value = 1; - func(); - } - sa_mutex_unlock(control->mutex); - - /* Caveat: We have to make sure that the once func has completed - * before returning, even if the once func is not actually - * executed by us. Hence the awkward locking. */ - - return 0; -} diff --git a/src/once.h b/src/once.h deleted file mode 100644 index a374529..0000000 --- a/src/once.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef foosydneyoncehfoo -#define foosydneyoncehfoo - -#include "mutex.h" - -typedef struct sa_once { - unsigned int once_value; - sa_mutex_t *mutex; -} sa_once_t; - -#define SA_ONCE_INIT { .once_value = 0, .mutex = NULL } - -typedef void (*sa_once_func_t) (void); - -int sa_once(sa_once_t *o, sa_once_func_t f); - -#endif -- cgit