Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread Move pthread_once implementation into a separ...



details:   https://anonhg.NetBSD.org/src/rev/b176b048a463
branches:  trunk
changeset: 778021:b176b048a463
user:      joerg <joerg%NetBSD.org@localhost>
date:      Mon Mar 12 21:35:10 2012 +0000

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

diffstat:

 lib/libpthread/Makefile        |   3 +-
 lib/libpthread/pthread_mutex.c |  32 +-------------------
 lib/libpthread/pthread_once.c  |  66 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 31 deletions(-)

diffs (154 lines):

diff -r 424fdc7c3b76 -r b176b048a463 lib/libpthread/Makefile
--- a/lib/libpthread/Makefile   Mon Mar 12 20:17:16 2012 +0000
+++ b/lib/libpthread/Makefile   Mon Mar 12 21:35:10 2012 +0000
@@ -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_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
diff -r 424fdc7c3b76 -r b176b048a463 lib/libpthread/pthread_mutex.c
--- a/lib/libpthread/pthread_mutex.c    Mon Mar 12 20:17:16 2012 +0000
+++ b/lib/libpthread/pthread_mutex.c    Mon Mar 12 21:35:10 2012 +0000
@@ -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 @@
        return 0;
 }
 
-
 int
 pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *typep)
 {
@@ -560,7 +559,6 @@
        return 0;
 }
 
-
 int
 pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
 {
@@ -579,32 +577,6 @@
        }
 }
 
-
-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)
 {
diff -r 424fdc7c3b76 -r b176b048a463 lib/libpthread/pthread_once.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpthread/pthread_once.c     Mon Mar 12 21:35:10 2012 +0000
@@ -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;
+}



Home | Main Index | Thread Index | Old Index