summaryrefslogtreecommitdiff
path: root/lib/librthread/rthread_sync.c
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2005-12-06 06:19:32 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2005-12-06 06:19:32 +0000
commit9aab9e260c1704f12c1a2e98883427bc9cd79a46 (patch)
treedd53dd228e1b517ad62070c9a60ebf28b6e20c35 /lib/librthread/rthread_sync.c
parent08821d85b0dd3f03968454d4c924d03f2a607b74 (diff)
add pthread_once. unfortunately, the public pthread.h header
defines the pthread_once_t internals, so we're stuck with them.
Diffstat (limited to 'lib/librthread/rthread_sync.c')
-rw-r--r--lib/librthread/rthread_sync.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c
index a2d7faf01cd..262983a926d 100644
--- a/lib/librthread/rthread_sync.c
+++ b/lib/librthread/rthread_sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_sync.c,v 1.1 2005/12/03 18:16:19 tedu Exp $ */
+/* $OpenBSD: rthread_sync.c,v 1.2 2005/12/06 06:19:31 tedu Exp $ */
/*
* Copyright (c) 2004 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -475,3 +475,16 @@ pthread_rwlockattr_destory(pthread_rwlockattr_t *attrp)
return (0);
}
+
+int
+pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
+{
+ pthread_mutex_lock(&once_control->mutex);
+ if (once_control->state == PTHREAD_NEEDS_INIT) {
+ init_routine();
+ once_control->state = PTHREAD_DONE_INIT;
+ }
+ pthread_mutex_unlock(&once_control->mutex);
+
+ return (0);
+}