Module Name:    src
Committed By:   joerg
Date:           Mon Mar 12 21:35:11 UTC 2012

Modified Files:
        src/lib/libpthread: Makefile pthread_mutex.c
Added Files:
        src/lib/libpthread: pthread_once.c

Log Message:
Move pthread_once implementation into a separate file, it doesn't depend
on the mutex implementation in any way.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/lib/libpthread/Makefile
cvs rdiff -u -r1.51 -r1.52 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r0 -r1.1 src/lib/libpthread/pthread_once.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpthread/Makefile
diff -u src/lib/libpthread/Makefile:1.73 src/lib/libpthread/Makefile:1.74
--- src/lib/libpthread/Makefile:1.73	Thu Nov 10 14:01:11 2011
+++ src/lib/libpthread/Makefile	Mon Mar 12 21:35:10 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.73 2011/11/10 14:01:11 yamt Exp $
+#	$NetBSD: Makefile,v 1.74 2012/03/12 21:35:10 joerg Exp $
 #
 
 WARNS=	4
@@ -48,6 +48,7 @@ SRCS+=	pthread_cond.c
 SRCS+=	pthread_lock.c 
 SRCS+=	pthread_misc.c
 SRCS+=	pthread_mutex.c
+SRCS+=	pthread_once.c
 SRCS+=	pthread_rwlock.c
 SRCS+=	pthread_specific.c
 SRCS+=	pthread_spin.c

Index: src/lib/libpthread/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.51 src/lib/libpthread/pthread_mutex.c:1.52
--- src/lib/libpthread/pthread_mutex.c:1.51	Sat Aug  2 19:46:30 2008
+++ src/lib/libpthread/pthread_mutex.c	Mon Mar 12 21:35:10 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.51 2008/08/02 19:46:30 matt Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.52 2012/03/12 21:35:10 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_mutex.c,v 1.51 2008/08/02 19:46:30 matt Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.52 2012/03/12 21:35:10 joerg Exp $");
 
 #include <sys/types.h>
 #include <sys/lwpctl.h>
@@ -548,7 +548,6 @@ pthread_mutexattr_destroy(pthread_mutexa
 	return 0;
 }
 
-
 int
 pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *typep)
 {
@@ -560,7 +559,6 @@ pthread_mutexattr_gettype(const pthread_
 	return 0;
 }
 
-
 int
 pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
 {
@@ -579,32 +577,6 @@ pthread_mutexattr_settype(pthread_mutexa
 	}
 }
 
-
-static void
-once_cleanup(void *closure)
-{
-
-       pthread_mutex_unlock((pthread_mutex_t *)closure);
-}
-
-
-int
-pthread_once(pthread_once_t *once_control, void (*routine)(void))
-{
-
-	if (once_control->pto_done == 0) {
-		pthread_mutex_lock(&once_control->pto_mutex);
-		pthread_cleanup_push(&once_cleanup, &once_control->pto_mutex);
-		if (once_control->pto_done == 0) {
-			routine();
-			once_control->pto_done = 1;
-		}
-		pthread_cleanup_pop(1);
-	}
-
-	return 0;
-}
-
 void
 pthread__mutex_deferwake(pthread_t self, pthread_mutex_t *ptm)
 {

Added files:

Index: src/lib/libpthread/pthread_once.c
diff -u /dev/null src/lib/libpthread/pthread_once.c:1.1
--- /dev/null	Mon Mar 12 21:35:11 2012
+++ src/lib/libpthread/pthread_once.c	Mon Mar 12 21:35:10 2012
@@ -0,0 +1,66 @@
+/*	$NetBSD: pthread_once.c,v 1.1 2012/03/12 21:35:10 joerg Exp $	*/
+
+/*-
+ * Copyright (c) 2001, 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nathan J. Williams, and by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: pthread_once.c,v 1.1 2012/03/12 21:35:10 joerg Exp $");
+
+#include "pthread.h"
+
+static void
+once_cleanup(void *closure)
+{
+
+       pthread_mutex_unlock((pthread_mutex_t *)closure);
+}
+
+int
+pthread_once(pthread_once_t *once_control, void (*routine)(void))
+{
+
+	if (once_control->pto_done == 0) {
+		pthread_mutex_lock(&once_control->pto_mutex);
+		pthread_cleanup_push(&once_cleanup, &once_control->pto_mutex);
+		if (once_control->pto_done == 0) {
+			routine();
+			once_control->pto_done = 1;
+		}
+		pthread_cleanup_pop(1);
+	}
+
+	return 0;
+}

Reply via email to