CVS commit: src/lib/libpthread

2021-04-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Apr 13 00:31:54 UTC 2021

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
fake-use alloca()'s return value to quieten -Werror=unused-result


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.178 src/lib/libpthread/pthread.c:1.179
--- src/lib/libpthread/pthread.c:1.178	Wed Jul 22 01:24:39 2020
+++ src/lib/libpthread/pthread.c	Tue Apr 13 00:31:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.178 2020/07/22 01:24:39 msaitoh Exp $	*/
+/*	$NetBSD: pthread.c,v 1.179 2021/04/13 00:31:54 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.178 2020/07/22 01:24:39 msaitoh Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.179 2021/04/13 00:31:54 mrg Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -535,6 +535,7 @@ pthread__create_tramp(void *cookie)
 {
 	pthread_t self;
 	void *retval;
+	void *junk __unused;
 
 	self = cookie;
 
@@ -544,7 +545,7 @@ pthread__create_tramp(void *cookie)
 	 * be allocating stacks on fixed 2MB boundaries.  Needs a
 	 * thread register or decent thread local storage.
 	 */
-	(void)alloca(((unsigned)self->pt_lid & 7) << 8);
+	junk = alloca(((unsigned)self->pt_lid & 7) << 8);
 
 	if (self->pt_name != NULL) {
 		pthread_mutex_lock(>pt_lock);



CVS commit: src/lib/libpthread

2021-03-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 10 15:05:11 UTC 2021

Modified Files:
src/lib/libpthread: pthread_types.h

Log Message:
Use __pthread_volatile for ptc_waiters (Greg A. Woods)


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/lib/libpthread/pthread_types.h

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/pthread_types.h
diff -u src/lib/libpthread/pthread_types.h:1.25 src/lib/libpthread/pthread_types.h:1.26
--- src/lib/libpthread/pthread_types.h:1.25	Wed Jun 10 18:45:15 2020
+++ src/lib/libpthread/pthread_types.h	Wed Mar 10 10:05:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_types.h,v 1.25 2020/06/10 22:45:15 ad Exp $	*/
+/*	$NetBSD: pthread_types.h,v 1.26 2021/03/10 15:05:11 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2008, 2020 The NetBSD Foundation, Inc.
@@ -172,7 +172,7 @@ struct	__pthread_cond_st {
 
 	/* Protects the queue of waiters */
 	__pthread_spin_t ptc_lock;
-	void *volatile ptc_waiters;
+	void *__pthread_volatile ptc_waiters;
 	void *ptc_spare;
 
 	pthread_mutex_t	*ptc_mutex;	/* Current mutex */



CVS commit: src/lib/libpthread

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 21:33:28 UTC 2020

Modified Files:
src/lib/libpthread: pthread_cond.c

Log Message:
Another bug.  The CAS loop in pthread_cond_signal() could race against the
thread it is trying to awake.  The thread could exit the condvar and then
reinsert itself at the head of the list with a new waiter behind it.  It's
likely possible to fix this in a way that's wait-free but for now just fix
the bug.


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/lib/libpthread/pthread_cond.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/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.75 src/lib/libpthread/pthread_cond.c:1.76
--- src/lib/libpthread/pthread_cond.c:1.75	Sat Jun 13 17:39:42 2020
+++ src/lib/libpthread/pthread_cond.c	Sun Jun 14 21:33:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.75 2020/06/13 17:39:42 riastradh Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.76 2020/06/14 21:33:28 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.75 2020/06/13 17:39:42 riastradh Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.76 2020/06/14 21:33:28 ad Exp $");
 
 #include 
 #include 
@@ -54,6 +54,13 @@ __strong_alias(__libc_cond_wait,pthread_
 __strong_alias(__libc_cond_timedwait,pthread_cond_timedwait)
 __strong_alias(__libc_cond_destroy,pthread_cond_destroy)
 
+/*
+ * A dummy waiter that's used to flag that pthread_cond_signal() is in
+ * progress and nobody else should try to modify the waiter list until
+ * it completes.
+ */
+static struct pthread__waiter pthread__cond_dummy;
+
 static clockid_t
 pthread_cond_getclock(const pthread_cond_t *cond)
 {
@@ -111,7 +118,7 @@ int
 pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
 		   const struct timespec *abstime)
 {
-	struct pthread__waiter waiter, *next, *waiters;
+	struct pthread__waiter waiter, *next, *head;
 	pthread_t self;
 	int error, cancel;
 	clockid_t clkid = pthread_cond_getclock(cond);
@@ -135,33 +142,39 @@ pthread_cond_timedwait(pthread_cond_t *c
 
 	/* Note this thread as waiting on the CV. */
 	cond->ptc_mutex = mutex;
-	for (waiters = cond->ptc_waiters;; waiters = next) {
+	for (head = cond->ptc_waiters;; head = next) {
+		/* Wait while pthread_cond_signal() in progress. */
+		if (__predict_false(head == __cond_dummy)) {
+			sched_yield();
+			next = cond->ptc_waiters;
+			continue;
+		}
 		waiter.lid = self->pt_lid;
-		waiter.next = waiters;
+		waiter.next = head;
 #ifndef PTHREAD__ATOMIC_IS_MEMBAR
 		membar_producer();
 #endif
-		next = atomic_cas_ptr(>ptc_waiters, waiters, );
-		if (__predict_true(next == waiters)) {
+		next = atomic_cas_ptr(>ptc_waiters, head, );
+		if (__predict_true(next == head)) {
 			break;
 		}
 	}
 
-	/* Drop the interlock */
-	pthread_mutex_unlock(mutex);
+	/* Drop the interlock and wait. */
 	error = 0;
-
+	pthread_mutex_unlock(mutex);
 	while (waiter.lid && !(cancel = self->pt_cancel)) {
 		int rv = _lwp_park(clkid, TIMER_ABSTIME, __UNCONST(abstime),
 		0, NULL, NULL);
 		if (rv == 0) {
 			continue;
 		}
-		if (errno != EINTR && errno != EALREADY && errno != ESRCH) {
+		if (errno != EINTR && errno != EALREADY) {
 			error = errno;
 			break;
 		}
 	}
+	pthread_mutex_lock(mutex);
 
 	/*
 	 * If this thread absorbed a wakeup from pthread_cond_signal() and
@@ -169,11 +182,6 @@ pthread_cond_timedwait(pthread_cond_t *c
 	 *
 	 * And if awoken early, we may still be on the waiter list and must
 	 * remove self.
-	 *
-	 * In all cases do the wakeup without the mutex held otherwise:
-	 *
-	 * - wakeup could be deferred until mutex release
-	 * - it would be mixing up two sets of waitpoints
 	 */
 	if (__predict_false(cancel | error)) {
 		pthread_cond_broadcast(cond);
@@ -183,10 +191,12 @@ pthread_cond_timedwait(pthread_cond_t *c
 		 * Wait until released, otherwise "waiter" is still globally
 		 * visible.
 		 */
+		pthread_mutex_unlock(mutex);
 		while (__predict_false(waiter.lid)) {
 			(void)_lwp_park(CLOCK_MONOTONIC, 0, NULL, 0, NULL,
 			NULL);
 		}
+		pthread_mutex_lock(mutex);
 	} else {
 		pthread__assert(!waiter.lid);
 	}
@@ -195,7 +205,6 @@ pthread_cond_timedwait(pthread_cond_t *c
 	 * If cancelled then exit.  POSIX dictates that the mutex must be
 	 * held if this happens.
 	 */
-	pthread_mutex_lock(mutex);
 	if (cancel) {
 		pthread__cancelled();
 	}
@@ -215,7 +224,7 @@ pthread_cond_wait(pthread_cond_t *cond, 
 int
 pthread_cond_signal(pthread_cond_t *cond)
 {
-	struct pthread__waiter *waiter, *next;
+	struct pthread__waiter *head, *next;
 	pthread_mutex_t *mutex;
 	pthread_t self;
 
@@ -228,28 +237,39 @@ pthread_cond_signal(pthread_cond_t *cond
 	/* Take ownership of one waiter. */
 	self = pthread_self();
 	mutex = cond->ptc_mutex;
-	for (waiter = cond->ptc_waiters;; 

CVS commit: src/lib/libpthread

2020-06-14 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Jun 14 21:31:11 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Don't need to ignore ESRCH from _lwp_park() any more.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.176 src/lib/libpthread/pthread.c:1.177
--- src/lib/libpthread/pthread.c:1.176	Thu Jun 11 18:42:02 2020
+++ src/lib/libpthread/pthread.c	Sun Jun 14 21:31:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.177 2020/06/14 21:31:11 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.177 2020/06/14 21:31:11 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -1145,7 +1145,6 @@ pthread__park(pthread_t self, pthread_mu
 			switch (rv = errno) {
 			case EINTR:
 			case EALREADY:
-			case ESRCH:
 rv = 0;
 break;
 			case ETIMEDOUT:



CVS commit: src/lib/libpthread

2020-06-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 13 17:39:42 UTC 2020

Modified Files:
src/lib/libpthread: pthread_cond.c

Log Message:
Nix trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/lib/libpthread/pthread_cond.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/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.74 src/lib/libpthread/pthread_cond.c:1.75
--- src/lib/libpthread/pthread_cond.c:1.74	Wed Jun 10 22:45:15 2020
+++ src/lib/libpthread/pthread_cond.c	Sat Jun 13 17:39:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.74 2020/06/10 22:45:15 ad Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.75 2020/06/13 17:39:42 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.74 2020/06/10 22:45:15 ad Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.75 2020/06/13 17:39:42 riastradh Exp $");
 
 #include 
 #include 
@@ -179,7 +179,7 @@ pthread_cond_timedwait(pthread_cond_t *c
 		pthread_cond_broadcast(cond);
 
 		/*
-		 * Might have raced with another thread to do the wakeup. 
+		 * Might have raced with another thread to do the wakeup.
 		 * Wait until released, otherwise "waiter" is still globally
 		 * visible.
 		 */



CVS commit: src/lib/libpthread

2020-06-11 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Jun 11 18:42:02 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_tsd.c

Log Message:
Drop self->pt_lock before clearing TSD / malloc TSD.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.22 -r1.23 src/lib/libpthread/pthread_tsd.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.175 src/lib/libpthread/pthread.c:1.176
--- src/lib/libpthread/pthread.c:1.175	Wed Jun 10 22:45:15 2020
+++ src/lib/libpthread/pthread.c	Thu Jun 11 18:42:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.176 2020/06/11 18:42:02 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -615,21 +615,18 @@ pthread_exit(void *retval)
 	pthread_mutex_lock(>pt_lock);
 	self->pt_flags |= PT_FLAG_CS_DISABLED;
 	self->pt_cancel = 0;
+	pthread_mutex_unlock(>pt_lock);
 
 	/* Call any cancellation cleanup handlers */
 	if (!PTQ_EMPTY(>pt_cleanup_stack)) {
-		pthread_mutex_unlock(>pt_lock);
 		while (!PTQ_EMPTY(>pt_cleanup_stack)) {
 			cleanup = PTQ_FIRST(>pt_cleanup_stack);
 			PTQ_REMOVE(>pt_cleanup_stack, cleanup, ptc_next);
 			(*cleanup->ptc_cleanup)(cleanup->ptc_arg);
 		}
-		pthread_mutex_lock(>pt_lock);
 	}
 
-	pthread_mutex_unlock(>pt_lock);
 	__cxa_thread_run_atexit();
-	pthread_mutex_lock(>pt_lock);
 
 	/* Perform cleanup of thread-specific data */
 	pthread__destroy_tsd(self);
@@ -641,6 +638,7 @@ pthread_exit(void *retval)
 	 * Signal our exit.  Our stack and pthread_t won't be reused until
 	 * pthread_create() can see from kernel info that this LWP is gone.
 	 */
+	pthread_mutex_lock(>pt_lock);
 	self->pt_exitval = retval;
 	if (self->pt_flags & PT_FLAG_DETACHED) {
 		/* pthread__reap() will drop the lock. */

Index: src/lib/libpthread/pthread_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.22 src/lib/libpthread/pthread_tsd.c:1.23
--- src/lib/libpthread/pthread_tsd.c:1.22	Sun Apr 19 20:47:03 2020
+++ src/lib/libpthread/pthread_tsd.c	Thu Jun 11 18:42:02 2020
@@ -1,7 +1,7 @@
-/*	$NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $	*/
+/*	$NetBSD: pthread_tsd.c,v 1.23 2020/06/11 18:42:02 ad Exp $	*/
 
 /*-
- * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
+ * Copyright (c) 2001, 2007, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.23 2020/06/11 18:42:02 ad Exp $");
 
 /* Functions and structures dealing with thread-specific data */
 #include 
@@ -323,7 +323,6 @@ pthread__destroy_tsd(pthread_t self)
 
 	if (!self->pt_havespecific)
 		return;
-	pthread_mutex_unlock(>pt_lock);
 
 	/* Butenhof, section 5.4.2 (page 167):
 	 * 
@@ -378,7 +377,6 @@ pthread__destroy_tsd(pthread_t self)
 	} while (!done && --iterations);
 
 	self->pt_havespecific = 0;
-	pthread_mutex_lock(>pt_lock);
 }
 
 void



CVS commit: src/lib/libpthread

2020-06-11 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Thu Jun 11 18:41:22 UTC 2020

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
Adjust memory barriers.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.80 src/lib/libpthread/pthread_mutex.c:1.81
--- src/lib/libpthread/pthread_mutex.c:1.80	Wed Jun 10 22:45:15 2020
+++ src/lib/libpthread/pthread_mutex.c	Thu Jun 11 18:41:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.80 2020/06/10 22:45:15 ad Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.81 2020/06/11 18:41:22 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.80 2020/06/10 22:45:15 ad Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.81 2020/06/11 18:41:22 ad Exp $");
 
 #include 
 #include 
@@ -532,7 +532,7 @@ pthread__mutex_wakeup(pthread_t self, st
 		next = cur->next;
 		pthread__assert(cur->lid != 0);
 		lids[nlid++] = cur->lid;
-		membar_sync();
+		membar_exit();
 		cur->lid = 0;
 		/* No longer safe to touch 'cur' */
 	}
@@ -719,6 +719,9 @@ pthread__mutex_deferwake(pthread_t self,
 	/* Append atomically. */
 	for (o = ptm->ptm_waiters;; o = n) {
 		tail->next = o;
+#ifndef PTHREAD__ATOMIC_IS_MEMBAR
+		membar_producer();
+#endif
 		n = atomic_cas_ptr(>ptm_waiters, o, head);
 		if (__predict_true(n == o)) {
 			break;



CVS commit: src/lib/libpthread

2020-06-10 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jun 10 22:45:15 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_cond.c pthread_int.h
pthread_mutex.c pthread_types.h

Log Message:
- Make pthread_condvar and pthread_mutex work on the stack rather than in
  pthread_t, so there's less chance of bad things happening if someone calls
  (for example) pthread_cond_broadcast() from a signal handler.

- Remove all the deferred waiter handling except for the one case that really
  matters which is transferring waiters from condvar -> mutex on wakeup, and
  do that by splicing the condvar's waiters onto the mutex.

- Remove the mutex waiters bit as it's another complication that's not
  strictly needed.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.73 -r1.74 src/lib/libpthread/pthread_cond.c
cvs rdiff -u -r1.106 -r1.107 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.79 -r1.80 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.24 -r1.25 src/lib/libpthread/pthread_types.h

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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.174 src/lib/libpthread/pthread.c:1.175
--- src/lib/libpthread/pthread.c:1.174	Thu Jun  4 00:45:32 2020
+++ src/lib/libpthread/pthread.c	Wed Jun 10 22:45:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.174 2020/06/04 00:45:32 joerg Exp $	*/
+/*	$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.174 2020/06/04 00:45:32 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.175 2020/06/10 22:45:15 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -297,11 +297,7 @@ pthread__initthread(pthread_t t)
 
 	t->pt_self = t;
 	t->pt_magic = PT_MAGIC;
-	t->pt_willpark = 0;
-	t->pt_waiters[0] = 0;
-	t->pt_nwaiters = 0;
 	t->pt_sleepobj = NULL;
-	t->pt_signalled = 0;
 	t->pt_havespecific = 0;
 	t->pt_lwpctl = __dummy_lwpctl;
 
@@ -602,48 +598,6 @@ pthread_resume_np(pthread_t thread)
 	return errno;
 }
 
-/*
- * Wake all deferred waiters hanging off self.
- *
- * It's possible for threads to have called _lwp_exit() before we wake them,
- * because of cancellation and timeout, so ESRCH is tolerated here.  If a
- * thread exits and its LID is reused, and the a thread receives an wakeup
- * meant for the previous incarnation of the LID, no harm will be done.
- */
-void
-pthread__clear_waiters(pthread_t self)
-{
-	int rv;
-
-	pthread__smt_wake();
-
-	switch (self->pt_nwaiters) {
-	case 0:
-		break;
-	case 1:
-		if (self->pt_willpark) {
-			break;
-		}
-		rv = _lwp_unpark(self->pt_waiters[0], NULL);
-		self->pt_waiters[0] = 0;
-		self->pt_nwaiters = 0;
-		if (rv != 0 && errno != ESRCH) {
-			pthread__errorfunc(__FILE__, __LINE__, __func__,
-			"_lwp_unpark failed: %d", errno);
-		}
-		break;
-	default:
-		rv = _lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, NULL);
-		self->pt_waiters[0] = 0;
-		self->pt_nwaiters = 0;
-		if (rv != 0 && errno != ESRCH) {
-			pthread__errorfunc(__FILE__, __LINE__, __func__,
-			"_lwp_unpark_all failed: %d", errno);
-		}
-		break;
-	}
-}
-
 void
 pthread_exit(void *retval)
 {
@@ -658,7 +612,6 @@ pthread_exit(void *retval)
 	self = pthread__self();
 
 	/* Disable cancellability. */
-	self->pt_willpark = 0;
 	pthread_mutex_lock(>pt_lock);
 	self->pt_flags |= PT_FLAG_CS_DISABLED;
 	self->pt_cancel = 0;
@@ -692,14 +645,10 @@ pthread_exit(void *retval)
 	if (self->pt_flags & PT_FLAG_DETACHED) {
 		/* pthread__reap() will drop the lock. */
 		pthread__reap(self);
-		pthread__assert(!self->pt_willpark);
-		pthread__clear_waiters(self);
 		_lwp_exit();
 	} else {
 		self->pt_state = PT_STATE_ZOMBIE;
-		pthread__assert(!self->pt_willpark);
 		pthread_mutex_unlock(>pt_lock);
-		pthread__clear_waiters(self);
 		/* Note: name will be freed by the joiner. */
 		_lwp_exit();
 	}
@@ -1166,9 +1115,7 @@ pthread__park(pthread_t self, pthread_mu
 {
 	int rv, error;
 
-	self->pt_willpark = 1;
 	pthread_mutex_unlock(lock);
-	self->pt_willpark = 0;
 
 	/*
 	 * Wait until we are awoken by a pending unpark operation,
@@ -1194,13 +1141,8 @@ pthread__park(pthread_t self, pthread_mu
 		 * If we deferred unparking a thread, arrange to
 		 * have _lwp_park() restart it before blocking.
 		 */
-		pthread__assert(self->pt_nwaiters <= 1);
-		pthread__assert(self->pt_nwaiters != 0 ||
-		self->pt_waiters[0] == 0);
 		error = _lwp_park(CLOCK_REALTIME, TIMER_ABSTIME,
-		__UNCONST(abstime), self->pt_waiters[0], NULL, NULL);
-		self->pt_waiters[0] = 0;
-		self->pt_nwaiters = 0;
+		__UNCONST(abstime), 0, NULL, NULL);
 		if (error != 0) {
 			switch (rv = errno) {
 			case EINTR:
@@ -1230,31 +1172,34 @@ pthread__unpark(pthread_queue_t *queue, 
 	pthread_t target;
 
 	target = PTQ_FIRST(queue);
-	if 

CVS commit: src/lib/libpthread

2020-06-06 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jun  6 22:24:00 UTC 2020

Modified Files:
src/lib/libpthread: pthread_cond.c

Log Message:
Adjust previous.  In the condvar case the wakeup might already have been
eaten.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/lib/libpthread/pthread_cond.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/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.72 src/lib/libpthread/pthread_cond.c:1.73
--- src/lib/libpthread/pthread_cond.c:1.72	Thu Jun  4 04:40:01 2020
+++ src/lib/libpthread/pthread_cond.c	Sat Jun  6 22:23:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.72 2020/06/04 04:40:01 riastradh Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.73 2020/06/06 22:23:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.72 2020/06/04 04:40:01 riastradh Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.73 2020/06/06 22:23:59 ad Exp $");
 
 #include 
 #include 
@@ -185,14 +185,14 @@ pthread_cond_timedwait(pthread_cond_t *c
 		pthread_cond_broadcast(cond);
 
 		/*
-		 * Might have raced with another thread to do the wakeup.
-		 * In any case there will be a wakeup for sure.  Eat it and
-		 * wait for pt_condwait to clear.
+		 * Might have raced with another thread to do the wakeup. 
+		 * Wait until released - this thread can't wait on a condvar
+		 * again until the data structures are no longer in us.
 		 */
-		do {
+		while (self->pt_condwait) {
 			(void)_lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, NULL,
 			0, NULL, NULL);
-		} while (self->pt_condwait);
+		}
 	}
 
 	/*



CVS commit: src/lib/libpthread

2020-06-03 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Jun  4 04:40:01 UTC 2020

Modified Files:
src/lib/libpthread: pthread_cond.c

Log Message:
Nix trailing whitespace.  NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/lib/libpthread/pthread_cond.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/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.71 src/lib/libpthread/pthread_cond.c:1.72
--- src/lib/libpthread/pthread_cond.c:1.71	Wed Jun  3 22:10:24 2020
+++ src/lib/libpthread/pthread_cond.c	Thu Jun  4 04:40:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.71 2020/06/03 22:10:24 ad Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.72 2020/06/04 04:40:01 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.71 2020/06/03 22:10:24 ad Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.72 2020/06/04 04:40:01 riastradh Exp $");
 
 #include 
 #include 
@@ -61,7 +61,7 @@ pthread_cond_getclock(const pthread_cond
 	pthread__error(EINVAL, "Invalid condition variable",
 	cond->ptc_magic == _PT_COND_MAGIC);
 
-	return cond->ptc_private ? 
+	return cond->ptc_private ?
 	*(clockid_t *)cond->ptc_private : CLOCK_REALTIME;
 }
 
@@ -185,7 +185,7 @@ pthread_cond_timedwait(pthread_cond_t *c
 		pthread_cond_broadcast(cond);
 
 		/*
-		 * Might have raced with another thread to do the wakeup. 
+		 * Might have raced with another thread to do the wakeup.
 		 * In any case there will be a wakeup for sure.  Eat it and
 		 * wait for pt_condwait to clear.
 		 */



CVS commit: src/lib/libpthread

2020-06-03 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jun  3 22:10:24 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_cond.c pthread_mutex.c

Log Message:
Deal with a couple of problems with threads being awoken early due to
timeouts or cancellation where:

- The restarting thread calls _lwp_exit() before another thread gets around
  to waking it with _lwp_unpark(), leading to ESRCH (observed by joerg@).
  (I may have removed a similar check mistakenly over the weekend.)

- The restarting thread considers itself gone off the sleep queue but
  at the same time another thread is part way through waking it, and hasn't
  fully completed that operation yet by setting thread->pt_mutexwait = 0.
  I think that could have potentially lead to the list of waiters getting
  messed up given the right circumstances.


To generate a diff of this commit:
cvs rdiff -u -r1.172 -r1.173 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.70 -r1.71 src/lib/libpthread/pthread_cond.c
cvs rdiff -u -r1.78 -r1.79 src/lib/libpthread/pthread_mutex.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.172 src/lib/libpthread/pthread.c:1.173
--- src/lib/libpthread/pthread.c:1.172	Tue Jun  2 00:29:53 2020
+++ src/lib/libpthread/pthread.c	Wed Jun  3 22:10:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.172 2020/06/02 00:29:53 joerg Exp $	*/
+/*	$NetBSD: pthread.c,v 1.173 2020/06/03 22:10:24 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.172 2020/06/02 00:29:53 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.173 2020/06/03 22:10:24 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -599,9 +599,12 @@ pthread_resume_np(pthread_t thread)
 }
 
 /*
- * In case the thread is exiting at an inopportune time leaving waiters not
- * awoken (because cancelled, for instance) make sure we have no waiters
- * left.
+ * Wake all deferred waiters hanging off self.
+ *
+ * It's possible for threads to have called _lwp_exit() before we wake them,
+ * because of cancellation and timeout, so ESRCH is tolerated here.  If a
+ * thread exits and its LID is reused, and the a thread receives an wakeup
+ * meant for the previous incarnation of the LID, no harm will be done.
  */
 void
 pthread__clear_waiters(pthread_t self)
@@ -620,7 +623,7 @@ pthread__clear_waiters(pthread_t self)
 		rv = _lwp_unpark(self->pt_waiters[0], NULL);
 		self->pt_waiters[0] = 0;
 		self->pt_nwaiters = 0;
-		if (rv != 0) {
+		if (rv != 0 && errno != ESRCH) {
 			pthread__errorfunc(__FILE__, __LINE__, __func__,
 			"_lwp_unpark failed: %d", errno);
 		}
@@ -629,7 +632,7 @@ pthread__clear_waiters(pthread_t self)
 		rv = _lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, NULL);
 		self->pt_waiters[0] = 0;
 		self->pt_nwaiters = 0;
-		if (rv != 0) {
+		if (rv != 0 && errno != ESRCH) {
 			pthread__errorfunc(__FILE__, __LINE__, __func__,
 			"_lwp_unpark_all failed: %d", errno);
 		}
@@ -1195,6 +1198,7 @@ pthread__park(pthread_t self, pthread_mu
 			switch (rv = errno) {
 			case EINTR:
 			case EALREADY:
+			case ESRCH:
 rv = 0;
 break;
 			case ETIMEDOUT:

Index: src/lib/libpthread/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.70 src/lib/libpthread/pthread_cond.c:1.71
--- src/lib/libpthread/pthread_cond.c:1.70	Mon Jun  1 11:44:59 2020
+++ src/lib/libpthread/pthread_cond.c	Wed Jun  3 22:10:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.70 2020/06/01 11:44:59 ad Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.71 2020/06/03 22:10:24 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.70 2020/06/01 11:44:59 ad Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.71 2020/06/03 22:10:24 ad Exp $");
 
 #include 
 #include 
@@ -112,7 +112,7 @@ pthread_cond_timedwait(pthread_cond_t *c
 		   const struct timespec *abstime)
 {
 	pthread_t self, next, waiters;
-	int retval;
+	int retval, cancel;
 	clockid_t clkid = pthread_cond_getclock(cond);
 
 	if (__predict_false(__uselibcstub))
@@ -126,6 +126,7 @@ pthread_cond_timedwait(pthread_cond_t *c
 	mutex->ptm_owner != NULL);
 
 	self = pthread__self();
+	pthread__assert(!self->pt_condwait);
 
 	if (__predict_false(self->pt_cancel)) {
 		pthread__cancelled();
@@ -165,24 +166,42 @@ pthread_cond_timedwait(pthread_cond_t *c
 retval = errno;
 			}
 		}
-	} while (self->pt_condwait && !self->pt_cancel && !retval);
+		cancel = self->pt_cancel;
+	} while (self->pt_condwait && !cancel && !retval);
 
 	/*
-	 * If we have cancelled then exit.  POSIX dictates that
-	 * the mutex must be held when we action the cancellation.
+	 * If this thread absorbed a wakeup from pthread_cond_signal() and
+	 * cannot take the wakeup, we must ensure that another 

CVS commit: src/lib/libpthread

2020-06-01 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Jun  2 00:29:53 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_int.h pthread_rwlock.c

Log Message:
Pass down errno when calling pthread__errorfunc after a system call.
Allow format arguments for that reason and use (v)snprintf_ss in
pthread_errorfunc to avoid race conditions and the like.


To generate a diff of this commit:
cvs rdiff -u -r1.171 -r1.172 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.105 -r1.106 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.41 -r1.42 src/lib/libpthread/pthread_rwlock.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.171 src/lib/libpthread/pthread.c:1.172
--- src/lib/libpthread/pthread.c:1.171	Mon Jun  1 11:44:59 2020
+++ src/lib/libpthread/pthread.c	Tue Jun  2 00:29:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.171 2020/06/01 11:44:59 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.172 2020/06/02 00:29:53 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.171 2020/06/01 11:44:59 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.172 2020/06/02 00:29:53 joerg Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -622,7 +622,7 @@ pthread__clear_waiters(pthread_t self)
 		self->pt_nwaiters = 0;
 		if (rv != 0) {
 			pthread__errorfunc(__FILE__, __LINE__, __func__,
-			"_lwp_unpark failed");
+			"_lwp_unpark failed: %d", errno);
 		}
 		break;
 	default:
@@ -631,7 +631,7 @@ pthread__clear_waiters(pthread_t self)
 		self->pt_nwaiters = 0;
 		if (rv != 0) {
 			pthread__errorfunc(__FILE__, __LINE__, __func__,
-			"_lwp_unpark_all failed");
+			"_lwp_unpark_all failed: %d", errno);
 		}
 		break;
 	}
@@ -1102,23 +1102,29 @@ pthread__assertfunc(const char *file, in
 
 void
 pthread__errorfunc(const char *file, int line, const char *function,
-		   const char *msg)
+		   const char *msg, ...)
 {
 	char buf[1024];
+	char buf2[1024];
 	size_t len;
+	va_list ap;
 
 	if (pthread__diagassert == 0)
 		return;
 
+	va_start(ap, msg);
+	vsnprintf_ss(buf2, sizeof(buf2), msg, ap);
+	va_end(ap);
+
 	/*
 	 * snprintf should not acquire any locks, or we could
 	 * end up deadlocked if the assert caller held locks.
 	 */
-	len = snprintf(buf, 1024,
+	len = snprintf_ss(buf, sizeof(buf),
 	"%s: Error detected by libpthread: %s.\n"
 	"Detected by file \"%s\", line %d%s%s%s.\n"
 	"See pthread(3) for information.\n",
-	getprogname(), msg, file, line,
+	getprogname(), buf2, file, line,
 	function ? ", function \"" : "",
 	function ? function : "",
 	function ? "\"" : "");
@@ -1195,7 +1201,7 @@ pthread__park(pthread_t self, pthread_mu
 break;
 			default:
 pthread__errorfunc(__FILE__, __LINE__,
-__func__, "_lwp_park failed");
+__func__, "_lwp_park failed: %d", errno);
 break;
 			}
 		}

Index: src/lib/libpthread/pthread_int.h
diff -u src/lib/libpthread/pthread_int.h:1.105 src/lib/libpthread/pthread_int.h:1.106
--- src/lib/libpthread/pthread_int.h:1.105	Mon Jun  1 11:44:59 2020
+++ src/lib/libpthread/pthread_int.h	Tue Jun  2 00:29:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_int.h,v 1.105 2020/06/01 11:44:59 ad Exp $	*/
+/*	$NetBSD: pthread_int.h,v 1.106 2020/06/02 00:29:53 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -300,8 +300,8 @@ void	pthread__copy_tsd(pthread_t) PTHREA
 
 __dead void	pthread__assertfunc(const char *, int, const char *, const char *)
 			PTHREAD_HIDE;
-void	pthread__errorfunc(const char *, int, const char *, const char *)
-			   PTHREAD_HIDE;
+void	pthread__errorfunc(const char *, int, const char *, const char *, ...)
+			__printflike(4, 5) PTHREAD_HIDE;
 char	*pthread__getenv(const char *) PTHREAD_HIDE;
 __dead void	pthread__cancelled(void) PTHREAD_HIDE;
 void	pthread__mutex_deferwake(pthread_t, pthread_mutex_t *) PTHREAD_HIDE;

Index: src/lib/libpthread/pthread_rwlock.c
diff -u src/lib/libpthread/pthread_rwlock.c:1.41 src/lib/libpthread/pthread_rwlock.c:1.42
--- src/lib/libpthread/pthread_rwlock.c:1.41	Mon Jun  1 11:44:59 2020
+++ src/lib/libpthread/pthread_rwlock.c	Tue Jun  2 00:29:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_rwlock.c,v 1.41 2020/06/01 11:44:59 ad Exp $ */
+/*	$NetBSD: pthread_rwlock.c,v 1.42 2020/06/02 00:29:53 joerg Exp $ */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_rwlock.c,v 1.41 2020/06/01 11:44:59 ad Exp $");
+__RCSID("$NetBSD: pthread_rwlock.c,v 1.42 2020/06/02 00:29:53 joerg Exp $");
 
 #include 
 #include 
@@ -361,7 +361,7 @@ pthread__rwlock_wrlock(pthread_rwlock_t 
 			return error;
 
 		pthread__errorfunc(__FILE__, __LINE__, __func__,
-		"direct handoff failure");
+		"direct handoff failure: %d", 

CVS commit: src/lib/libpthread

2020-06-01 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jun  1 11:44:59 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_cond.c pthread_int.h
pthread_mutex.c pthread_rwlock.c pthread_types.h

Log Message:
In the interests of reliability simplify waiter handling more and redo
condvars to manage the list of waiters with atomic ops.


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.69 -r1.70 src/lib/libpthread/pthread_cond.c
cvs rdiff -u -r1.104 -r1.105 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.77 -r1.78 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.40 -r1.41 src/lib/libpthread/pthread_rwlock.c
cvs rdiff -u -r1.23 -r1.24 src/lib/libpthread/pthread_types.h

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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.170 src/lib/libpthread/pthread.c:1.171
--- src/lib/libpthread/pthread.c:1.170	Sat May 16 22:53:37 2020
+++ src/lib/libpthread/pthread.c	Mon Jun  1 11:44:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.170 2020/05/16 22:53:37 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.171 2020/06/01 11:44:59 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.170 2020/05/16 22:53:37 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.171 2020/06/01 11:44:59 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -294,12 +294,11 @@ pthread__initthread(pthread_t t)
 	t->pt_self = t;
 	t->pt_magic = PT_MAGIC;
 	t->pt_willpark = 0;
-	t->pt_unpark = 0;
+	t->pt_waiters[0] = 0;
 	t->pt_nwaiters = 0;
 	t->pt_sleepobj = NULL;
 	t->pt_signalled = 0;
 	t->pt_havespecific = 0;
-	t->pt_early = NULL;
 	t->pt_lwpctl = __dummy_lwpctl;
 
 	memcpy(>pt_lockops, pthread__lock_ops, sizeof(t->pt_lockops));
@@ -609,51 +608,32 @@ pthread__clear_waiters(pthread_t self)
 {
 	int rv;
 
-	/* Zero waiters or one waiter in error case (pthread_exit()). */
-	if (self->pt_nwaiters == 0) {
-		if (self->pt_unpark != 0 && self->pt_willpark == 0) {
-			rv = (ssize_t)_lwp_unpark(self->pt_unpark, NULL);
-			self->pt_unpark = 0;
-			if (rv != 0 && errno != EALREADY && errno != EINTR &&
-			errno != ESRCH) {
-pthread__errorfunc(__FILE__, __LINE__, __func__,
-"_lwp_unpark failed");
-			}
-		}
-		return;
-	}
+	pthread__smt_wake();
 
-	/* One waiter or two waiters (the second being a deferred wakeup). */
-	if (self->pt_nwaiters == 1) {
-		if (self->pt_unpark != 0) {
-			/* Fall through to multiple waiters case. */
-			self->pt_waiters[1] = self->pt_unpark;
-			self->pt_nwaiters = 2;
-			self->pt_unpark = 0;
-		} else if (self->pt_willpark) {
-			/* Defer to _lwp_park(). */
-			self->pt_unpark = self->pt_waiters[0];
-			self->pt_nwaiters = 0;
-			return;
-		} else {
-			/* Wake one now. */
-			rv = (ssize_t)_lwp_unpark(self->pt_waiters[0], NULL);
-			self->pt_nwaiters = 0;
-			if (rv != 0 && errno != EALREADY && errno != EINTR &&
-			errno != ESRCH) {
-pthread__errorfunc(__FILE__, __LINE__, __func__,
-"_lwp_unpark failed");
-			}
-			return;
+	switch (self->pt_nwaiters) {
+	case 0:
+		break;
+	case 1:
+		if (self->pt_willpark) {
+			break;
 		}
-	}
-
-	/* Multiple waiters. */
-	rv = _lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, NULL);
-	self->pt_nwaiters = 0;
-	if (rv != 0 && errno != EINTR) {
-		pthread__errorfunc(__FILE__, __LINE__, __func__,
-		"_lwp_unpark_all failed");
+		rv = _lwp_unpark(self->pt_waiters[0], NULL);
+		self->pt_waiters[0] = 0;
+		self->pt_nwaiters = 0;
+		if (rv != 0) {
+			pthread__errorfunc(__FILE__, __LINE__, __func__,
+			"_lwp_unpark failed");
+		}
+		break;
+	default:
+		rv = _lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, NULL);
+		self->pt_waiters[0] = 0;
+		self->pt_nwaiters = 0;
+		if (rv != 0) {
+			pthread__errorfunc(__FILE__, __LINE__, __func__,
+			"_lwp_unpark_all failed");
+		}
+		break;
 	}
 }
 
@@ -1115,7 +1095,7 @@ pthread__assertfunc(const char *file, in
 	function ? "\"" : "");
 
 	_sys_write(STDERR_FILENO, buf, (size_t)len);
-	(void)_lwp_kill(_lwp_self(), SIGABRT);
+	(void)raise(SIGABRT);
 	_exit(1);
 }
 
@@ -1163,16 +1143,12 @@ pthread__errorfunc(const char *file, int
  * http://www.sun.com/software/whitepapers/solaris9/multithread.pdf
  */
 
-#define	OOPS(msg)			\
-pthread__errorfunc(__FILE__, __LINE__, __func__, msg)
-
 int
 pthread__park(pthread_t self, pthread_mutex_t *lock,
 	  pthread_queue_t *queue, const struct timespec *abstime,
 	  int cancelpt)
 {
 	int rv, error;
-	void *obj;
 
 	self->pt_willpark = 1;
 	pthread_mutex_unlock(lock);
@@ -1186,26 +1162,15 @@ pthread__park(pthread_t self, pthread_mu
 	 * It is fine to test the value of pt_sleepobj without
 	 * holding any locks, because:
 	 *
-	 * o Only the blocking thread (this thread) ever sets them
+	 * o Only the blocking thread (this thread) ever sets 

CVS commit: src/lib/libpthread

2020-05-16 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 16 22:53:37 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_barrier.c pthread_cond.c
pthread_int.h pthread_mutex.c pthread_rwlock.c

Log Message:
- Try to eliminate a hang in "parked" I've been seeing while stress testing.
  Centralise wakeup of deferred waiters in pthread__clear_waiters() and use
  throughout libpthread.  Make fewer assumptions.  Be more conservative in
  pthread_mutex when dealing with pending waiters.

- Remove the "hint" argument everywhere since the kernel doesn't use it any
  more.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.21 -r1.22 src/lib/libpthread/pthread_barrier.c
cvs rdiff -u -r1.68 -r1.69 src/lib/libpthread/pthread_cond.c
cvs rdiff -u -r1.103 -r1.104 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.76 -r1.77 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.39 -r1.40 src/lib/libpthread/pthread_rwlock.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.169 src/lib/libpthread/pthread.c:1.170
--- src/lib/libpthread/pthread.c:1.169	Fri May 15 14:30:23 2020
+++ src/lib/libpthread/pthread.c	Sat May 16 22:53:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.169 2020/05/15 14:30:23 joerg Exp $	*/
+/*	$NetBSD: pthread.c,v 1.170 2020/05/16 22:53:37 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.169 2020/05/15 14:30:23 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.170 2020/05/16 22:53:37 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -105,7 +105,7 @@ static int pthread__diagassert;
 
 int pthread__concurrency;
 int pthread__nspins;
-int pthread__unpark_max = PTHREAD__UNPARK_MAX;
+size_t pthread__unpark_max = PTHREAD__UNPARK_MAX;
 int pthread__dbg;	/* set by libpthread_dbg if active */
 
 /*
@@ -191,9 +191,9 @@ pthread__init(void)
 {
 	pthread_t first;
 	char *p;
-	int i;
 	int mib[2];
 	unsigned int value;
+	ssize_t slen;
 	size_t len;
 	extern int __isthreaded;
 
@@ -223,16 +223,16 @@ pthread__init(void)
 
 	/* Initialize locks first; they're needed elsewhere. */
 	pthread__lockprim_init();
-	for (i = 0; i < NHASHLOCK; i++) {
+	for (int i = 0; i < NHASHLOCK; i++) {
 		pthread_mutex_init([i].mutex, NULL);
 	}
 
 	/* Fetch parameters. */
-	i = (int)_lwp_unpark_all(NULL, 0, NULL);
-	if (i == -1)
+	slen = _lwp_unpark_all(NULL, 0, NULL);
+	if (slen < 0)
 		err(EXIT_FAILURE, "_lwp_unpark_all");
-	if (i < pthread__unpark_max)
-		pthread__unpark_max = i;
+	if ((size_t)slen < pthread__unpark_max)
+		pthread__unpark_max = slen;
 
 	/* Basic data structure setup */
 	pthread_attr_init(_default_attr);
@@ -604,16 +604,57 @@ pthread_resume_np(pthread_t thread)
  * awoken (because cancelled, for instance) make sure we have no waiters
  * left.
  */
-static void
+void
 pthread__clear_waiters(pthread_t self)
 {
+	int rv;
 
-	if (self->pt_nwaiters != 0) {
-		(void)_lwp_unpark_all(self->pt_waiters, self->pt_nwaiters,
-		NULL);
-		self->pt_nwaiters = 0;
+	/* Zero waiters or one waiter in error case (pthread_exit()). */
+	if (self->pt_nwaiters == 0) {
+		if (self->pt_unpark != 0 && self->pt_willpark == 0) {
+			rv = (ssize_t)_lwp_unpark(self->pt_unpark, NULL);
+			self->pt_unpark = 0;
+			if (rv != 0 && errno != EALREADY && errno != EINTR &&
+			errno != ESRCH) {
+pthread__errorfunc(__FILE__, __LINE__, __func__,
+"_lwp_unpark failed");
+			}
+		}
+		return;
+	}
+
+	/* One waiter or two waiters (the second being a deferred wakeup). */
+	if (self->pt_nwaiters == 1) {
+		if (self->pt_unpark != 0) {
+			/* Fall through to multiple waiters case. */
+			self->pt_waiters[1] = self->pt_unpark;
+			self->pt_nwaiters = 2;
+			self->pt_unpark = 0;
+		} else if (self->pt_willpark) {
+			/* Defer to _lwp_park(). */
+			self->pt_unpark = self->pt_waiters[0];
+			self->pt_nwaiters = 0;
+			return;
+		} else {
+			/* Wake one now. */
+			rv = (ssize_t)_lwp_unpark(self->pt_waiters[0], NULL);
+			self->pt_nwaiters = 0;
+			if (rv != 0 && errno != EALREADY && errno != EINTR &&
+			errno != ESRCH) {
+pthread__errorfunc(__FILE__, __LINE__, __func__,
+"_lwp_unpark failed");
+			}
+			return;
+		}
+	}
+
+	/* Multiple waiters. */
+	rv = _lwp_unpark_all(self->pt_waiters, self->pt_nwaiters, NULL);
+	self->pt_nwaiters = 0;
+	if (rv != 0 && errno != EINTR) {
+		pthread__errorfunc(__FILE__, __LINE__, __func__,
+		"_lwp_unpark_all failed");
 	}
-	self->pt_willpark = 0;
 }
 
 void
@@ -630,6 +671,7 @@ pthread_exit(void *retval)
 	self = pthread__self();
 
 	/* Disable cancellability. */
+	self->pt_willpark = 0;
 	pthread_mutex_lock(>pt_lock);
 	self->pt_flags |= PT_FLAG_CS_DISABLED;
 	self->pt_cancel = 0;
@@ -660,10 +702,12 @@ pthread_exit(void *retval)
 	if (self->pt_flags & 

CVS commit: src/lib/libpthread

2020-05-15 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri May 15 14:30:23 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Lock/unlock/reinit pthread__deadqueue_lock over fork.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.168 src/lib/libpthread/pthread.c:1.169
--- src/lib/libpthread/pthread.c:1.168	Tue Apr 14 23:35:07 2020
+++ src/lib/libpthread/pthread.c	Fri May 15 14:30:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.168 2020/04/14 23:35:07 joerg Exp $	*/
+/*	$NetBSD: pthread.c,v 1.169 2020/05/15 14:30:23 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.168 2020/04/14 23:35:07 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.169 2020/05/15 14:30:23 joerg Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -82,7 +82,6 @@ static void	pthread__create_tramp(void *
 static void	pthread__initthread(pthread_t);
 static void	pthread__scrubthread(pthread_t, char *, int);
 static void	pthread__initmain(pthread_t *);
-static void	pthread__fork_callback(void);
 static void	pthread__reap(pthread_t);
 
 void	pthread__init(void);
@@ -155,6 +154,32 @@ static union hashlock {
 	char		pad[64];
 } hashlocks[NHASHLOCK] __aligned(64);
 
+static void
+pthread__prefork(void)
+{
+	pthread_mutex_lock(__deadqueue_lock);
+}
+
+static void
+pthread__fork_parent(void)
+{
+	pthread_mutex_unlock(__deadqueue_lock);
+}
+
+static void
+pthread__fork_child(void)
+{
+	struct __pthread_st *self = pthread__self();
+
+	pthread_mutex_init(__deadqueue_lock, NULL);
+
+	/* lwpctl state is not copied across fork. */
+	if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, >pt_lwpctl)) {
+		err(EXIT_FAILURE, "_lwp_ctl");
+	}
+	self->pt_lid = _lwp_self();
+}
+
 /*
  * This needs to be started by the library loading code, before main()
  * gets to run, for various things that use the state of the initial thread
@@ -256,22 +281,10 @@ pthread__init(void)
 	}
 
 	/* Tell libc that we're here and it should role-play accordingly. */
-	pthread_atfork(NULL, NULL, pthread__fork_callback);
+	pthread_atfork(pthread__prefork, pthread__fork_parent, pthread__fork_child);
 	__isthreaded = 1;
 }
 
-static void
-pthread__fork_callback(void)
-{
-	struct __pthread_st *self = pthread__self();
-
-	/* lwpctl state is not copied across fork. */
-	if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, >pt_lwpctl)) {
-		err(EXIT_FAILURE, "_lwp_ctl");
-	}
-	self->pt_lid = _lwp_self();
-}
-
 /* General-purpose thread data structure sanitization. */
 /* ARGSUSED */
 static void



CVS commit: src/lib/libpthread

2020-04-19 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Apr 19 20:47:04 UTC 2020

Modified Files:
src/lib/libpthread: pthread_tsd.c

Log Message:
Improve TSD behavior

Optimistically check whether the key has been used by this thread
already and avoid locking in that case. This avoids the atomic operation
in the hot path. When the value is set to non-NULL for the first time,
put the entry on the to-be-freed list and keep it their until
destruction or thread exit. Setting the key to NULL and back is common
enough and updating the list is more expensive than the extra check on
the final round.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libpthread/pthread_tsd.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/pthread_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.21 src/lib/libpthread/pthread_tsd.c:1.22
--- src/lib/libpthread/pthread_tsd.c:1.21	Sun Apr 19 20:46:04 2020
+++ src/lib/libpthread/pthread_tsd.c	Sun Apr 19 20:47:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_tsd.c,v 1.21 2020/04/19 20:46:04 joerg Exp $	*/
+/*	$NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_tsd.c,v 1.21 2020/04/19 20:46:04 joerg Exp $");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.22 2020/04/19 20:47:03 joerg Exp $");
 
 /* Functions and structures dealing with thread-specific data */
 #include 
@@ -173,14 +173,17 @@ pthread_key_create(pthread_key_t *key, v
  * elements. When an element is used it is inserted into the appropriate
  * key bucket of pthread__tsd_list. This means that ptqe_prev == NULL,
  * means that the element is not threaded, ptqe_prev != NULL it is
- * already part of the list. When we set to a NULL value we delete from the
- * list if it was in the list, and when we set to non-NULL value, we insert
- * in the list if it was not already there.
+ * already part of the list. If a key is set to a non-NULL value for the
+ * first time, it is added to the list.
  *
  * We keep this global array of lists of threads that have called
  * pthread_set_specific with non-null values, for each key so that
  * we don't have to check all threads for non-NULL values in
- * pthread_key_destroy
+ * pthread_key_destroy.
+ *
+ * The assumption here is that a concurrent pthread_key_delete is already
+ * undefined behavior. The mutex is taken only once per thread/key
+ * combination.
  *
  * We could keep an accounting of the number of specific used
  * entries per thread, so that we can update pt_havespecific when we delete
@@ -193,21 +196,15 @@ pthread__add_specific(pthread_t self, pt
 
 	pthread__assert(key >= 0 && key < pthread_keys_max);
 
-	pthread_mutex_lock(_mutex);
 	pthread__assert(pthread__tsd_destructors[key] != NULL);
 	pt = >pt_specific[key];
 	self->pt_havespecific = 1;
-	if (value) {
-		if (pt->pts_next.ptqe_prev == NULL)
-			PTQ_INSERT_HEAD(__tsd_list[key], pt, pts_next);
-	} else {
-		if (pt->pts_next.ptqe_prev != NULL) {
-			PTQ_REMOVE(__tsd_list[key], pt, pts_next);
-			pt->pts_next.ptqe_prev = NULL;
-		}
+	if (value && !pt->pts_next.ptqe_prev) {
+		pthread_mutex_lock(_mutex);
+		PTQ_INSERT_HEAD(__tsd_list[key], pt, pts_next);
+		pthread_mutex_unlock(_mutex);
 	}
 	pt->pts_value = __UNCONST(value);
-	pthread_mutex_unlock(_mutex);
 
 	return 0;
 }
@@ -373,7 +370,7 @@ pthread__destroy_tsd(pthread_t self)
 destructor = NULL;
 
 			pthread_mutex_unlock(_mutex);
-			if (destructor != NULL) {
+			if (destructor != NULL && val != NULL) {
 done = 0;
 (*destructor)(val);
 			}



CVS commit: src/lib/libpthread

2020-04-19 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Apr 19 20:46:04 UTC 2020

Modified Files:
src/lib/libpthread: pthread_tsd.c

Log Message:
Reinit TSD mutex in the child to avoid issues with former waiters


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libpthread/pthread_tsd.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/pthread_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.20 src/lib/libpthread/pthread_tsd.c:1.21
--- src/lib/libpthread/pthread_tsd.c:1.20	Sun Feb 16 17:45:11 2020
+++ src/lib/libpthread/pthread_tsd.c	Sun Apr 19 20:46:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_tsd.c,v 1.20 2020/02/16 17:45:11 kamil Exp $	*/
+/*	$NetBSD: pthread_tsd.c,v 1.21 2020/04/19 20:46:04 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_tsd.c,v 1.20 2020/02/16 17:45:11 kamil Exp $");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.21 2020/04/19 20:46:04 joerg Exp $");
 
 /* Functions and structures dealing with thread-specific data */
 #include 
@@ -73,6 +73,12 @@ pthread_tsd_postfork(void)
 	pthread_mutex_unlock(_mutex);
 }
 
+static void
+pthread_tsd_postfork_child(void)
+{
+	pthread_mutex_init(_mutex, NULL);
+}
+
 void *
 pthread_tsd_init(size_t *tlen)
 {
@@ -80,7 +86,7 @@ pthread_tsd_init(size_t *tlen)
 	size_t alen;
 	char *arena;
 
-	pthread_atfork(pthread_tsd_prefork, pthread_tsd_postfork, pthread_tsd_postfork);
+	pthread_atfork(pthread_tsd_prefork, pthread_tsd_postfork, pthread_tsd_postfork_child);
 
 	if ((pkm = pthread__getenv("PTHREAD_KEYS_MAX")) != NULL) {
 		pthread_keys_max = (int)strtol(pkm, NULL, 0);



CVS commit: src/lib/libpthread

2020-04-14 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Apr 14 23:35:07 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_cond.c

Log Message:
Drop most of the logic associated with pthread__started.

The pthread_cond logic is a questionable optimisation at best and the
post-fork logic is plainly broken.


To generate a diff of this commit:
cvs rdiff -u -r1.167 -r1.168 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.67 -r1.68 src/lib/libpthread/pthread_cond.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.167 src/lib/libpthread/pthread.c:1.168
--- src/lib/libpthread/pthread.c:1.167	Sun Feb 16 17:45:11 2020
+++ src/lib/libpthread/pthread.c	Tue Apr 14 23:35:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.167 2020/02/16 17:45:11 kamil Exp $	*/
+/*	$NetBSD: pthread.c,v 1.168 2020/04/14 23:35:07 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.167 2020/02/16 17:45:11 kamil Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.168 2020/04/14 23:35:07 joerg Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -84,8 +84,6 @@ static void	pthread__scrubthread(pthread
 static void	pthread__initmain(pthread_t *);
 static void	pthread__fork_callback(void);
 static void	pthread__reap(pthread_t);
-static void	pthread__child_callback(void);
-static void	pthread__start(void);
 
 void	pthread__init(void);
 
@@ -274,36 +272,6 @@ pthread__fork_callback(void)
 	self->pt_lid = _lwp_self();
 }
 
-static void
-pthread__child_callback(void)
-{
-
-	/*
-	 * Clean up data structures that a forked child process might
-	 * trip over. Note that if threads have been created (causing
-	 * this handler to be registered) the standards say that the
-	 * child will trigger undefined behavior if it makes any
-	 * pthread_* calls (or any other calls that aren't
-	 * async-signal-safe), so we don't really have to clean up
-	 * much. Anything that permits some pthread_* calls to work is
-	 * merely being polite.
-	 */
-	pthread__started = 0;
-}
-
-static void
-pthread__start(void)
-{
-
-	/*
-	 * Per-process timers are cleared by fork(); despite the
-	 * various restrictions on fork() and threads, it's legal to
-	 * fork() before creating any threads.
-	 */
-	pthread_atfork(NULL, NULL, pthread__child_callback);
-}
-
-
 /* General-purpose thread data structure sanitization. */
 /* ARGSUSED */
 static void
@@ -424,15 +392,6 @@ pthread_create(pthread_t *thread, const 
 		return __libc_thr_create_stub(thread, attr, startfunc, arg);
 	}
 
-	/*
-	 * It's okay to check this without a lock because there can
-	 * only be one thread before it becomes true.
-	 */
-	if (pthread__started == 0) {
-		pthread__start();
-		pthread__started = 1;
-	}
-
 	if (attr == NULL)
 		nattr = pthread_default_attr;
 	else if (attr->pta_magic == PT_ATTR_MAGIC)
@@ -440,6 +399,8 @@ pthread_create(pthread_t *thread, const 
 	else
 		return EINVAL;
 
+	pthread__started = 1;
+
 	/* Fetch misc. attributes from the attr structure. */
 	name = NULL;
 	if ((p = nattr.pta_private) != NULL)

Index: src/lib/libpthread/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.67 src/lib/libpthread/pthread_cond.c:1.68
--- src/lib/libpthread/pthread_cond.c:1.67	Wed Jan 29 15:07:46 2020
+++ src/lib/libpthread/pthread_cond.c	Tue Apr 14 23:35:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.68 2020/04/14 23:35:07 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.68 2020/04/14 23:35:07 joerg Exp $");
 
 #include 
 #include 
@@ -59,11 +59,6 @@ __RCSID("$NetBSD: pthread_cond.c,v 1.67 
 
 int	_sys___nanosleep50(const struct timespec *, struct timespec *);
 
-extern int pthread__started;
-
-static int pthread_cond_wait_nothread(pthread_t, pthread_mutex_t *,
-pthread_cond_t *, const struct timespec *);
-
 int	_pthread_cond_has_waiters_np(pthread_cond_t *);
 
 __weak_alias(pthread_cond_has_waiters_np,_pthread_cond_has_waiters_np)
@@ -149,10 +144,6 @@ pthread_cond_timedwait(pthread_cond_t *c
 
 	self = pthread__self();
 
-	/* Just hang out for a while if threads aren't running yet. */
-	if (__predict_false(pthread__started == 0)) {
-		return pthread_cond_wait_nothread(self, mutex, cond, abstime);
-	}
 	if (__predict_false(self->pt_cancel)) {
 		pthread__cancelled();
 	}
@@ -431,38 +422,3 @@ pthread_condattr_setpshared(pthread_cond
 	return EINVAL;
 }
 #endif
-
-/* Utility routine to hang out for a while if threads haven't started yet. */
-static int
-pthread_cond_wait_nothread(pthread_t self, pthread_mutex_t *mutex,
-pthread_cond_t *cond, const struct timespec *abstime)

CVS commit: src/lib/libpthread

2020-02-16 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Feb 16 17:45:12 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_int.h pthread_mutex.c
pthread_tsd.c

Log Message:
Revert "Enhance the pthread(3) + malloc(3) init model"

It is reported to hand on aarch64 with gzip.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.102 -r1.103 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.75 -r1.76 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.19 -r1.20 src/lib/libpthread/pthread_tsd.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.166 src/lib/libpthread/pthread.c:1.167
--- src/lib/libpthread/pthread.c:1.166	Sun Feb 16 17:14:31 2020
+++ src/lib/libpthread/pthread.c	Sun Feb 16 17:45:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.166 2020/02/16 17:14:31 kamil Exp $	*/
+/*	$NetBSD: pthread.c,v 1.167 2020/02/16 17:45:11 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.166 2020/02/16 17:14:31 kamil Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.167 2020/02/16 17:45:11 kamil Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -181,7 +181,7 @@ pthread__init(void)
 	 * while pthread_keys descriptors are not
 	 * yet allocated.
 	 */
-	pthread__main = pthread_tsd_earlyinit(&__pthread_st_size);
+	pthread__main = pthread_tsd_init(&__pthread_st_size);
 	if (pthread__main == NULL)
 		err(EXIT_FAILURE, "Cannot allocate pthread storage");
 
@@ -257,23 +257,9 @@ pthread__init(void)
 		}
 	}
 
-	/*
-	 * We are officially threded now.
-	 *
-	 * libc must be informed about this before bootstrapping malloc(3).
-	 */
-	__isthreaded = 1;
-
-	/*
-	 * Tell libc that we're here and it should role-play accordingly.
-	 *
-	 * pthread_atfork(3) calls malloc(3) and initializes the system malloc.
-	 * At this point all POSIX thread inferfaces must be functional.
-	 */
+	/* Tell libc that we're here and it should role-play accordingly. */
 	pthread_atfork(NULL, NULL, pthread__fork_callback);
-
-	/* Register atfork handlers for TSD. */
-	pthread_tsd_init();
+	__isthreaded = 1;
 }
 
 static void

Index: src/lib/libpthread/pthread_int.h
diff -u src/lib/libpthread/pthread_int.h:1.102 src/lib/libpthread/pthread_int.h:1.103
--- src/lib/libpthread/pthread_int.h:1.102	Sat Feb 15 23:59:30 2020
+++ src/lib/libpthread/pthread_int.h	Sun Feb 16 17:45:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_int.h,v 1.102 2020/02/15 23:59:30 kamil Exp $	*/
+/*	$NetBSD: pthread_int.h,v 1.103 2020/02/16 17:45:11 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -294,8 +294,7 @@ pthread__self(void)
 	} \
 } while (/*CONSTCOND*/0)
 
-void 	*pthread_tsd_earlyinit(size_t *) PTHREAD_HIDE;
-void 	pthread_tsd_init(void) PTHREAD_HIDE;
+void 	*pthread_tsd_init(size_t *) PTHREAD_HIDE;
 void	pthread__destroy_tsd(pthread_t) PTHREAD_HIDE;
 void	pthread__copy_tsd(pthread_t) PTHREAD_HIDE;
 

Index: src/lib/libpthread/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.75 src/lib/libpthread/pthread_mutex.c:1.76
--- src/lib/libpthread/pthread_mutex.c:1.75	Sat Feb 15 23:59:30 2020
+++ src/lib/libpthread/pthread_mutex.c	Sun Feb 16 17:45:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.75 2020/02/15 23:59:30 kamil Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.76 2020/02/16 17:45:11 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.75 2020/02/15 23:59:30 kamil Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.76 2020/02/16 17:45:11 kamil Exp $");
 
 #include 
 #include 
@@ -122,12 +122,14 @@ pthread_mutex_init(pthread_mutex_t *ptm,
 {
 	uintptr_t type, proto, val, ceil;
 
+#if 0
 	/*
 	 * Always initialize the mutex structure, maybe be used later
 	 * and the cost should be minimal.
 	 */
 	if (__predict_false(__uselibcstub))
 		return __libc_mutex_init_stub(ptm, attr);
+#endif
 
 	pthread__error(EINVAL, "Invalid mutes attribute",
 	attr == NULL || attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
@@ -617,9 +619,10 @@ pthread__mutex_wakeup(pthread_t self, pt
 int
 pthread_mutexattr_init(pthread_mutexattr_t *attr)
 {
-
+#if 0
 	if (__predict_false(__uselibcstub))
 		return __libc_mutexattr_init_stub(attr);
+#endif
 
 	attr->ptma_magic = _PT_MUTEXATTR_MAGIC;
 	attr->ptma_private = (void *)PTHREAD_MUTEX_DEFAULT;

Index: src/lib/libpthread/pthread_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.19 src/lib/libpthread/pthread_tsd.c:1.20
--- src/lib/libpthread/pthread_tsd.c:1.19	Sat Feb 15 23:59:30 2020
+++ src/lib/libpthread/pthread_tsd.c	Sun Feb 16 17:45:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_tsd.c,v 1.19 2020/02/15 23:59:30 kamil Exp $	*/
+/*	$NetBSD: 

CVS commit: src/lib/libpthread

2020-02-16 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Feb 16 17:14:31 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Set __isthreaded before bootstrapping malloc(3)

jemalloc depends on the __isthreaded dynamic state logic.

Reported by  for mpv and by  for gzip.


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.165 src/lib/libpthread/pthread.c:1.166
--- src/lib/libpthread/pthread.c:1.165	Sat Feb 15 23:59:30 2020
+++ src/lib/libpthread/pthread.c	Sun Feb 16 17:14:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.165 2020/02/15 23:59:30 kamil Exp $	*/
+/*	$NetBSD: pthread.c,v 1.166 2020/02/16 17:14:31 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.165 2020/02/15 23:59:30 kamil Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.166 2020/02/16 17:14:31 kamil Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -258,16 +258,22 @@ pthread__init(void)
 	}
 
 	/*
+	 * We are officially threded now.
+	 *
+	 * libc must be informed about this before bootstrapping malloc(3).
+	 */
+	__isthreaded = 1;
+
+	/*
 	 * Tell libc that we're here and it should role-play accordingly.
 	 *
 	 * pthread_atfork(3) calls malloc(3) and initializes the system malloc.
+	 * At this point all POSIX thread inferfaces must be functional.
 	 */
 	pthread_atfork(NULL, NULL, pthread__fork_callback);
 
-	/* Requires functional malloc(3). */
+	/* Register atfork handlers for TSD. */
 	pthread_tsd_init();
-
-	__isthreaded = 1;
 }
 
 static void



CVS commit: src/lib/libpthread

2020-02-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb 15 23:59:30 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_int.h pthread_mutex.c
pthread_tsd.c

Log Message:
Enhance the pthread(3) + malloc(3) init model

Separate the pthread_atfork(3) call from pthread_tsd_init()
and move it into a distinct function.

Call inside pthread__init() late TSD initialization route, just after
"pthread_atfork(NULL, NULL, pthread__fork_callback);".

Document that malloc(3) initialization is now controlled again and called
during the first pthread_atfork(3) call.

Remove #if 0 code from pthread_mutex.c as we no longer initialize malloc
prematurely.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.101 -r1.102 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.74 -r1.75 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libpthread/pthread_tsd.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.164 src/lib/libpthread/pthread.c:1.165
--- src/lib/libpthread/pthread.c:1.164	Sat Feb  8 17:06:03 2020
+++ src/lib/libpthread/pthread.c	Sat Feb 15 23:59:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.164 2020/02/08 17:06:03 kamil Exp $	*/
+/*	$NetBSD: pthread.c,v 1.165 2020/02/15 23:59:30 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.164 2020/02/08 17:06:03 kamil Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.165 2020/02/15 23:59:30 kamil Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -181,7 +181,7 @@ pthread__init(void)
 	 * while pthread_keys descriptors are not
 	 * yet allocated.
 	 */
-	pthread__main = pthread_tsd_init(&__pthread_st_size);
+	pthread__main = pthread_tsd_earlyinit(&__pthread_st_size);
 	if (pthread__main == NULL)
 		err(EXIT_FAILURE, "Cannot allocate pthread storage");
 
@@ -257,8 +257,16 @@ pthread__init(void)
 		}
 	}
 
-	/* Tell libc that we're here and it should role-play accordingly. */
+	/*
+	 * Tell libc that we're here and it should role-play accordingly.
+	 *
+	 * pthread_atfork(3) calls malloc(3) and initializes the system malloc.
+	 */
 	pthread_atfork(NULL, NULL, pthread__fork_callback);
+
+	/* Requires functional malloc(3). */
+	pthread_tsd_init();
+
 	__isthreaded = 1;
 }
 

Index: src/lib/libpthread/pthread_int.h
diff -u src/lib/libpthread/pthread_int.h:1.101 src/lib/libpthread/pthread_int.h:1.102
--- src/lib/libpthread/pthread_int.h:1.101	Wed Feb  5 11:05:10 2020
+++ src/lib/libpthread/pthread_int.h	Sat Feb 15 23:59:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_int.h,v 1.101 2020/02/05 11:05:10 kamil Exp $	*/
+/*	$NetBSD: pthread_int.h,v 1.102 2020/02/15 23:59:30 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -294,7 +294,8 @@ pthread__self(void)
 	} \
 } while (/*CONSTCOND*/0)
 
-void 	*pthread_tsd_init(size_t *) PTHREAD_HIDE;
+void 	*pthread_tsd_earlyinit(size_t *) PTHREAD_HIDE;
+void 	pthread_tsd_init(void) PTHREAD_HIDE;
 void	pthread__destroy_tsd(pthread_t) PTHREAD_HIDE;
 void	pthread__copy_tsd(pthread_t) PTHREAD_HIDE;
 

Index: src/lib/libpthread/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.74 src/lib/libpthread/pthread_mutex.c:1.75
--- src/lib/libpthread/pthread_mutex.c:1.74	Sat Feb  1 18:14:16 2020
+++ src/lib/libpthread/pthread_mutex.c	Sat Feb 15 23:59:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.74 2020/02/01 18:14:16 kamil Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.75 2020/02/15 23:59:30 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.74 2020/02/01 18:14:16 kamil Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.75 2020/02/15 23:59:30 kamil Exp $");
 
 #include 
 #include 
@@ -122,14 +122,12 @@ pthread_mutex_init(pthread_mutex_t *ptm,
 {
 	uintptr_t type, proto, val, ceil;
 
-#if 0
 	/*
 	 * Always initialize the mutex structure, maybe be used later
 	 * and the cost should be minimal.
 	 */
 	if (__predict_false(__uselibcstub))
 		return __libc_mutex_init_stub(ptm, attr);
-#endif
 
 	pthread__error(EINVAL, "Invalid mutes attribute",
 	attr == NULL || attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
@@ -619,10 +617,9 @@ pthread__mutex_wakeup(pthread_t self, pt
 int
 pthread_mutexattr_init(pthread_mutexattr_t *attr)
 {
-#if 0
+
 	if (__predict_false(__uselibcstub))
 		return __libc_mutexattr_init_stub(attr);
-#endif
 
 	attr->ptma_magic = _PT_MUTEXATTR_MAGIC;
 	attr->ptma_private = (void *)PTHREAD_MUTEX_DEFAULT;

Index: src/lib/libpthread/pthread_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.18 src/lib/libpthread/pthread_tsd.c:1.19
--- src/lib/libpthread/pthread_tsd.c:1.18	Wed Dec 25 00:44:45 2019
+++ 

CVS commit: src/lib/libpthread

2020-02-08 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb  8 17:06:03 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Change the behavior of pthread_equal()

On error when not aborting, do not return EINVAL as it has a side effect
of being interpreted as matching threads. For invalid threads return
unmatched.

Check pthreads for NULL, before accessing pt_magic field. This avoids
faults on comparision with a NULL pointer.

This behavior is in the scope of UB, but should be easier to deal with
buggy software.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.163 src/lib/libpthread/pthread.c:1.164
--- src/lib/libpthread/pthread.c:1.163	Wed Feb  5 14:56:04 2020
+++ src/lib/libpthread/pthread.c	Sat Feb  8 17:06:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.163 2020/02/05 14:56:04 ryoon Exp $	*/
+/*	$NetBSD: pthread.c,v 1.164 2020/02/08 17:06:03 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.163 2020/02/05 14:56:04 ryoon Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.164 2020/02/08 17:06:03 kamil Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -770,11 +770,11 @@ pthread_equal(pthread_t t1, pthread_t t2
 	if (__predict_false(__uselibcstub))
 		return __libc_thr_equal_stub(t1, t2);
 
-	pthread__error(EINVAL, "Invalid thread",
-	t1->pt_magic == PT_MAGIC);
+	pthread__error(0, "Invalid thread",
+	(t1 != NULL) && (t1->pt_magic == PT_MAGIC));
 
-	pthread__error(EINVAL, "Invalid thread",
-	t2->pt_magic == PT_MAGIC);
+	pthread__error(0, "Invalid thread",
+	(t2 != NULL) && (t2->pt_magic == PT_MAGIC));
 
 	/* Nothing special here. */
 	return (t1 == t2);



CVS commit: src/lib/libpthread

2020-02-05 Thread Ryo ONODERA
Module Name:src
Committed By:   ryoon
Date:   Wed Feb  5 14:56:04 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Remove trailing whiteapaces and tab


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.162 src/lib/libpthread/pthread.c:1.163
--- src/lib/libpthread/pthread.c:1.162	Wed Jan 29 17:11:57 2020
+++ src/lib/libpthread/pthread.c	Wed Feb  5 14:56:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.162 2020/01/29 17:11:57 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.163 2020/02/05 14:56:04 ryoon Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.162 2020/01/29 17:11:57 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.163 2020/02/05 14:56:04 ryoon Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -111,7 +111,7 @@ int pthread__nspins;
 int pthread__unpark_max = PTHREAD__UNPARK_MAX;
 int pthread__dbg;	/* set by libpthread_dbg if active */
 
-/* 
+/*
  * We have to initialize the pthread_stack* variables here because
  * mutexes are used before pthread_init() and thus pthread__initmain()
  * are called.  Since mutexes only save the stack pointer and not a
@@ -176,9 +176,9 @@ pthread__init(void)
 
 	/*
 	 * Allocate pthread_keys descriptors before
-	 * reseting __uselibcstub because otherwise 
+	 * reseting __uselibcstub because otherwise
 	 * malloc() will call pthread_keys_create()
-	 * while pthread_keys descriptors are not 
+	 * while pthread_keys descriptors are not
 	 * yet allocated.
 	 */
 	pthread__main = pthread_tsd_init(&__pthread_st_size);
@@ -298,7 +298,7 @@ pthread__start(void)
 	/*
 	 * Per-process timers are cleared by fork(); despite the
 	 * various restrictions on fork() and threads, it's legal to
-	 * fork() before creating any threads. 
+	 * fork() before creating any threads.
 	 */
 	pthread_atfork(NULL, NULL, pthread__child_callback);
 }
@@ -617,7 +617,7 @@ pthread_resume_np(pthread_t thread)
 
 	pthread__error(EINVAL, "Invalid thread",
 	thread->pt_magic == PT_MAGIC);
- 
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 	if (_lwp_continue(thread->pt_lid) == 0)
@@ -1089,7 +1089,7 @@ pthread__assertfunc(const char *file, in
 	 * snprintf should not acquire any locks, or we could
 	 * end up deadlocked if the assert caller held locks.
 	 */
-	len = snprintf(buf, 1024, 
+	len = snprintf(buf, 1024,
 	"assertion \"%s\" failed: file \"%s\", line %d%s%s%s\n",
 	expr, file, line,
 	function ? ", function \"" : "",
@@ -1108,7 +1108,7 @@ pthread__errorfunc(const char *file, int
 {
 	char buf[1024];
 	size_t len;
-	
+
 	if (pthread__diagassert == 0)
 		return;
 
@@ -1116,7 +1116,7 @@ pthread__errorfunc(const char *file, int
 	 * snprintf should not acquire any locks, or we could
 	 * end up deadlocked if the assert caller held locks.
 	 */
-	len = snprintf(buf, 1024, 
+	len = snprintf(buf, 1024,
 	"%s: Error detected by libpthread: %s.\n"
 	"Detected by file \"%s\", line %d%s%s%s.\n"
 	"See pthread(3) for information.\n",



CVS commit: src/lib/libpthread

2020-02-05 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Feb  5 11:05:10 UTC 2020

Modified Files:
src/lib/libpthread: pthread_int.h pthread_rwlock.c pthread_spin.c

Log Message:
Retire ifdef ERRORCHECK in pthread(3)

It is enabled unconditionally since 2003 and used only for rwlocks and
spinlocks.

LLVM sanitizers make assumptions that these checks are enabled always.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.38 -r1.39 src/lib/libpthread/pthread_rwlock.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libpthread/pthread_spin.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/pthread_int.h
diff -u src/lib/libpthread/pthread_int.h:1.100 src/lib/libpthread/pthread_int.h:1.101
--- src/lib/libpthread/pthread_int.h:1.100	Tue Jan 28 13:08:40 2020
+++ src/lib/libpthread/pthread_int.h	Wed Feb  5 11:05:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_int.h,v 1.100 2020/01/28 13:08:40 ad Exp $	*/
+/*	$NetBSD: pthread_int.h,v 1.101 2020/02/05 11:05:10 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -36,7 +36,6 @@
 #include 
 
 /* #define PTHREAD__DEBUG */
-#define ERRORCHECK
 
 #include "pthread_types.h"
 #include "pthread_queue.h"

Index: src/lib/libpthread/pthread_rwlock.c
diff -u src/lib/libpthread/pthread_rwlock.c:1.38 src/lib/libpthread/pthread_rwlock.c:1.39
--- src/lib/libpthread/pthread_rwlock.c:1.38	Fri Jan 31 17:52:14 2020
+++ src/lib/libpthread/pthread_rwlock.c	Wed Feb  5 11:05:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_rwlock.c,v 1.38 2020/01/31 17:52:14 kamil Exp $ */
+/*	$NetBSD: pthread_rwlock.c,v 1.39 2020/02/05 11:05:10 kamil Exp $ */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_rwlock.c,v 1.38 2020/01/31 17:52:14 kamil Exp $");
+__RCSID("$NetBSD: pthread_rwlock.c,v 1.39 2020/02/05 11:05:10 kamil Exp $");
 
 #include 
 #include 
@@ -158,10 +158,8 @@ pthread__rwlock_rdlock(pthread_rwlock_t 
 	pthread_t self;
 	int error;
 
-#ifdef ERRORCHECK
 	pthread__error(EINVAL, "Invalid rwlock",
 	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
-#endif
 
 	for (owner = (uintptr_t)ptr->ptr_owner;; owner = next) {
 		/*
@@ -248,10 +246,8 @@ pthread_rwlock_tryrdlock(pthread_rwlock_
 	if (__predict_false(__uselibcstub))
 		return __libc_rwlock_tryrdlock_stub(ptr);
 
-#ifdef ERRORCHECK
 	pthread__error(EINVAL, "Invalid rwlock",
 	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
-#endif
 
 	/*
 	 * Don't get a readlock if there is a writer or if there are waiting
@@ -283,10 +279,8 @@ pthread__rwlock_wrlock(pthread_rwlock_t 
 	self = pthread__self();
 	_DIAGASSERT(((uintptr_t)self & RW_FLAGMASK) == 0);
 
-#ifdef ERRORCHECK
 	pthread__error(EINVAL, "Invalid rwlock",
 	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
-#endif
 
 	for (owner = (uintptr_t)ptr->ptr_owner;; owner = next) {
 		/*
@@ -374,10 +368,8 @@ pthread_rwlock_trywrlock(pthread_rwlock_
 	if (__predict_false(__uselibcstub))
 		return __libc_rwlock_trywrlock_stub(ptr);
 
-#ifdef ERRORCHECK
 	pthread__error(EINVAL, "Invalid rwlock",
 	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
-#endif
 
 	self = pthread__self();
 	_DIAGASSERT(((uintptr_t)self & RW_FLAGMASK) == 0);
@@ -453,10 +445,8 @@ pthread_rwlock_unlock(pthread_rwlock_t *
 	if (__predict_false(__uselibcstub))
 		return __libc_rwlock_unlock_stub(ptr);
 
-#ifdef ERRORCHECK
 	pthread__error(EINVAL, "Invalid rwlock",
 	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
-#endif
 
 #ifndef PTHREAD__ATOMIC_IS_MEMBAR
 	membar_exit();

Index: src/lib/libpthread/pthread_spin.c
diff -u src/lib/libpthread/pthread_spin.c:1.7 src/lib/libpthread/pthread_spin.c:1.8
--- src/lib/libpthread/pthread_spin.c:1.7	Fri Jan 31 17:52:14 2020
+++ src/lib/libpthread/pthread_spin.c	Wed Feb  5 11:05:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_spin.c,v 1.7 2020/01/31 17:52:14 kamil Exp $	*/
+/*	$NetBSD: pthread_spin.c,v 1.8 2020/02/05 11:05:10 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_spin.c,v 1.7 2020/01/31 17:52:14 kamil Exp $");
+__RCSID("$NetBSD: pthread_spin.c,v 1.8 2020/02/05 11:05:10 kamil Exp $");
 
 #include 
 #include 
@@ -53,11 +53,10 @@ int
 pthread_spin_init(pthread_spinlock_t *lock, int pshared)
 {
 
-#ifdef ERRORCHECK
 	pthread__error(EINVAL, "Invalid pshared",
 	pshared == PTHREAD_PROCESS_PRIVATE ||
 	pshared == PTHREAD_PROCESS_SHARED);
-#endif
+
 	lock->pts_magic = _PT_SPINLOCK_MAGIC;
 
 	/*
@@ -75,13 +74,11 @@ int
 pthread_spin_destroy(pthread_spinlock_t *lock)
 {
 
-#ifdef ERRORCHECK
 	pthread__error(EINVAL, "Invalid spinlock",
 	lock->pts_magic == _PT_SPINLOCK_MAGIC);
 
 	if (!__SIMPLELOCK_UNLOCKED_P(>pts_spin))
 		return EBUSY;
-#endif
 
 	lock->pts_magic = _PT_SPINLOCK_DEAD;
 
@@ -93,10 +90,8 @@ pthread_spin_lock(pthread_spinlock_t 

CVS commit: src/lib/libpthread

2020-02-01 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Feb  1 15:39:56 UTC 2020

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
Remove 'ifdef 0' hacks

It is no longer needed as the proper fix avoiding premature malloc()
landed the sources.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.72 src/lib/libpthread/pthread_mutex.c:1.73
--- src/lib/libpthread/pthread_mutex.c:1.72	Fri Jan 31 17:52:14 2020
+++ src/lib/libpthread/pthread_mutex.c	Sat Feb  1 15:39:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.72 2020/01/31 17:52:14 kamil Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.73 2020/02/01 15:39:56 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.72 2020/01/31 17:52:14 kamil Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.73 2020/02/01 15:39:56 kamil Exp $");
 
 #include 
 #include 
@@ -122,14 +122,12 @@ pthread_mutex_init(pthread_mutex_t *ptm,
 {
 	uintptr_t type, proto, val, ceil;
 
-#if 0
 	/*
 	 * Always initialize the mutex structure, maybe be used later
 	 * and the cost should be minimal.
 	 */
 	if (__predict_false(__uselibcstub))
 		return __libc_mutex_init_stub(ptm, attr);
-#endif
 
 	pthread__error(EINVAL, "Invalid mutes attribute",
 	attr == NULL || attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
@@ -619,10 +617,9 @@ pthread__mutex_wakeup(pthread_t self, pt
 int
 pthread_mutexattr_init(pthread_mutexattr_t *attr)
 {
-#if 0
+
 	if (__predict_false(__uselibcstub))
 		return __libc_mutexattr_init_stub(attr);
-#endif
 
 	attr->ptma_magic = _PT_MUTEXATTR_MAGIC;
 	attr->ptma_private = (void *)PTHREAD_MUTEX_DEFAULT;



CVS commit: src/lib/libpthread

2020-01-31 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Jan 31 17:52:15 UTC 2020

Modified Files:
src/lib/libpthread: pthread_mutex.c pthread_rwlock.c pthread_spin.c

Log Message:
Refactor libpthread checks for invalid arguments

Switch from manual functions to pthread__error().


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.37 -r1.38 src/lib/libpthread/pthread_rwlock.c
cvs rdiff -u -r1.6 -r1.7 src/lib/libpthread/pthread_spin.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.71 src/lib/libpthread/pthread_mutex.c:1.72
--- src/lib/libpthread/pthread_mutex.c:1.71	Fri Jan 31 02:37:46 2020
+++ src/lib/libpthread/pthread_mutex.c	Fri Jan 31 17:52:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.71 2020/01/31 02:37:46 christos Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.72 2020/01/31 17:52:14 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.71 2020/01/31 02:37:46 christos Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.72 2020/01/31 17:52:14 kamil Exp $");
 
 #include 
 #include 
@@ -131,6 +131,9 @@ pthread_mutex_init(pthread_mutex_t *ptm,
 		return __libc_mutex_init_stub(ptm, attr);
 #endif
 
+	pthread__error(EINVAL, "Invalid mutes attribute",
+	attr == NULL || attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
+
 	if (attr == NULL) {
 		type = PTHREAD_MUTEX_NORMAL;
 		proto = PTHREAD_PRIO_NONE;

Index: src/lib/libpthread/pthread_rwlock.c
diff -u src/lib/libpthread/pthread_rwlock.c:1.37 src/lib/libpthread/pthread_rwlock.c:1.38
--- src/lib/libpthread/pthread_rwlock.c:1.37	Mon Jan 13 18:22:56 2020
+++ src/lib/libpthread/pthread_rwlock.c	Fri Jan 31 17:52:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_rwlock.c,v 1.37 2020/01/13 18:22:56 ad Exp $ */
+/*	$NetBSD: pthread_rwlock.c,v 1.38 2020/01/31 17:52:14 kamil Exp $ */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_rwlock.c,v 1.37 2020/01/13 18:22:56 ad Exp $");
+__RCSID("$NetBSD: pthread_rwlock.c,v 1.38 2020/01/31 17:52:14 kamil Exp $");
 
 #include 
 #include 
@@ -91,8 +91,9 @@ pthread_rwlock_init(pthread_rwlock_t *pt
 	if (__predict_false(__uselibcstub))
 		return __libc_rwlock_init_stub(ptr, attr);
 
-	if (attr && (attr->ptra_magic != _PT_RWLOCKATTR_MAGIC))
-		return EINVAL;
+	pthread__error(EINVAL, "Invalid rwlock attribute",
+	attr == NULL || attr->ptra_magic == _PT_RWLOCKATTR_MAGIC);
+
 	ptr->ptr_magic = _PT_RWLOCK_MAGIC;
 	PTQ_INIT(>ptr_rblocked);
 	PTQ_INIT(>ptr_wblocked);
@@ -109,8 +110,10 @@ pthread_rwlock_destroy(pthread_rwlock_t 
 	if (__predict_false(__uselibcstub))
 		return __libc_rwlock_destroy_stub(ptr);
 
-	if ((ptr->ptr_magic != _PT_RWLOCK_MAGIC) ||
-	(!PTQ_EMPTY(>ptr_rblocked)) ||
+	pthread__error(EINVAL, "Invalid rwlock",
+	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
+
+	if ((!PTQ_EMPTY(>ptr_rblocked)) ||
 	(!PTQ_EMPTY(>ptr_wblocked)) ||
 	(ptr->ptr_nreaders != 0) ||
 	(ptr->ptr_owner != NULL))
@@ -156,8 +159,8 @@ pthread__rwlock_rdlock(pthread_rwlock_t 
 	int error;
 
 #ifdef ERRORCHECK
-	if (ptr->ptr_magic != _PT_RWLOCK_MAGIC)
-		return EINVAL;
+	pthread__error(EINVAL, "Invalid rwlock",
+	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
 #endif
 
 	for (owner = (uintptr_t)ptr->ptr_owner;; owner = next) {
@@ -246,8 +249,8 @@ pthread_rwlock_tryrdlock(pthread_rwlock_
 		return __libc_rwlock_tryrdlock_stub(ptr);
 
 #ifdef ERRORCHECK
-	if (ptr->ptr_magic != _PT_RWLOCK_MAGIC)
-		return EINVAL;
+	pthread__error(EINVAL, "Invalid rwlock",
+	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
 #endif
 
 	/*
@@ -281,8 +284,8 @@ pthread__rwlock_wrlock(pthread_rwlock_t 
 	_DIAGASSERT(((uintptr_t)self & RW_FLAGMASK) == 0);
 
 #ifdef ERRORCHECK
-	if (ptr->ptr_magic != _PT_RWLOCK_MAGIC)
-		return EINVAL;
+	pthread__error(EINVAL, "Invalid rwlock",
+	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
 #endif
 
 	for (owner = (uintptr_t)ptr->ptr_owner;; owner = next) {
@@ -372,8 +375,8 @@ pthread_rwlock_trywrlock(pthread_rwlock_
 		return __libc_rwlock_trywrlock_stub(ptr);
 
 #ifdef ERRORCHECK
-	if (ptr->ptr_magic != _PT_RWLOCK_MAGIC)
-		return EINVAL;
+	pthread__error(EINVAL, "Invalid rwlock",
+	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
 #endif
 
 	self = pthread__self();
@@ -451,8 +454,8 @@ pthread_rwlock_unlock(pthread_rwlock_t *
 		return __libc_rwlock_unlock_stub(ptr);
 
 #ifdef ERRORCHECK
-	if ((ptr == NULL) || (ptr->ptr_magic != _PT_RWLOCK_MAGIC))
-		return EINVAL;
+	pthread__error(EINVAL, "Invalid rwlock",
+	ptr->ptr_magic == _PT_RWLOCK_MAGIC);
 #endif
 
 #ifndef PTHREAD__ATOMIC_IS_MEMBAR
@@ -650,6 +653,10 @@ int
 pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * __restrict attr,
 int * 

CVS commit: src/lib/libpthread

2020-01-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 31 02:37:47 UTC 2020

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
In the same spirit as the previous pthread_mutex_init change for jemalloc,
make pthread_mutexattr_init do always a full initialization, so that the
attribute that will be used later when we become threaded is properly
initialized.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.70 src/lib/libpthread/pthread_mutex.c:1.71
--- src/lib/libpthread/pthread_mutex.c:1.70	Wed Jan 29 16:11:24 2020
+++ src/lib/libpthread/pthread_mutex.c	Thu Jan 30 21:37:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.70 2020/01/29 21:11:24 kamil Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.71 2020/01/31 02:37:46 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.70 2020/01/29 21:11:24 kamil Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.71 2020/01/31 02:37:46 christos Exp $");
 
 #include 
 #include 
@@ -616,8 +616,10 @@ pthread__mutex_wakeup(pthread_t self, pt
 int
 pthread_mutexattr_init(pthread_mutexattr_t *attr)
 {
+#if 0
 	if (__predict_false(__uselibcstub))
 		return __libc_mutexattr_init_stub(attr);
+#endif
 
 	attr->ptma_magic = _PT_MUTEXATTR_MAGIC;
 	attr->ptma_private = (void *)PTHREAD_MUTEX_DEFAULT;



CVS commit: src/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 21:11:25 UTC 2020

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
Use pthread_mutexattr_t and pthread_mutex_t magic fields

Validate _PT_MUTEX_MAGIC in pthread_mutex_t and _PT_MUTEXATTR_MAGIC
in pthread_mutexattr_t accordingly.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.69 src/lib/libpthread/pthread_mutex.c:1.70
--- src/lib/libpthread/pthread_mutex.c:1.69	Wed Jan 29 10:55:23 2020
+++ src/lib/libpthread/pthread_mutex.c	Wed Jan 29 21:11:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.69 2020/01/29 10:55:23 kamil Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.70 2020/01/29 21:11:24 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.69 2020/01/29 10:55:23 kamil Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.70 2020/01/29 21:11:24 kamil Exp $");
 
 #include 
 #include 
@@ -197,6 +197,9 @@ pthread_mutex_lock(pthread_mutex_t *ptm)
 	if (__predict_false(__uselibcstub))
 		return __libc_mutex_lock_stub(ptm);
 
+	pthread__error(EINVAL, "Invalid mutex",
+	ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
 	self = pthread__self();
 	val = atomic_cas_ptr(>ptm_owner, NULL, self);
 	if (__predict_true(val == NULL)) {
@@ -214,6 +217,9 @@ pthread_mutex_timedlock(pthread_mutex_t*
 	pthread_t self;
 	void *val;
 
+	pthread__error(EINVAL, "Invalid mutex",
+	ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
 	self = pthread__self();
 	val = atomic_cas_ptr(>ptm_owner, NULL, self);
 	if (__predict_true(val == NULL)) {
@@ -298,9 +304,6 @@ pthread__mutex_lock_slow(pthread_mutex_t
 	int serrno;
 	int error;
 
-	pthread__error(EINVAL, "Invalid mutex",
-	ptm->ptm_magic == _PT_MUTEX_MAGIC);
-
 	owner = ptm->ptm_owner;
 	self = pthread__self();
 
@@ -410,6 +413,9 @@ pthread_mutex_trylock(pthread_mutex_t *p
 	if (__predict_false(__uselibcstub))
 		return __libc_mutex_trylock_stub(ptm);
 
+	pthread__error(EINVAL, "Invalid mutex",
+	ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
 	self = pthread__self();
 	val = atomic_cas_ptr(>ptm_owner, NULL, self);
 	if (__predict_true(val == NULL)) {
@@ -450,6 +456,9 @@ pthread_mutex_unlock(pthread_mutex_t *pt
 	if (__predict_false(__uselibcstub))
 		return __libc_mutex_unlock_stub(ptm);
 
+	pthread__error(EINVAL, "Invalid mutex",
+	ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
 #ifndef PTHREAD__ATOMIC_IS_MEMBAR
 	membar_exit();
 #endif
@@ -468,9 +477,6 @@ pthread__mutex_unlock_slow(pthread_mutex
 	pthread_t self, owner, new;
 	int weown, error;
 
-	pthread__error(EINVAL, "Invalid mutex",
-	ptm->ptm_magic == _PT_MUTEX_MAGIC);
-
 	self = pthread__self();
 	owner = ptm->ptm_owner;
 	weown = (MUTEX_OWNER(owner) == (uintptr_t)self);
@@ -725,6 +731,9 @@ pthread_mutexattr_getpshared(const pthre
 int * __restrict pshared)
 {
 
+	pthread__error(EINVAL, "Invalid mutex attribute",
+		attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
+
 	*pshared = PTHREAD_PROCESS_PRIVATE;
 	return 0;
 }
@@ -733,6 +742,9 @@ int
 pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
 {
 
+	pthread__error(EINVAL, "Invalid mutex attribute",
+		attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
+
 	switch(pshared) {
 	case PTHREAD_PROCESS_PRIVATE:
 		return 0;
@@ -772,6 +784,10 @@ pthread__mutex_deferwake(pthread_t self,
 int
 pthread_mutex_getprioceiling(const pthread_mutex_t *ptm, int *ceil) 
 {
+
+	pthread__error(EINVAL, "Invalid mutex",
+	ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
 	*ceil = ptm->ptm_ceiling;
 	return 0;
 }
@@ -781,6 +797,9 @@ pthread_mutex_setprioceiling(pthread_mut
 {
 	int error;
 
+	pthread__error(EINVAL, "Invalid mutex",
+	ptm->ptm_magic == _PT_MUTEX_MAGIC);
+
 	error = pthread_mutex_lock(ptm);
 	if (error == 0) {
 		*old_ceil = ptm->ptm_ceiling;



CVS commit: src/lib/libpthread

2020-01-29 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed Jan 29 17:11:57 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
- pthread_join(): remove temporary hack now kernel returns correct errno.

- kill(getpid(), SIGABRT)  ->  _lwp_kill(_lwp_self(), SIGABRT)


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.161 src/lib/libpthread/pthread.c:1.162
--- src/lib/libpthread/pthread.c:1.161	Wed Jan 29 16:03:44 2020
+++ src/lib/libpthread/pthread.c	Wed Jan 29 17:11:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.161 2020/01/29 16:03:44 kamil Exp $	*/
+/*	$NetBSD: pthread.c,v 1.162 2020/01/29 17:11:57 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.161 2020/01/29 16:03:44 kamil Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.162 2020/01/29 17:11:57 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -719,10 +719,6 @@ pthread_join(pthread_t thread, void **va
 	if (thread == self)
 		return EDEADLK;
 
-	/* XXX temporary - kernel should handle. */
-	if ((thread->pt_flags & PT_FLAG_DETACHED) != 0)
-		return EINVAL;
-
 	/* IEEE Std 1003.1 says pthread_join() never returns EINTR. */
 	for (;;) {
 		pthread__testcancel(self);
@@ -1101,8 +1097,7 @@ pthread__assertfunc(const char *file, in
 	function ? "\"" : "");
 
 	_sys_write(STDERR_FILENO, buf, (size_t)len);
-	(void)kill(getpid(), SIGABRT);
-
+	(void)_lwp_kill(_lwp_self(), SIGABRT);
 	_exit(1);
 }
 
@@ -1137,7 +1132,7 @@ pthread__errorfunc(const char *file, int
 		syslog(LOG_DEBUG | LOG_USER, "%s", buf);
 
 	if (pthread__diagassert & DIAGASSERT_ABORT) {
-		(void)kill(getpid(), SIGABRT);
+		(void)_lwp_kill(_lwp_self(), SIGABRT);
 		_exit(1);
 	}
 }



CVS commit: src/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 16:34:09 UTC 2020

Modified Files:
src/lib/libpthread: pthread_misc.c

Log Message:
Check thread->pt_magic with PT_MAGIC promptly


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libpthread/pthread_misc.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/pthread_misc.c
diff -u src/lib/libpthread/pthread_misc.c:1.16 src/lib/libpthread/pthread_misc.c:1.17
--- src/lib/libpthread/pthread_misc.c:1.16	Mon Jan 13 18:22:56 2020
+++ src/lib/libpthread/pthread_misc.c	Wed Jan 29 16:34:09 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_misc.c,v 1.16 2020/01/13 18:22:56 ad Exp $	*/
+/*	$NetBSD: pthread_misc.c,v 1.17 2020/01/29 16:34:09 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_misc.c,v 1.16 2020/01/13 18:22:56 ad Exp $");
+__RCSID("$NetBSD: pthread_misc.c,v 1.17 2020/01/29 16:34:09 kamil Exp $");
 
 #include 
 #include 
@@ -61,6 +61,9 @@ int
 pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param)
 {
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 
@@ -76,6 +79,9 @@ pthread_setschedparam(pthread_t thread, 
 {
 	struct sched_param sp;
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 
@@ -90,6 +96,9 @@ int
 pthread_getaffinity_np(pthread_t thread, size_t size, cpuset_t *cpuset)
 {
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 
@@ -103,6 +112,9 @@ int
 pthread_setaffinity_np(pthread_t thread, size_t size, cpuset_t *cpuset)
 {
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 
@@ -117,6 +129,9 @@ pthread_setschedprio(pthread_t thread, i
 {
 	struct sched_param sp;
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 
@@ -131,6 +146,9 @@ int
 pthread_kill(pthread_t thread, int sig)
 {
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if ((sig < 0) || (sig >= _NSIG))
 		return EINVAL;
 	if (pthread__find(thread) != 0)



CVS commit: src/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 16:03:44 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_getcpuclockid.c

Log Message:
Chack thread->pt_magic with PT_MAGIC promptly

Rearrange some checks to avoid verifying pthread_t after using it.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libpthread/pthread_getcpuclockid.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.160 src/lib/libpthread/pthread.c:1.161
--- src/lib/libpthread/pthread.c:1.160	Wed Jan 29 15:31:14 2020
+++ src/lib/libpthread/pthread.c	Wed Jan 29 16:03:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.160 2020/01/29 15:31:14 kamil Exp $	*/
+/*	$NetBSD: pthread.c,v 1.161 2020/01/29 16:03:44 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.160 2020/01/29 15:31:14 kamil Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.161 2020/01/29 16:03:44 kamil Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -597,6 +597,9 @@ pthread_suspend_np(pthread_t thread)
 {
 	pthread_t self;
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	self = pthread__self();
 	if (self == thread) {
 		return EDEADLK;
@@ -611,6 +614,9 @@ pthread_suspend_np(pthread_t thread)
 int
 pthread_resume_np(pthread_t thread)
 {
+
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
  
 	if (pthread__find(thread) != 0)
 		return ESRCH;
@@ -702,14 +708,14 @@ pthread_join(pthread_t thread, void **va
 {
 	pthread_t self;
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	self = pthread__self();
 
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 
-	if (thread->pt_magic != PT_MAGIC)
-		return EINVAL;
-
 	if (thread == self)
 		return EDEADLK;
 
@@ -764,9 +770,16 @@ pthread__reap(pthread_t thread)
 int
 pthread_equal(pthread_t t1, pthread_t t2)
 {
+
 	if (__predict_false(__uselibcstub))
 		return __libc_thr_equal_stub(t1, t2);
 
+	pthread__error(EINVAL, "Invalid thread",
+	t1->pt_magic == PT_MAGIC);
+
+	pthread__error(EINVAL, "Invalid thread",
+	t2->pt_magic == PT_MAGIC);
+
 	/* Nothing special here. */
 	return (t1 == t2);
 }
@@ -777,12 +790,12 @@ pthread_detach(pthread_t thread)
 {
 	int error;
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 
-	if (thread->pt_magic != PT_MAGIC)
-		return EINVAL;
-
 	pthread_mutex_lock(>pt_lock);
 	if ((thread->pt_flags & PT_FLAG_DETACHED) != 0) {
 		error = EINVAL;
@@ -806,12 +819,12 @@ int
 pthread_getname_np(pthread_t thread, char *name, size_t len)
 {
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 
-	if (thread->pt_magic != PT_MAGIC)
-		return EINVAL;
-
 	pthread_mutex_lock(>pt_lock);
 	if (thread->pt_name == NULL)
 		name[0] = '\0';
@@ -829,12 +842,12 @@ pthread_setname_np(pthread_t thread, con
 	char *oldname, *cp, newname[PTHREAD_MAX_NAMELEN_NP];
 	int namelen;
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 
-	if (thread->pt_magic != PT_MAGIC)
-		return EINVAL;
-
 	namelen = snprintf(newname, sizeof(newname), name, arg);
 	if (namelen >= PTHREAD_MAX_NAMELEN_NP)
 		return EINVAL;
@@ -870,6 +883,9 @@ int
 pthread_cancel(pthread_t thread)
 {
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	if (pthread__find(thread) != 0)
 		return ESRCH;
 	pthread_mutex_lock(>pt_lock);

Index: src/lib/libpthread/pthread_getcpuclockid.c
diff -u src/lib/libpthread/pthread_getcpuclockid.c:1.2 src/lib/libpthread/pthread_getcpuclockid.c:1.3
--- src/lib/libpthread/pthread_getcpuclockid.c:1.2	Sat Mar  4 11:16:33 2017
+++ src/lib/libpthread/pthread_getcpuclockid.c	Wed Jan 29 16:03:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $	*/
+/*	$NetBSD: pthread_getcpuclockid.c,v 1.3 2020/01/29 16:03:44 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: pthread_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $");
+__RCSID("$NetBSD: pthread_getcpuclockid.c,v 1.3 2020/01/29 16:03:44 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include 
@@ -45,6 +45,9 @@ pthread_getcpuclockid(pthread_t thread, 
 {
 	int error = 0, saved_errno;
 
+	pthread__error(EINVAL, "Invalid thread",
+	thread->pt_magic == PT_MAGIC);
+
 	saved_errno = errno;
 	if (clock_getcpuclockid2(P_LWPID, (id_t)thread->pt_lid, clock_id) == -1)
 		error = errno;



CVS commit: src/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 15:31:14 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Revert previous

Two assignments are correct.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.159 src/lib/libpthread/pthread.c:1.160
--- src/lib/libpthread/pthread.c:1.159	Wed Jan 29 15:15:00 2020
+++ src/lib/libpthread/pthread.c	Wed Jan 29 15:31:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.159 2020/01/29 15:15:00 kamil Exp $	*/
+/*	$NetBSD: pthread.c,v 1.160 2020/01/29 15:31:14 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.159 2020/01/29 15:15:00 kamil Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.160 2020/01/29 15:31:14 kamil Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -362,9 +362,8 @@ pthread__getstack(pthread_t newthread, c
 		newthread->pt_stack.ss_size == stacksize &&
 		newthread->pt_guardsize == guardsize)
 			return 0;
-#ifdef __MACHINE_STACK_GROWS_UP
 		stackbase2 = newthread->pt_stack.ss_sp;
-#else
+#ifndef __MACHINE_STACK_GROWS_UP
 		stackbase2 = (char *)stackbase2 - newthread->pt_guardsize;
 #endif
 		munmap(stackbase2,



CVS commit: src/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 15:15:00 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Do not set stackbase2 twice for !__MACHINE_STACK_GROWS_UP


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.158 src/lib/libpthread/pthread.c:1.159
--- src/lib/libpthread/pthread.c:1.158	Tue Jan 28 09:23:15 2020
+++ src/lib/libpthread/pthread.c	Wed Jan 29 15:15:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.158 2020/01/28 09:23:15 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.159 2020/01/29 15:15:00 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.158 2020/01/28 09:23:15 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.159 2020/01/29 15:15:00 kamil Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -362,8 +362,9 @@ pthread__getstack(pthread_t newthread, c
 		newthread->pt_stack.ss_size == stacksize &&
 		newthread->pt_guardsize == guardsize)
 			return 0;
+#ifdef __MACHINE_STACK_GROWS_UP
 		stackbase2 = newthread->pt_stack.ss_sp;
-#ifndef __MACHINE_STACK_GROWS_UP
+#else
 		stackbase2 = (char *)stackbase2 - newthread->pt_guardsize;
 #endif
 		munmap(stackbase2,



CVS commit: src/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 15:07:46 UTC 2020

Modified Files:
src/lib/libpthread: pthread_cond.c

Log Message:
Use pthread_condattr_t and pthread_cond_t magic fields

Validate _PT_CONDATTR_MAGIC and _PT_COND_MAGIC respectively.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/lib/libpthread/pthread_cond.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/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.66 src/lib/libpthread/pthread_cond.c:1.67
--- src/lib/libpthread/pthread_cond.c:1.66	Mon Jan 13 18:22:56 2020
+++ src/lib/libpthread/pthread_cond.c	Wed Jan 29 15:07:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.66 2020/01/13 18:22:56 ad Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.66 2020/01/13 18:22:56 ad Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $");
 
 #include 
 #include 
@@ -78,6 +78,10 @@ __strong_alias(__libc_cond_destroy,pthre
 static clockid_t
 pthread_cond_getclock(const pthread_cond_t *cond)
 {
+
+	pthread__error(EINVAL, "Invalid condition variable",
+	cond->ptc_magic == _PT_COND_MAGIC);
+
 	return cond->ptc_private ? 
 	*(clockid_t *)cond->ptc_private : CLOCK_REALTIME;
 }
@@ -222,9 +226,6 @@ pthread__cond_wake_one(pthread_cond_t *c
 	pthread_mutex_t *mutex;
 	lwpid_t lid;
 
-	pthread__error(EINVAL, "Invalid condition variable",
-	cond->ptc_magic == _PT_COND_MAGIC);
-
 	/*
 	 * Pull the first thread off the queue.  If the current thread
 	 * is associated with the condition variable, remove it without
@@ -278,6 +279,9 @@ pthread_cond_signal(pthread_cond_t *cond
 	if (__predict_false(__uselibcstub))
 		return __libc_cond_signal_stub(cond);
 
+	pthread__error(EINVAL, "Invalid condition variable",
+	cond->ptc_magic == _PT_COND_MAGIC);
+
 	if (__predict_true(PTQ_EMPTY(>ptc_waiters)))
 		return 0;
 	return pthread__cond_wake_one(cond);
@@ -291,9 +295,6 @@ pthread__cond_wake_all(pthread_cond_t *c
 	u_int max;
 	size_t nwaiters;
 
-	pthread__error(EINVAL, "Invalid condition variable",
-	cond->ptc_magic == _PT_COND_MAGIC);
-
 	/*
 	 * Try to defer waking threads (see pthread_cond_signal()).
 	 * Only transfer waiters for which there is no pending wakeup.
@@ -328,6 +329,9 @@ pthread_cond_broadcast(pthread_cond_t *c
 	if (__predict_false(__uselibcstub))
 		return __libc_cond_broadcast_stub(cond);
 
+	pthread__error(EINVAL, "Invalid condition variable",
+	cond->ptc_magic == _PT_COND_MAGIC);
+
 	if (__predict_true(PTQ_EMPTY(>ptc_waiters)))
 		return 0;
 	return pthread__cond_wake_all(cond);
@@ -353,6 +357,10 @@ pthread_condattr_init(pthread_condattr_t
 int
 pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clck)
 {
+
+	pthread__error(EINVAL, "Invalid condition variable attribute",
+	attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
 	switch (clck) {
 	case CLOCK_MONOTONIC:
 	case CLOCK_REALTIME:
@@ -371,6 +379,10 @@ int
 pthread_condattr_getclock(const pthread_condattr_t *__restrict attr,
 clockid_t *__restrict clock_id)
 {
+
+	pthread__error(EINVAL, "Invalid condition variable attribute",
+	attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
 	if (attr == NULL || attr->ptca_private == NULL)
 		return EINVAL;
 	*clock_id = *(clockid_t *)attr->ptca_private;
@@ -396,6 +408,9 @@ pthread_condattr_getpshared(const pthrea
 int * __restrict pshared)
 {
 
+	pthread__error(EINVAL, "Invalid condition variable attribute",
+	attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
 	*pshared = PTHREAD_PROCESS_PRIVATE;
 	return 0;
 }
@@ -404,6 +419,9 @@ int
 pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
 {
 
+	pthread__error(EINVAL, "Invalid condition variable attribute",
+	attr->ptca_magic == _PT_CONDATTR_MAGIC);
+
 	switch(pshared) {
 	case PTHREAD_PROCESS_PRIVATE:
 		return 0;



CVS commit: src/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 14:41:57 UTC 2020

Modified Files:
src/lib/libpthread: pthread_barrier.c

Log Message:
Use pthread_barrierattr_t and pthread_barrier_t magic fields

Set respectively _PT_BARRIER_DEAD for pthread_barrier_destroy() and
_PT_BARRIERATTR_DEAD for pthread_barrierattr_destroy().

Validate _PT_BARRIER_MAGIC in pthread_barrier_t and _PT_BARRIERATTR_MAGIC
in pthread_barrierattr_t accordingly.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libpthread/pthread_barrier.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/pthread_barrier.c
diff -u src/lib/libpthread/pthread_barrier.c:1.20 src/lib/libpthread/pthread_barrier.c:1.21
--- src/lib/libpthread/pthread_barrier.c:1.20	Sun Jul  3 14:24:58 2016
+++ src/lib/libpthread/pthread_barrier.c	Wed Jan 29 14:41:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_barrier.c,v 1.20 2016/07/03 14:24:58 christos Exp $	*/
+/*	$NetBSD: pthread_barrier.c,v 1.21 2020/01/29 14:41:57 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_barrier.c,v 1.20 2016/07/03 14:24:58 christos Exp $");
+__RCSID("$NetBSD: pthread_barrier.c,v 1.21 2020/01/29 14:41:57 kamil Exp $");
 
 #include 
 
@@ -41,9 +41,9 @@ int
 pthread_barrier_init(pthread_barrier_t *barrier,
 		 const pthread_barrierattr_t *attr, unsigned int count)
 {
-	
-	if (attr != NULL && attr->ptba_magic != _PT_BARRIERATTR_MAGIC)
-		return EINVAL;
+
+	pthread__error(EINVAL, "Invalid barrier attribute",
+	attr == NULL || attr->ptba_magic == _PT_BARRIERATTR_MAGIC);
 	if (count == 0)
 		return EINVAL;
 
@@ -59,10 +59,13 @@ int
 pthread_barrier_destroy(pthread_barrier_t *barrier)
 {
 
-	if (barrier->ptb_magic != _PT_BARRIER_MAGIC)
-		return EINVAL;
+	pthread__error(EINVAL, "Invalid barrier",
+	barrier->ptb_magic == _PT_BARRIER_MAGIC);
 	if (barrier->ptb_curcount != 0)
 		return EBUSY;
+
+	barrier->ptb_magic = _PT_BARRIER_DEAD;
+
 	return 0;
 }
 
@@ -73,8 +76,8 @@ pthread_barrier_wait(pthread_barrier_t *
 	pthread_t self;
 	unsigned int gen;
 
-	if (barrier->ptb_magic != _PT_BARRIER_MAGIC)
-		return EINVAL;
+	pthread__error(EINVAL, "Invalid barrier",
+	barrier->ptb_magic == _PT_BARRIER_MAGIC);
 
 	/*
 	 * A single arbitrary thread is supposed to return
@@ -123,6 +126,9 @@ pthread_barrierattr_getpshared(const pth
 int * __restrict pshared)
 {
 
+	pthread__error(EINVAL, "Invalid barrier attribute",
+	attr->ptba_magic == _PT_BARRIERATTR_MAGIC);
+
 	*pshared = PTHREAD_PROCESS_PRIVATE;
 	return 0;
 }
@@ -131,6 +137,9 @@ int
 pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared)
 {
 
+	pthread__error(EINVAL, "Invalid barrier attribute",
+	attr->ptba_magic == _PT_BARRIERATTR_MAGIC);
+
 	switch(pshared) {
 	case PTHREAD_PROCESS_PRIVATE:
 		return 0;
@@ -153,8 +162,8 @@ int
 pthread_barrierattr_destroy(pthread_barrierattr_t *attr)
 {
 
-	if (attr->ptba_magic != _PT_BARRIERATTR_MAGIC)
-		return EINVAL;
+	pthread__error(EINVAL, "Invalid barrier attribute",
+	attr->ptba_magic == _PT_BARRIERATTR_MAGIC);
 	attr->ptba_magic = _PT_BARRIERATTR_DEAD;
 	return 0;
 }



CVS commit: src/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 13:47:31 UTC 2020

Modified Files:
src/lib/libpthread: pthread_attr.c

Log Message:
Use the pta_magic field in pthread attribute

Set PT_ATTR_DEAD on pthread_attr_destroy().
Check pta_magic before using pthread_attr_t in a bunch of other functions.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libpthread/pthread_attr.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/pthread_attr.c
diff -u src/lib/libpthread/pthread_attr.c:1.18 src/lib/libpthread/pthread_attr.c:1.19
--- src/lib/libpthread/pthread_attr.c:1.18	Tue Aug  1 12:31:45 2017
+++ src/lib/libpthread/pthread_attr.c	Wed Jan 29 13:47:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_attr.c,v 1.18 2017/08/01 12:31:45 martin Exp $	*/
+/*	$NetBSD: pthread_attr.c,v 1.19 2020/01/29 13:47:31 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_attr.c,v 1.18 2017/08/01 12:31:45 martin Exp $");
+__RCSID("$NetBSD: pthread_attr.c,v 1.19 2020/01/29 13:47:31 kamil Exp $");
 
 #include 
 #include 
@@ -86,9 +86,14 @@ pthread_attr_destroy(pthread_attr_t *att
 {
 	struct pthread_attr_private *p;
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	if ((p = attr->pta_private) != NULL)
 		free(p);
 
+	attr->pta_magic = PT_ATTR_DEAD;
+
 	return 0;
 }
 
@@ -98,6 +103,9 @@ pthread_attr_get_np(pthread_t thread, pt
 {
 	struct pthread_attr_private *p;
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	p = pthread__attr_init_private(attr);
 	if (p == NULL)
 		return ENOMEM;
@@ -117,6 +125,9 @@ int
 pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
 {
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	if (attr->pta_flags & PT_FLAG_DETACHED)
 		*detachstate = PTHREAD_CREATE_DETACHED;
 	else
@@ -130,6 +141,9 @@ int
 pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
 {
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	switch (detachstate) {
 	case PTHREAD_CREATE_JOINABLE:
 		attr->pta_flags &= ~PT_FLAG_DETACHED;
@@ -150,6 +164,9 @@ pthread_attr_getguardsize(const pthread_
 {
 	struct pthread_attr_private *p;
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	if ((p = attr->pta_private) == NULL)
 		*guard = pthread__guardsize;
 	else
@@ -164,6 +181,9 @@ pthread_attr_setguardsize(pthread_attr_t
 {
 	struct pthread_attr_private *p;
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	p = pthread__attr_init_private(attr);
 	if (p == NULL)
 		return ENOMEM;
@@ -178,6 +198,9 @@ int
 pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit)
 {
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	if (attr->pta_flags & PT_FLAG_EXPLICIT_SCHED)
 		*inherit = PTHREAD_EXPLICIT_SCHED;
 	else
@@ -191,6 +214,9 @@ int
 pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit)
 {
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	switch (inherit) {
 	case PTHREAD_INHERIT_SCHED:
 		attr->pta_flags &= ~PT_FLAG_EXPLICIT_SCHED;
@@ -210,6 +236,9 @@ int
 pthread_attr_getscope(const pthread_attr_t *attr, int *scope)
 {
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	if (attr->pta_flags & PT_FLAG_SCOPE_SYSTEM)
 		*scope = PTHREAD_SCOPE_SYSTEM;
 	else
@@ -223,6 +252,9 @@ int
 pthread_attr_setscope(pthread_attr_t *attr, int scope)
 {
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	switch (scope) {
 	case PTHREAD_SCOPE_PROCESS:
 		attr->pta_flags &= ~PT_FLAG_SCOPE_SYSTEM;
@@ -245,6 +277,9 @@ pthread_attr_setschedparam(pthread_attr_
 	struct pthread_attr_private *p;
 	int error;
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	if (param == NULL)
 		return EINVAL;
 	p = pthread__attr_init_private(attr);
@@ -263,6 +298,9 @@ pthread_attr_getschedparam(const pthread
 {
 	struct pthread_attr_private *p;
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	if (param == NULL)
 		return EINVAL;
 	p = attr->pta_private;
@@ -279,6 +317,8 @@ pthread_attr_setschedpolicy(pthread_attr
 {
 	struct pthread_attr_private *p;
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
 
 	switch (policy) {
 	case SCHED_OTHER:
@@ -300,6 +340,9 @@ pthread_attr_getschedpolicy(const pthrea
 {
 	struct pthread_attr_private *p;
 
+	pthread__error(EINVAL, "Invalid attribute",
+	attr->pta_magic == PT_ATTR_MAGIC);
+
 	p = attr->pta_private;
 	if (p 

CVS commit: src/lib/libpthread

2020-01-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Jan 29 10:55:23 UTC 2020

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
Mark destroyed pthread_mutexattr_t as dead


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.68 src/lib/libpthread/pthread_mutex.c:1.69
--- src/lib/libpthread/pthread_mutex.c:1.68	Sat Jan 25 18:30:41 2020
+++ src/lib/libpthread/pthread_mutex.c	Wed Jan 29 10:55:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.68 2020/01/25 18:30:41 ad Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.69 2020/01/29 10:55:23 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.68 2020/01/25 18:30:41 ad Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.69 2020/01/29 10:55:23 kamil Exp $");
 
 #include 
 #include 
@@ -627,6 +627,8 @@ pthread_mutexattr_destroy(pthread_mutexa
 	pthread__error(EINVAL, "Invalid mutex attribute",
 	attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
 
+	attr->ptma_magic = _PT_MUTEXATTR_DEAD;
+
 	return 0;
 }
 



CVS commit: src/lib/libpthread

2020-01-28 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue Jan 28 13:08:40 UTC 2020

Modified Files:
src/lib/libpthread: pthread_int.h

Log Message:
- A bit more alignment in __pthread_st especially for the rbtree node.
- Use COHERENCY_UNIT from sys/param.h.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/lib/libpthread/pthread_int.h

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/pthread_int.h
diff -u src/lib/libpthread/pthread_int.h:1.99 src/lib/libpthread/pthread_int.h:1.100
--- src/lib/libpthread/pthread_int.h:1.99	Mon Jan 27 20:50:05 2020
+++ src/lib/libpthread/pthread_int.h	Tue Jan 28 13:08:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_int.h,v 1.99 2020/01/27 20:50:05 ad Exp $	*/
+/*	$NetBSD: pthread_int.h,v 1.100 2020/01/28 13:08:40 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -47,6 +47,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -96,7 +97,6 @@ struct	__pthread_st {
 #endif
 	unsigned int	pt_magic;	/* Magic number */
 	int		pt_state;	/* running, blocked, etc. */
-	pthread_mutex_t	pt_lock;	/* lock on state */
 	int		pt_flags;	/* see PT_FLAG_* below */
 	int		pt_cancel;	/* Deferred cancellation */
 	int		pt_errno;	/* Thread-specific errno. */
@@ -120,15 +120,25 @@ struct	__pthread_st {
 
 	/* LWP ID and entry on the list of all threads. */
 	lwpid_t		pt_lid;
-	rb_node_t	pt_alltree;
-	PTQ_ENTRY(__pthread_st) pt_allq;
 	PTQ_ENTRY(__pthread_st)	pt_deadq;
 
 	/*
+	 * rbtree node and entry on the list of all threads.  pt_alltree in
+	 * its own cacheline, so pthread__find() is not needlessly impacted
+	 * by threads going about their normal business.  pt_allq is
+	 * adjusted at the same time as pt_alltree.
+	 */
+	rb_node_t	pt_alltree __aligned(COHERENCY_UNIT);
+	PTQ_ENTRY(__pthread_st) pt_allq;
+
+	/* Lock on state also gets its own line. */
+	pthread_mutex_t	pt_lock __aligned(COHERENCY_UNIT);
+
+	/*
 	 * General synchronization data.  We try to align, as threads
 	 * on other CPUs will access this data frequently.
 	 */
-	int		pt_dummy1 __aligned(128);
+	int		pt_dummy1 __aligned(COHERENCY_UNIT);
 	struct lwpctl 	*pt_lwpctl;	/* Kernel/user comms area */
 	volatile int	pt_rwlocked;	/* Handed rwlock successfully */
 	volatile int	pt_signalled;	/* Received pthread_cond_signal() */
@@ -137,10 +147,9 @@ struct	__pthread_st {
 	void * volatile	pt_sleepobj;	/* Object slept on */
 	PTQ_ENTRY(__pthread_st) pt_sleep;
 	void		(*pt_early)(void *);
-	int		pt_dummy2 __aligned(128);
 
 	/* Thread-specific data.  Large so it sits close to the end. */
-	int		pt_havespecific;
+	int		pt_havespecific __aligned(COHERENCY_UNIT);
 	struct pt_specific {
 		void *pts_value;
 		PTQ_ENTRY(pt_specific) pts_next;



CVS commit: src/lib/libpthread

2020-01-28 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Tue Jan 28 09:23:15 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
pthread_join(): add a temporary hack to make lib/libpthread/t_detach pass.
The correct fix is to do this in kernel (I have that change, but it's part
of the wider change to index LWPs in a tree).


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.157 src/lib/libpthread/pthread.c:1.158
--- src/lib/libpthread/pthread.c:1.157	Mon Jan 27 20:50:05 2020
+++ src/lib/libpthread/pthread.c	Tue Jan 28 09:23:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.157 2020/01/27 20:50:05 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.158 2020/01/28 09:23:15 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.157 2020/01/27 20:50:05 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.158 2020/01/28 09:23:15 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -713,6 +713,10 @@ pthread_join(pthread_t thread, void **va
 	if (thread == self)
 		return EDEADLK;
 
+	/* XXX temporary - kernel should handle. */
+	if ((thread->pt_flags & PT_FLAG_DETACHED) != 0)
+		return EINVAL;
+
 	/* IEEE Std 1003.1 says pthread_join() never returns EINTR. */
 	for (;;) {
 		pthread__testcancel(self);



CVS commit: src/lib/libpthread

2020-01-27 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jan 27 20:50:05 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_int.h

Log Message:
pthread_detach(), pthread_join():  go back to using _lwp_detach() and
_lwp_wait(), rather than doing it all in userspace.  There's less to go
wrong.  Doesn't seem to be a performance penalty.


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.98 -r1.99 src/lib/libpthread/pthread_int.h

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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.156 src/lib/libpthread/pthread.c:1.157
--- src/lib/libpthread/pthread.c:1.156	Sat Jan 25 18:01:28 2020
+++ src/lib/libpthread/pthread.c	Mon Jan 27 20:50:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.156 2020/01/25 18:01:28 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.157 2020/01/27 20:50:05 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.156 2020/01/25 18:01:28 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.157 2020/01/27 20:50:05 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -320,12 +320,10 @@ pthread__initthread(pthread_t t)
 	t->pt_havespecific = 0;
 	t->pt_early = NULL;
 	t->pt_lwpctl = __dummy_lwpctl;
-	t->pt_droplock = NULL;
 
 	memcpy(>pt_lockops, pthread__lock_ops, sizeof(t->pt_lockops));
 	pthread_mutex_init(>pt_lock, NULL);
 	PTQ_INIT(>pt_cleanup_stack);
-	pthread_cond_init(>pt_joiners, NULL);
 }
 
 static void
@@ -457,11 +455,9 @@ pthread_create(pthread_t *thread, const 
 	if (!PTQ_EMPTY(__deadqueue)) {
 		pthread_mutex_lock(__deadqueue_lock);
 		PTQ_FOREACH(newthread, __deadqueue, pt_deadq) {
-			/* Still running? */
+			/* Still busily exiting, or finished? */
 			if (newthread->pt_lwpctl->lc_curcpu ==
-			LWPCTL_CPU_EXITED ||
-			(_lwp_kill(newthread->pt_lid, 0) == -1 &&
-			errno == ESRCH))
+			LWPCTL_CPU_EXITED)
 break;
 		}
 		if (newthread)
@@ -527,10 +523,12 @@ pthread_create(pthread_t *thread, const 
 	private_area = newthread;
 #endif
 
-	flag = LWP_DETACHED;
+	flag = 0;
 	if ((newthread->pt_flags & PT_FLAG_SUSPENDED) != 0 ||
 	(nattr.pta_flags & PT_FLAG_EXPLICIT_SCHED) != 0)
 		flag |= LWP_SUSPENDED;
+	if ((newthread->pt_flags & PT_FLAG_DETACHED) != 0)
+		flag |= LWP_DETACHED;
 
 	ret = pthread__makelwp(pthread__create_tramp, newthread, private_area,
 	newthread->pt_stack.ss_sp, newthread->pt_stack.ss_size,
@@ -643,7 +641,6 @@ pthread_exit(void *retval)
 {
 	pthread_t self;
 	struct pt_clean_t *cleanup;
-	char *name;
 
 	if (__predict_false(__uselibcstub)) {
 		__libc_thr_exit_stub(retval);
@@ -681,20 +678,12 @@ pthread_exit(void *retval)
 	 */
 	self->pt_exitval = retval;
 	if (self->pt_flags & PT_FLAG_DETACHED) {
-		self->pt_state = PT_STATE_DEAD;
-		name = self->pt_name;
-		self->pt_name = NULL;
-		pthread_mutex_unlock(>pt_lock);
-		if (name != NULL)
-			free(name);
-		pthread_mutex_lock(__deadqueue_lock);
-		PTQ_INSERT_TAIL(__deadqueue, self, pt_deadq);
-		pthread_mutex_unlock(__deadqueue_lock);
+		/* pthread__reap() will drop the lock. */
+		pthread__reap(self);
 		pthread__clear_waiters(self);
 		_lwp_exit();
 	} else {
 		self->pt_state = PT_STATE_ZOMBIE;
-		pthread_cond_broadcast(>pt_joiners);
 		pthread_mutex_unlock(>pt_lock);
 		pthread__clear_waiters(self);
 		/* Note: name will be freed by the joiner. */
@@ -712,7 +701,6 @@ int
 pthread_join(pthread_t thread, void **valptr)
 {
 	pthread_t self;
-	int error;
 
 	self = pthread__self();
 
@@ -725,36 +713,29 @@ pthread_join(pthread_t thread, void **va
 	if (thread == self)
 		return EDEADLK;
 
-	self->pt_droplock = >pt_lock;
-	pthread_mutex_lock(>pt_lock);
+	/* IEEE Std 1003.1 says pthread_join() never returns EINTR. */
 	for (;;) {
-		if (thread->pt_state == PT_STATE_ZOMBIE)
+		pthread__testcancel(self);
+		if (_lwp_wait(thread->pt_lid, NULL) == 0)
 			break;
-		if (thread->pt_state == PT_STATE_DEAD) {
-			pthread_mutex_unlock(>pt_lock);
-			self->pt_droplock = NULL;
-			return ESRCH;
-		}
-		if ((thread->pt_flags & PT_FLAG_DETACHED) != 0) {
-			pthread_mutex_unlock(>pt_lock);
-			self->pt_droplock = NULL;
-			return EINVAL;
-		}
-		error = pthread_cond_wait(>pt_joiners,
-		>pt_lock);
-		if (error != 0) {
-			pthread__errorfunc(__FILE__, __LINE__,
-			__func__, "unexpected return from cond_wait()");
-		}
-
+		if (errno != EINTR)
+			return errno;
 	}
-	pthread__testcancel(self);
+
+	/*
+	 * Don't test for cancellation again.  The spec is that if
+	 * cancelled, pthread_join() must not have succeeded.
+	 */
+	pthread_mutex_lock(>pt_lock);
+	if (thread->pt_state != PT_STATE_ZOMBIE) {
+		pthread__errorfunc(__FILE__, __LINE__, __func__,
+		"not a zombie");
+ 	}
 	if (valptr != NULL)
 		*valptr = thread->pt_exitval;
+
 	/* pthread__reap() will drop the lock. */
 	pthread__reap(thread);
-	

CVS commit: src/lib/libpthread

2020-01-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jan 25 18:30:41 UTC 2020

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
Adjustment to previous: don't call _lwp_unpark_all() with nwaiters == 0.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.67 src/lib/libpthread/pthread_mutex.c:1.68
--- src/lib/libpthread/pthread_mutex.c:1.67	Sat Jan 25 17:58:28 2020
+++ src/lib/libpthread/pthread_mutex.c	Sat Jan 25 18:30:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.67 2020/01/25 17:58:28 ad Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.68 2020/01/25 18:30:41 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.67 2020/01/25 17:58:28 ad Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.68 2020/01/25 18:30:41 ad Exp $");
 
 #include 
 #include 
@@ -529,7 +529,7 @@ pthread__mutex_unlock_slow(pthread_mutex
 			(void)_lwp_unpark(self->pt_waiters[0],
 			__UNVOLATILE(>ptm_waiters));
 		}
-	} else {
+	} else if (self->pt_nwaiters > 0) {
 		(void)_lwp_unpark_all(self->pt_waiters, self->pt_nwaiters,
 		__UNVOLATILE(>ptm_waiters));
 	}



CVS commit: src/lib/libpthread

2020-01-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jan 25 18:01:28 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
pthread_exit(): it looks there there is at least one path through which
a thread can exit with waiters still hanging off it (cancellation when
waiting on a condvar) so deal with all/any crappy failure like that and
make sure there are never any waiters left before exiting.  Maybe of help
for:

PR: bin/50350: rump/rumpkern/t_sp/stress_{long,short} fail on Core 2


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.155 src/lib/libpthread/pthread.c:1.156
--- src/lib/libpthread/pthread.c:1.155	Sat Jan 25 15:41:52 2020
+++ src/lib/libpthread/pthread.c	Sat Jan 25 18:01:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.155 2020/01/25 15:41:52 ad Exp $	*/
+/*	$NetBSD: pthread.c,v 1.156 2020/01/25 18:01:28 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.155 2020/01/25 15:41:52 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.156 2020/01/25 18:01:28 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -621,6 +621,23 @@ pthread_resume_np(pthread_t thread)
 	return errno;
 }
 
+/*
+ * In case the thread is exiting at an inopportune time leaving waiters not
+ * awoken (because cancelled, for instance) make sure we have no waiters
+ * left.
+ */
+static void
+pthread__clear_waiters(pthread_t self)
+{
+
+	if (self->pt_nwaiters != 0) {
+		(void)_lwp_unpark_all(self->pt_waiters, self->pt_nwaiters,
+		NULL);
+		self->pt_nwaiters = 0;
+	}
+	self->pt_willpark = 0;
+}
+
 void
 pthread_exit(void *retval)
 {
@@ -658,7 +675,10 @@ pthread_exit(void *retval)
 	/* Perform cleanup of thread-specific data */
 	pthread__destroy_tsd(self);
 
-	/* Signal our exit. */
+	/*
+	 * Signal our exit.  Our stack and pthread_t won't be reused until
+	 * pthread_create() can see from kernel info that this LWP is gone.
+	 */
 	self->pt_exitval = retval;
 	if (self->pt_flags & PT_FLAG_DETACHED) {
 		self->pt_state = PT_STATE_DEAD;
@@ -670,11 +690,13 @@ pthread_exit(void *retval)
 		pthread_mutex_lock(__deadqueue_lock);
 		PTQ_INSERT_TAIL(__deadqueue, self, pt_deadq);
 		pthread_mutex_unlock(__deadqueue_lock);
+		pthread__clear_waiters(self);
 		_lwp_exit();
 	} else {
 		self->pt_state = PT_STATE_ZOMBIE;
 		pthread_cond_broadcast(>pt_joiners);
 		pthread_mutex_unlock(>pt_lock);
+		pthread__clear_waiters(self);
 		/* Note: name will be freed by the joiner. */
 		_lwp_exit();
 	}



CVS commit: src/lib/libpthread

2020-01-25 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat Jan 25 17:58:28 UTC 2020

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
pthread__mutex_unlock_slow(): ignore the DEFERRED bit.  It's only purpose
is to get the thread to go through the slow path.  If there are waiters,
process them there and then.  Should not affect well behaved apps.  Maybe
of help for:

PR bin/50350: rump/rumpkern/t_sp/stress_{long,short} fail on Core 2 Quad


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.66 src/lib/libpthread/pthread_mutex.c:1.67
--- src/lib/libpthread/pthread_mutex.c:1.66	Mon Jan 13 18:22:56 2020
+++ src/lib/libpthread/pthread_mutex.c	Sat Jan 25 17:58:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.66 2020/01/13 18:22:56 ad Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.67 2020/01/25 17:58:28 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.66 2020/01/13 18:22:56 ad Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.67 2020/01/25 17:58:28 ad Exp $");
 
 #include 
 #include 
@@ -466,7 +466,7 @@ NOINLINE static int
 pthread__mutex_unlock_slow(pthread_mutex_t *ptm)
 {
 	pthread_t self, owner, new;
-	int weown, error, deferred;
+	int weown, error;
 
 	pthread__error(EINVAL, "Invalid mutex",
 	ptm->ptm_magic == _PT_MUTEX_MAGIC);
@@ -474,7 +474,6 @@ pthread__mutex_unlock_slow(pthread_mutex
 	self = pthread__self();
 	owner = ptm->ptm_owner;
 	weown = (MUTEX_OWNER(owner) == (uintptr_t)self);
-	deferred = (int)((uintptr_t)owner & MUTEX_DEFERRED_BIT);
 	error = 0;
 
 	if (__SIMPLELOCK_LOCKED_P(>ptm_errorcheck)) {
@@ -516,15 +515,9 @@ pthread__mutex_unlock_slow(pthread_mutex
 			pthread__mutex_wakeup(self, ptm);
 			return 0;
 		}
+		error = 0;
 	}
 
-	/*
-	 * There were no waiters, but we may have deferred waking
-	 * other threads until mutex unlock - we must wake them now.
-	 */
-	if (!deferred)
-		return error;
-
 	if (self->pt_nwaiters == 1) {
 		/*
 		 * If the calling thread is about to block, defer



CVS commit: src/lib/libpthread

2020-01-13 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Mon Jan 13 18:22:56 UTC 2020

Modified Files:
src/lib/libpthread: pthread.c pthread_cond.c pthread_int.h
pthread_misc.c pthread_mutex.c pthread_rwlock.c

Log Message:
Rip out some very ambitious optimisations around pthread_mutex that are
don't buy much.  This stuff is hard enough to get right in the kernel let
alone userspace, and I don't trust that it's right.


To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.65 -r1.66 src/lib/libpthread/pthread_cond.c \
src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.97 -r1.98 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.15 -r1.16 src/lib/libpthread/pthread_misc.c
cvs rdiff -u -r1.36 -r1.37 src/lib/libpthread/pthread_rwlock.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.153 src/lib/libpthread/pthread.c:1.154
--- src/lib/libpthread/pthread.c:1.153	Tue Mar  5 01:35:52 2019
+++ src/lib/libpthread/pthread.c	Mon Jan 13 18:22:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.153 2019/03/05 01:35:52 christos Exp $	*/
+/*	$NetBSD: pthread.c,v 1.154 2020/01/13 18:22:56 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.153 2019/03/05 01:35:52 christos Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.154 2020/01/13 18:22:56 ad Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -319,7 +319,6 @@ pthread__initthread(pthread_t t)
 	t->pt_havespecific = 0;
 	t->pt_early = NULL;
 	t->pt_lwpctl = __dummy_lwpctl;
-	t->pt_blocking = 0;
 	t->pt_droplock = NULL;
 
 	memcpy(>pt_lockops, pthread__lock_ops, sizeof(t->pt_lockops));
@@ -1157,15 +1156,9 @@ pthread__park(pthread_t self, pthread_mu
 	int rv, error;
 	void *obj;
 
-	/*
-	 * For non-interlocked release of mutexes we need a store
-	 * barrier before incrementing pt_blocking away from zero. 
-	 * This is provided by pthread_mutex_unlock().
-	 */
 	self->pt_willpark = 1;
 	pthread_mutex_unlock(lock);
 	self->pt_willpark = 0;
-	self->pt_blocking++;
 
 	/*
 	 * Wait until we are awoken by a pending unpark operation,
@@ -1239,8 +1232,6 @@ pthread__park(pthread_t self, pthread_mu
 		pthread_mutex_unlock(lock);
 	}
 	self->pt_early = NULL;
-	self->pt_blocking--;
-	membar_sync();
 
 	return rv;
 }

Index: src/lib/libpthread/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.65 src/lib/libpthread/pthread_cond.c:1.66
--- src/lib/libpthread/pthread_cond.c:1.65	Fri Dec  8 03:08:19 2017
+++ src/lib/libpthread/pthread_cond.c	Mon Jan 13 18:22:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.65 2017/12/08 03:08:19 christos Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.66 2020/01/13 18:22:56 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.65 2017/12/08 03:08:19 christos Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.66 2020/01/13 18:22:56 ad Exp $");
 
 #include 
 #include 
@@ -164,7 +164,6 @@ pthread_cond_timedwait(pthread_cond_t *c
 		self->pt_willpark = 1;
 		pthread_mutex_unlock(mutex);
 		self->pt_willpark = 0;
-		self->pt_blocking++;
 		do {
 			retval = _lwp_park(clkid, TIMER_ABSTIME,
 			__UNCONST(abstime), self->pt_unpark,
@@ -172,8 +171,6 @@ pthread_cond_timedwait(pthread_cond_t *c
 			__UNVOLATILE(>ptm_waiters));
 			self->pt_unpark = 0;
 		} while (retval == -1 && errno == ESRCH);
-		self->pt_blocking--;
-		membar_sync();
 		pthread_mutex_lock(mutex);
 
 		/*
Index: src/lib/libpthread/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.65 src/lib/libpthread/pthread_mutex.c:1.66
--- src/lib/libpthread/pthread_mutex.c:1.65	Tue Mar  5 22:49:38 2019
+++ src/lib/libpthread/pthread_mutex.c	Mon Jan 13 18:22:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.65 2019/03/05 22:49:38 christos Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.66 2020/01/13 18:22:56 ad Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.65 2019/03/05 22:49:38 christos Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.66 2020/01/13 18:22:56 ad Exp $");
 
 #include 
 #include 
@@ -235,10 +235,7 @@ pthread__mutex_pause(void)
 
 /*
  * Spin while the holder is running.  'lwpctl' gives us the true
- * status of the thread.  pt_blocking is set by libpthread in order
- * to cut out system call and kernel spinlock overhead on remote CPUs
- * (could represent many thousands of clock cycles).  pt_blocking also
- * makes this thread yield if the target is calling sched_yield().
+ * status of the thread.
  */
 NOINLINE static void *
 pthread__mutex_spin(pthread_mutex_t *ptm, pthread_t owner)
@@ -250,8 +247,7 @@ 

CVS commit: src/lib/libpthread

2019-12-24 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Dec 25 00:44:45 UTC 2019

Modified Files:
src/lib/libpthread: pthread_tsd.c

Log Message:
Since pthread_setspecific requires locks, ensure that they are acquired
before fork and dropped in both parent and child. At least Python
depends on TSD after fork, even though it is undefined behavior in
POSIX.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libpthread/pthread_tsd.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/pthread_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.17 src/lib/libpthread/pthread_tsd.c:1.18
--- src/lib/libpthread/pthread_tsd.c:1.17	Tue Mar  5 01:35:52 2019
+++ src/lib/libpthread/pthread_tsd.c	Wed Dec 25 00:44:45 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_tsd.c,v 1.17 2019/03/05 01:35:52 christos Exp $	*/
+/*	$NetBSD: pthread_tsd.c,v 1.18 2019/12/25 00:44:45 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_tsd.c,v 1.17 2019/03/05 01:35:52 christos Exp $");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.18 2019/12/25 00:44:45 joerg Exp $");
 
 /* Functions and structures dealing with thread-specific data */
 #include 
@@ -61,6 +61,18 @@ null_destructor(void *p)
 #include 
 #include 
 
+static void
+pthread_tsd_prefork(void)
+{
+	pthread_mutex_lock(_mutex);
+}
+
+static void
+pthread_tsd_postfork(void)
+{
+	pthread_mutex_unlock(_mutex);
+}
+
 void *
 pthread_tsd_init(size_t *tlen)
 {
@@ -68,6 +80,8 @@ pthread_tsd_init(size_t *tlen)
 	size_t alen;
 	char *arena;
 
+	pthread_atfork(pthread_tsd_prefork, pthread_tsd_postfork, pthread_tsd_postfork);
+
 	if ((pkm = pthread__getenv("PTHREAD_KEYS_MAX")) != NULL) {
 		pthread_keys_max = (int)strtol(pkm, NULL, 0);
 		if (pthread_keys_max < _POSIX_THREAD_KEYS_MAX)



CVS commit: src/lib/libpthread

2019-12-18 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Dec 18 15:11:57 UTC 2019

Modified Files:
src/lib/libpthread: pthread_int.h

Log Message:
Bump PTHREAD__UNPARK_MAX to 128 as bandaid for locking related hangs.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/lib/libpthread/pthread_int.h

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/pthread_int.h
diff -u src/lib/libpthread/pthread_int.h:1.96 src/lib/libpthread/pthread_int.h:1.97
--- src/lib/libpthread/pthread_int.h:1.96	Mon Dec 16 20:45:40 2019
+++ src/lib/libpthread/pthread_int.h	Wed Dec 18 15:11:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_int.h,v 1.96 2019/12/16 20:45:40 uwe Exp $	*/
+/*	$NetBSD: pthread_int.h,v 1.97 2019/12/18 15:11:57 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
 #define	PTHREAD_HIDE	/* nothing */
 #endif
 
-#define	PTHREAD__UNPARK_MAX	32
+#define	PTHREAD__UNPARK_MAX	128
 
 /*
  * The size of this structure needs to be no larger than struct



CVS commit: src/lib/libpthread

2019-12-16 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Dec 16 22:22:11 UTC 2019

Modified Files:
src/lib/libpthread: pthread_rwlock.c

Log Message:
pthread__rwlock_spin - clarify the test.

It's more pedantically correct to check RW_WRITE_LOCKED before
obtaining the thread id of the owner.  And since there must be an
owner annotate the guard NULL check as unlinkely.

No functional change intended.  Ok ad@.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/lib/libpthread/pthread_rwlock.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/pthread_rwlock.c
diff -u src/lib/libpthread/pthread_rwlock.c:1.35 src/lib/libpthread/pthread_rwlock.c:1.36
--- src/lib/libpthread/pthread_rwlock.c:1.35	Sun Dec 15 23:13:33 2019
+++ src/lib/libpthread/pthread_rwlock.c	Mon Dec 16 22:22:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_rwlock.c,v 1.35 2019/12/15 23:13:33 uwe Exp $ */
+/*	$NetBSD: pthread_rwlock.c,v 1.36 2019/12/16 22:22:11 uwe Exp $ */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_rwlock.c,v 1.35 2019/12/15 23:13:33 uwe Exp $");
+__RCSID("$NetBSD: pthread_rwlock.c,v 1.36 2019/12/16 22:22:11 uwe Exp $");
 
 #include 
 #include 
@@ -134,12 +134,15 @@ pthread__rwlock_spin(uintptr_t owner)
 	pthread_t thread;
 	unsigned int i;
 
-	thread = (pthread_t)(owner & RW_THREAD);
-	if (thread == NULL || (owner & ~RW_THREAD) != RW_WRITE_LOCKED)
+	if ((owner & ~RW_THREAD) != RW_WRITE_LOCKED)
 		return 0;
-	if (thread->pt_lwpctl->lc_curcpu == LWPCTL_CPU_NONE ||
+
+	thread = (pthread_t)(owner & RW_THREAD);
+	if (__predict_false(thread == NULL) ||
+	thread->pt_lwpctl->lc_curcpu == LWPCTL_CPU_NONE ||
 	thread->pt_blocking)
 		return 0;
+
 	for (i = 128; i != 0; i--)
 		pthread__rwlock_pause();
 	return 1;



CVS commit: src/lib/libpthread

2019-12-16 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Dec 16 20:45:40 UTC 2019

Modified Files:
src/lib/libpthread: pthread_int.h

Log Message:
G/c unused rwlock owner macros copy-pasted from the kernel.

They were brought along with the rwlock flags but never used and never
even adapted to the new home (the struct member name is different
here).  I looked at adapting and using them, but they don't really
help readability that much and there are cases where we need to deal
with "fused" owner values anyway and so can't use them.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/lib/libpthread/pthread_int.h

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/pthread_int.h
diff -u src/lib/libpthread/pthread_int.h:1.95 src/lib/libpthread/pthread_int.h:1.96
--- src/lib/libpthread/pthread_int.h:1.95	Tue Mar  5 01:35:52 2019
+++ src/lib/libpthread/pthread_int.h	Mon Dec 16 20:45:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_int.h,v 1.95 2019/03/05 01:35:52 christos Exp $	*/
+/*	$NetBSD: pthread_int.h,v 1.96 2019/12/16 20:45:40 uwe Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -324,8 +324,5 @@ int	pthread__add_specific(pthread_t, pth
 #define	RW_READ_COUNT_SHIFT	4
 #define	RW_READ_INCR		(1 << RW_READ_COUNT_SHIFT)
 #define	RW_THREAD		((uintptr_t)-RW_READ_INCR)
-#define	RW_OWNER(rw)		((rw)->rw_owner & RW_THREAD)
-#define	RW_COUNT(rw)		((rw)->rw_owner & RW_THREAD)
-#define	RW_FLAGS(rw)		((rw)->rw_owner & ~RW_THREAD)
 
 #endif /* _LIB_PTHREAD_INT_H */



CVS commit: src/lib/libpthread

2019-12-15 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sun Dec 15 23:13:33 UTC 2019

Modified Files:
src/lib/libpthread: pthread_rwlock.c

Log Message:
_DIAGASSERT that RW_FLAGMASK bits are not set in a thread pointer.

rwlock uses lower bits of a thread pointer for flags in the lock owner
field.  Assert that the pointer is properly aligned and those bits are
actually free to use.  This may not be the case when a program uses
its own allocator that can return less aligned pointers.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libpthread/pthread_rwlock.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/pthread_rwlock.c
diff -u src/lib/libpthread/pthread_rwlock.c:1.34 src/lib/libpthread/pthread_rwlock.c:1.35
--- src/lib/libpthread/pthread_rwlock.c:1.34	Sun Jul  3 14:24:58 2016
+++ src/lib/libpthread/pthread_rwlock.c	Sun Dec 15 23:13:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_rwlock.c,v 1.34 2016/07/03 14:24:58 christos Exp $ */
+/*	$NetBSD: pthread_rwlock.c,v 1.35 2019/12/15 23:13:33 uwe Exp $ */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,11 +30,12 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_rwlock.c,v 1.34 2016/07/03 14:24:58 christos Exp $");
+__RCSID("$NetBSD: pthread_rwlock.c,v 1.35 2019/12/15 23:13:33 uwe Exp $");
 
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -275,6 +276,7 @@ pthread__rwlock_wrlock(pthread_rwlock_t 
 	int error;
 
 	self = pthread__self();
+	_DIAGASSERT(((uintptr_t)self & RW_FLAGMASK) == 0);
 
 #ifdef ERRORCHECK
 	if (ptr->ptr_magic != _PT_RWLOCK_MAGIC)
@@ -373,6 +375,7 @@ pthread_rwlock_trywrlock(pthread_rwlock_
 #endif
 
 	self = pthread__self();
+	_DIAGASSERT(((uintptr_t)self & RW_FLAGMASK) == 0);
 
 	for (owner = (uintptr_t)ptr->ptr_owner;; owner = next) {
 		if (owner != 0)
@@ -509,6 +512,7 @@ pthread_rwlock_unlock(pthread_rwlock_t *
 		 */
 		self = pthread__self();
 		if ((thread = PTQ_FIRST(>ptr_wblocked)) != NULL) {
+			_DIAGASSERT(((uintptr_t)thread & RW_FLAGMASK) == 0);
 			new = (uintptr_t)thread | RW_WRITE_LOCKED;
 
 			if (PTQ_NEXT(thread, pt_sleep) != NULL)



CVS commit: src/lib/libpthread

2019-12-15 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Sun Dec 15 22:32:29 UTC 2019

Modified Files:
src/lib/libpthread: tss.c

Log Message:
Drop bogus _DIAGASSERT that don't even compile.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libpthread/tss.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/tss.c
diff -u src/lib/libpthread/tss.c:1.1 src/lib/libpthread/tss.c:1.2
--- src/lib/libpthread/tss.c:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/tss.c	Sun Dec 15 22:32:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: tss.c,v 1.1 2019/04/24 11:43:19 kamil Exp $	*/
+/*	$NetBSD: tss.c,v 1.2 2019/12/15 22:32:29 uwe Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: tss.c,v 1.1 2019/04/24 11:43:19 kamil Exp $");
+__RCSID("$NetBSD: tss.c,v 1.2 2019/12/15 22:32:29 uwe Exp $");
 
 #include 
 #include 
@@ -53,8 +53,6 @@ void
 tss_delete(tss_t key)
 {
 
-	_DIAGASSERT(key != NULL);
-
 	/*
 	 * The tss_delete(3) function that conforms to C11 returns no value.
 	 */
@@ -65,8 +63,6 @@ void *
 tss_get(tss_t key)
 {
 
-	_DIAGASSERT(key != NULL);
-
 	return pthread_getspecific(key);
 }
 
@@ -74,8 +70,6 @@ int
 tss_set(tss_t key, void *val)
 {
 
-	_DIAGASSERT(key != NULL);
-
 	if (pthread_setspecific(key, val) == 0)
 		return thrd_success;
 



CVS commit: src/lib/libpthread

2019-05-07 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Tue May  7 18:45:37 UTC 2019

Modified Files:
src/lib/libpthread: Makefile

Log Message:
Make CLEANFILES actually work. .TARGET is not defined when not in a target
rule.

Thanks xtos for the heads up.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/lib/libpthread/Makefile

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.93 src/lib/libpthread/Makefile:1.94
--- src/lib/libpthread/Makefile:1.93	Tue May  7 18:12:53 2019
+++ src/lib/libpthread/Makefile	Tue May  7 18:45:37 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.93 2019/05/07 18:12:53 maya Exp $
+#	$NetBSD: Makefile,v 1.94 2019/05/07 18:45:37 maya Exp $
 #
 
 NOSANITIZER=	# defined
@@ -281,7 +281,7 @@ __archivebuild: .USE
 	${LD} -r -o ${.TARGET}.o `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
 	${AR} ${_ARFL} ${.TARGET} ${.TARGET}.o
 
-CLEANFILES+=	${.TARGET}.o
+CLEANFILES+=	${_LIBS:=.o}
 
 .include 
 



CVS commit: src/lib/libpthread

2019-05-07 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Tue May  7 18:12:53 UTC 2019

Modified Files:
src/lib/libpthread: Makefile

Log Message:
Replace the link command for libpthread.a so that we create a single section
with all the libpthread symbols in it.
This makes -lpthread behave like to -Wl,--whole-archive -lpthread.

This avoids a situation where threaded static binaries use some libc thread
stubs, which are racy.

Fixes PR lib/54001: call_once2_32, call_once2_static test cases failing on
amd64 since gcc7 import.

Suggested by Jonathan Wakely, thanks!


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/lib/libpthread/Makefile

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.92 src/lib/libpthread/Makefile:1.93
--- src/lib/libpthread/Makefile:1.92	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/Makefile	Tue May  7 18:12:53 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.92 2019/04/24 11:43:19 kamil Exp $
+#	$NetBSD: Makefile,v 1.93 2019/05/07 18:12:53 maya Exp $
 #
 
 NOSANITIZER=	# defined
@@ -269,6 +269,20 @@ MLINKS+=	tss.3 tss_set.3
 
 INCS+=		threads.h
 
+# PR lib/54001: create libpthread.a as a single large object, with all the
+# symbols in one section. ensures that if any libpthread function is used,
+# you get all of them from libpthread, and not the libc stubs.
+#
+# This makes -lpthread equivalent to -Wl,--whole-archive -lpthread
+
+__archivebuild: .USE
+	${_MKTARGET_BUILD}
+	@rm -f ${.TARGET}
+	${LD} -r -o ${.TARGET}.o `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
+	${AR} ${_ARFL} ${.TARGET} ${.TARGET}.o
+
+CLEANFILES+=	${.TARGET}.o
+
 .include 
 
 .else



CVS commit: src/lib/libpthread

2019-04-29 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Mon Apr 29 20:11:44 UTC 2019

Modified Files:
src/lib/libpthread: thrd.c

Log Message:
Avoid incompatible function pointer casts in thrd_create(3)

Use an intermediate function trampoline to workaround different function
pointer prototypes.

While there, correct scenario returning thrd_nomem from thrd_create(3).
In practice ENOMEM is rarely returned from pthread(3).

Older code worked on tested ports, but was depending on unneeded UB.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libpthread/thrd.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/thrd.c
diff -u src/lib/libpthread/thrd.c:1.2 src/lib/libpthread/thrd.c:1.3
--- src/lib/libpthread/thrd.c:1.2	Wed Apr 24 18:47:54 2019
+++ src/lib/libpthread/thrd.c	Mon Apr 29 20:11:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: thrd.c,v 1.2 2019/04/24 18:47:54 kamil Exp $	*/
+/*	$NetBSD: thrd.c,v 1.3 2019/04/29 20:11:43 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,30 +30,67 @@
  */
 
 #include 
-__RCSID("$NetBSD: thrd.c,v 1.2 2019/04/24 18:47:54 kamil Exp $");
+__RCSID("$NetBSD: thrd.c,v 1.3 2019/04/29 20:11:43 kamil Exp $");
 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
+struct __thrd_tramp_data {
+	thrd_start_t func;
+	void *arg;
+};
+
+static void *
+__thrd_create_tramp(void *arg)
+{
+	struct __thrd_tramp_data *cookie;
+	int ret;
+
+	_DIAGASSERT(arg != NULL);
+
+	cookie = (struct __thrd_tramp_data *)arg;
+
+	ret = (cookie->func)(cookie->arg);
+
+	free(cookie);
+
+	return (void *)(intptr_t)ret;
+}
+
 int
 thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
 {
+	struct __thrd_tramp_data *cookie;
+	int error;
 
 	_DIAGASSERT(thr != NULL);
 	_DIAGASSERT(func != NULL);
 
-	switch(pthread_create(thr, NULL, (void *(*)(void *))func, arg)) {
+	cookie = malloc(sizeof(*cookie));
+	if (cookie == NULL)
+		return thrd_nomem;
+
+	cookie->func = func;
+	cookie->arg = arg;
+
+	switch(pthread_create(thr, NULL, __thrd_create_tramp, cookie)) {
 	case 0:
 		return thrd_success;
-	case EAGAIN:
-		return thrd_nomem;
+	case ENOMEM:
+		error = thrd_nomem;
+		break;
 	default:
-		return thrd_error;
+		error = thrd_error;
 	}
+
+	free(cookie);
+
+	return error;
 }
 
 thrd_t



CVS commit: src/lib/libpthread

2019-04-27 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sat Apr 27 10:57:12 UTC 2019

Modified Files:
src/lib/libpthread: call_once.3 cnd.3 mtx.3 thrd.3 threads.3 tss.3

Log Message:
Fix some typos, improve wording.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libpthread/call_once.3 \
src/lib/libpthread/cnd.3 src/lib/libpthread/mtx.3 \
src/lib/libpthread/threads.3 src/lib/libpthread/tss.3
cvs rdiff -u -r1.2 -r1.3 src/lib/libpthread/thrd.3

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/call_once.3
diff -u src/lib/libpthread/call_once.3:1.1 src/lib/libpthread/call_once.3:1.2
--- src/lib/libpthread/call_once.3:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/call_once.3	Sat Apr 27 10:57:11 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: call_once.3,v 1.1 2019/04/24 11:43:19 kamil Exp $
+.\"	$NetBSD: call_once.3,v 1.2 2019/04/27 10:57:11 wiz Exp $
 .\"
 .\" Copyright (c) 2016 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -38,7 +38,7 @@
 .Sh SYNOPSIS
 .In threads.h
 .Ft void
-.Fn call_once "once_flag *flag" "void (*func)(void))"
+.Fn call_once "once_flag *flag" "void (*func)(void)"
 .Vt #define ONCE_FLAG_INIT /* implementation specified */
 .Sh DESCRIPTION
 The
Index: src/lib/libpthread/cnd.3
diff -u src/lib/libpthread/cnd.3:1.1 src/lib/libpthread/cnd.3:1.2
--- src/lib/libpthread/cnd.3:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/cnd.3	Sat Apr 27 10:57:11 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: cnd.3,v 1.1 2019/04/24 11:43:19 kamil Exp $
+.\"	$NetBSD: cnd.3,v 1.2 2019/04/27 10:57:11 wiz Exp $
 .\"
 .\" Copyright (c) 2016 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -72,7 +72,7 @@ condition variable.
 .Pp
 The
 .Fn cnd_init
-function initializes new
+function initializes a new
 .Fa cond
 variable.
 .Pp
@@ -81,13 +81,13 @@ The
 function unblock one thread that currently waits on the
 .Fa cond
 variable.
-If there are no threads blocked
+If there are no threads blocked,
 .Fn cnd_signal
 does nothing and returns success.
 .Pp
 The
 .Fn cnd_timedwait
-function atomicalyl unlocks the mutex
+function atomically unlocks the mutex
 .Fa mtx
 and blocks on the condition variable
 .Fa cond
@@ -109,7 +109,7 @@ The
 .Fn cnd_wait
 function atomically unlocks the mutex
 .Fa mtx
-and tries to blocks on on the conditional variable
+and tries to block on the conditional variable
 .Fa cond
 until a thread is signalled by a call to
 .Fn cnd_signal
@@ -121,7 +121,7 @@ mutex is locked again before the functio
 If the mutex is not locked by the calling thread then behavior is undefined.
 .Sh RETURN VALUES
 The
-.Fn cnd_broadcast ,
+.Fn cnd_broadcast
 function returns
 .Dv thrd_success
 on success or
@@ -131,6 +131,8 @@ on failure.
 The
 .Fn cnd_destroy
 function returns no value.
+.Pp
+The
 .Fn cnd_init
 function returns
 .Dv thrd_success
@@ -153,7 +155,7 @@ function returns
 on success, otherwise
 .Dv thrd_timedout
 to indicate that system time has reached or exceeded the time specified in
-.Dv ts
+.Dv ts ,
 or
 .Dv thrd_error
 on failure.
@@ -162,7 +164,7 @@ The
 .Fn cnd_wait
 function returns
 .Dv thrd_success
-on success, otherwise
+on success or
 .Dv thrd_error
 on failure.
 .Sh SEE ALSO
Index: src/lib/libpthread/mtx.3
diff -u src/lib/libpthread/mtx.3:1.1 src/lib/libpthread/mtx.3:1.2
--- src/lib/libpthread/mtx.3:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/mtx.3	Sat Apr 27 10:57:11 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mtx.3,v 1.1 2019/04/24 11:43:19 kamil Exp $
+.\"	$NetBSD: mtx.3,v 1.2 2019/04/27 10:57:11 wiz Exp $
 .\"
 .\" Copyright (c) 2016 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -72,13 +72,13 @@ The allowed values of
 are as follows:
 .Bl -column "mtx_plain | mtx_recursive"
 .It Sy "Type"Ta Sy "Description"
-.It Xr mtx_plain Ta basic mutex
-.It Xr mtx_timed Ta mutex with timeout support
-.It Xr mtx_plain | mtx_recursive Ta basic recursive mutex
-.It Xr mtx_timed | mtx_recursive Ta recursive mutex with timeout support
+.It Dv mtx_plain Ta basic mutex
+.It Dv mtx_timed Ta mutex with timeout support
+.It Dv mtx_plain | Dv mtx_recursive Ta basic recursive mutex
+.It Dv mtx_timed | Dv mtx_recursive Ta recursive mutex with timeout support
 .El
 .Pp
-The underlaying
+The underlying
 .Nx
 implementation of mutex types does not distinguish between
 .Dv mtx_plain
@@ -91,17 +91,17 @@ The
 function locks the
 .Fa mtx
 object.
-It is required the never lock multiple times the same
+It is required to never lock the same
 .Fa mtx
 object without the
 .Dv mtx_recursive
-property.
+property multiple times.
 If the
 .Fa mtx
 object is already locked by another thread,
-caller of
+the caller of
 .Fa mtx_lock
-blocks until lock becomes available.
+blocks until the lock becomes available.
 .Pp
 The
 .Fn mtx_timedlock
@@ -109,7 +109,7 @@ function tries to lock the
 .Fa mtx
 

CVS commit: src/lib/libpthread

2019-04-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Apr 24 21:41:15 UTC 2019

Modified Files:
src/lib/libpthread: call_once.c

Log Message:
Drop error path from C11 call_once

The original implementation of C11 threads(3) contained check for error
paths, but it was stripped in the calls that are documented to return
no status from an operation. Do the same in call_once(3).


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libpthread/call_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/call_once.c
diff -u src/lib/libpthread/call_once.c:1.1 src/lib/libpthread/call_once.c:1.2
--- src/lib/libpthread/call_once.c:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/call_once.c	Wed Apr 24 21:41:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: call_once.c,v 1.1 2019/04/24 11:43:19 kamil Exp $	*/
+/*	$NetBSD: call_once.c,v 1.2 2019/04/24 21:41:15 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,12 +30,10 @@
  */
 
 #include 
-__RCSID("$NetBSD: call_once.c,v 1.1 2019/04/24 11:43:19 kamil Exp $");
+__RCSID("$NetBSD: call_once.c,v 1.2 2019/04/24 21:41:15 kamil Exp $");
 
 #include 
-#include 
 #include 
-#include 
 #include 
 
 void
@@ -45,8 +43,8 @@ call_once(once_flag *flag, void (*func)(
 	_DIAGASSERT(flag != NULL);
 	_DIAGASSERT(func != NULL);
 
-	/* The call_once(3) function returns no value, this forces this code to
-	 * break as there is nothing better available. */
-	if (pthread_once(flag, func) != 0)
-		errx(EXIT_FAILURE, "pthread_once failed");
+	/*
+	 * The call_once(3) function that conforms to C11 returns no value.
+	 */
+	(void)pthread_once(flag, func);
 }



CVS commit: src/lib/libpthread

2019-04-24 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Wed Apr 24 18:47:54 UTC 2019

Modified Files:
src/lib/libpthread: thrd.3 thrd.c threads.h

Log Message:
Introduce minor changes to the C11 threading library

Switch tss_t type from int to pthread_key_t (no functional change as
pthread_key_t was already typedefed as int).

Noted by .

Use C11 _Noreturn in thrd_exit(3) instead of NetBSD specific __dead.
The former is documented in the standard as an attribute of thrd_exit(3),
the latter is more portable to pre-C11 compilers, however C11 thread
support library needs C11 compiler for TLS anyway. __dead made a little bit
more point 3 years ago than today as 3 years ago pre-C11 compilers were
more common.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libpthread/thrd.3 src/lib/libpthread/thrd.c \
src/lib/libpthread/threads.h

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/thrd.3
diff -u src/lib/libpthread/thrd.3:1.1 src/lib/libpthread/thrd.3:1.2
--- src/lib/libpthread/thrd.3:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/thrd.3	Wed Apr 24 18:47:54 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: thrd.3,v 1.1 2019/04/24 11:43:19 kamil Exp $
+.\"	$NetBSD: thrd.3,v 1.2 2019/04/24 18:47:54 kamil Exp $
 .\"
 .\" Copyright (c) 2016 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -46,7 +46,7 @@
 .Fn thrd_detach "thrd_t thr"
 .Ft int
 .Fn thrd_equal "thrd_t t1" "thrd_t t2"
-.Ft __dead void
+.Ft _Noreturn void
 .Fn thrd_exit "int res"
 .Ft int
 .Fn thrd_join "thrd_t thr" "int *res"
@@ -191,14 +191,6 @@ otherwise it will return non-zero.
 The
 .Fn thrd_exit
 function does not return.
-The standard attributes this function with the
-.Dv _Noreturn
-keyword,
-however in the
-.Nx
-version it is attributed with the traditional and functionally equivalent
-.Dv __dead
-keyword.
 .Pp
 The
 .Fn thrd_join
Index: src/lib/libpthread/thrd.c
diff -u src/lib/libpthread/thrd.c:1.1 src/lib/libpthread/thrd.c:1.2
--- src/lib/libpthread/thrd.c:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/thrd.c	Wed Apr 24 18:47:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: thrd.c,v 1.1 2019/04/24 11:43:19 kamil Exp $	*/
+/*	$NetBSD: thrd.c,v 1.2 2019/04/24 18:47:54 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: thrd.c,v 1.1 2019/04/24 11:43:19 kamil Exp $");
+__RCSID("$NetBSD: thrd.c,v 1.2 2019/04/24 18:47:54 kamil Exp $");
 
 #include 
 #include 
@@ -85,7 +85,7 @@ thrd_equal(thrd_t t1, thrd_t t2)
 	return pthread_equal(t1, t2);
 }
 
-__dead void
+_Noreturn void
 thrd_exit(int res)
 {
 
Index: src/lib/libpthread/threads.h
diff -u src/lib/libpthread/threads.h:1.1 src/lib/libpthread/threads.h:1.2
--- src/lib/libpthread/threads.h:1.1	Wed Apr 24 11:43:19 2019
+++ src/lib/libpthread/threads.h	Wed Apr 24 18:47:54 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: threads.h,v 1.1 2019/04/24 11:43:19 kamil Exp $	*/
+/*	$NetBSD: threads.h,v 1.2 2019/04/24 18:47:54 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
 /* ISO/IEC 9899:201x 7.26.1/4 */
 typedef pthread_cond_t	  cnd_t;
 typedef pthread_t	  thrd_t;
-typedef int		  tss_t;
+typedef pthread_key_t	  tss_t;
 typedef pthread_mutex_t	  mtx_t;
 typedef void		(*tss_dtor_t)	(void *);
 typedef int		(*thrd_start_t)	(void *);
@@ -106,7 +106,7 @@ int	thrd_create(thrd_t *, thrd_start_t, 
 thrd_t	thrd_current(void);
 int	thrd_detach(thrd_t);
 int	thrd_equal(thrd_t, thrd_t);
-void	thrd_exit(int) __dead;
+_Noreturn void	thrd_exit(int);
 int	thrd_join(thrd_t, int *);
 int	thrd_sleep(const struct timespec *, struct timespec *);
 void	thrd_yield(void);



CVS commit: src/lib/libpthread

2019-03-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Mar  5 22:49:38 UTC 2019

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
Jemalloc initializes mutexes before we become threaded and expects to use
them later.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.64 src/lib/libpthread/pthread_mutex.c:1.65
--- src/lib/libpthread/pthread_mutex.c:1.64	Fri Dec  8 04:24:31 2017
+++ src/lib/libpthread/pthread_mutex.c	Tue Mar  5 17:49:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.64 2017/12/08 09:24:31 kre Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.65 2019/03/05 22:49:38 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.64 2017/12/08 09:24:31 kre Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.65 2019/03/05 22:49:38 christos Exp $");
 
 #include 
 #include 
@@ -122,8 +122,14 @@ pthread_mutex_init(pthread_mutex_t *ptm,
 {
 	uintptr_t type, proto, val, ceil;
 
+#if 0
+	/*
+	 * Always initialize the mutex structure, maybe be used later
+	 * and the cost should be minimal.
+	 */
 	if (__predict_false(__uselibcstub))
 		return __libc_mutex_init_stub(ptm, attr);
+#endif
 
 	if (attr == NULL) {
 		type = PTHREAD_MUTEX_NORMAL;



CVS commit: src/lib/libpthread/arch/arm

2018-11-22 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Nov 22 20:38:59 UTC 2018

Modified Files:
src/lib/libpthread/arch/arm: pthread_md.h

Log Message:
G/C __APCS_26__ support


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libpthread/arch/arm/pthread_md.h

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/arch/arm/pthread_md.h
diff -u src/lib/libpthread/arch/arm/pthread_md.h:1.10 src/lib/libpthread/arch/arm/pthread_md.h:1.11
--- src/lib/libpthread/arch/arm/pthread_md.h:1.10	Mon Jul 17 20:24:07 2017
+++ src/lib/libpthread/arch/arm/pthread_md.h	Thu Nov 22 20:38:59 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_md.h,v 1.10 2017/07/17 20:24:07 skrll Exp $	*/
+/*	$NetBSD: pthread_md.h,v 1.11 2018/11/22 20:38:59 skrll Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -66,15 +66,8 @@ pthread__sp(void)
  * Set initial, sane values for registers whose values aren't just
  * "don't care".
  */
-#ifdef __APCS_26__
-#define _INITCONTEXT_U_MD(ucp)		\
-/* Set R15_MODE_USR in the PC */	\
-	(ucp)->uc_mcontext.__gregs[_REG_PC] =\
-	 ((ucp)->uc_mcontext.__gregs[_REG_PC] & 0x3fc) | 0x0;
-#else
 /* Set CPSR to PSR_USR32_MODE (0x10) from arm/armreg.h */
 #define _INITCONTEXT_U_MD(ucp)		\
 	(ucp)->uc_mcontext.__gregs[_REG_CPSR] = 0x10;
-#endif
 
 #endif /* _LIB_PTHREAD_ARM_MD_H */



CVS commit: src/lib/libpthread

2018-09-09 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sun Sep  9 07:24:59 UTC 2018

Modified Files:
src/lib/libpthread: shlib_version

Log Message:
Add a todo item for a future major bump (rename many symbols)


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libpthread/shlib_version

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/shlib_version
diff -u src/lib/libpthread/shlib_version:1.17 src/lib/libpthread/shlib_version:1.18
--- src/lib/libpthread/shlib_version:1.17	Sat Apr 23 23:23:17 2016
+++ src/lib/libpthread/shlib_version	Sun Sep  9 07:24:59 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: shlib_version,v 1.17 2016/04/23 23:23:17 christos Exp $
+#	$NetBSD: shlib_version,v 1.18 2018/09/09 07:24:59 maya Exp $
 #	Remember to update distrib/sets/lists/base/shl.* when changing
 #
 # Things to do when bumping major version:
@@ -15,5 +15,8 @@
 #	inspect them for priority inheritance / inter-process synch,
 #	without compat_netbsd32 shims??
 #
+#	use reserved identifiers for things that shouldn't be visible,
+#	e.g. rename pthread__pagesize to __pthread_pagesize,
+#
 major=1
 minor=3



CVS commit: src/lib/libpthread

2018-08-18 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Aug 19 02:10:42 UTC 2018

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Drop a duplicate instruction line

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.151 -r1.152 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.151 src/lib/libpthread/pthread.c:1.152
--- src/lib/libpthread/pthread.c:1.151	Fri Dec  8 09:24:31 2017
+++ src/lib/libpthread/pthread.c	Sun Aug 19 02:10:42 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.151 2017/12/08 09:24:31 kre Exp $	*/
+/*	$NetBSD: pthread.c,v 1.152 2018/08/19 02:10:42 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.151 2017/12/08 09:24:31 kre Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.152 2018/08/19 02:10:42 kamil Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -1322,7 +1322,6 @@ pthread__initmainstack(void)
 
 	for (aux = _dlauxinfo(); aux->a_type != AT_NULL; ++aux) {
 		if (aux->a_type == AT_STACKBASE) {
-			pthread__main->pt_stack.ss_sp = (void *)aux->a_v;
 #ifdef __MACHINE_STACK_GROWS_UP
 			pthread__main->pt_stack.ss_sp = (void *)aux->a_v;
 #else



CVS commit: src/lib/libpthread

2018-07-28 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Jul 28 14:00:19 UTC 2018

Modified Files:
src/lib/libpthread: pthread_cond.3

Log Message:
PR lib/53477 (rudolf at eq.cz) - correct an obvious mistake.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libpthread/pthread_cond.3

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/pthread_cond.3
diff -u src/lib/libpthread/pthread_cond.3:1.8 src/lib/libpthread/pthread_cond.3:1.9
--- src/lib/libpthread/pthread_cond.3:1.8	Sun Oct 22 16:37:24 2017
+++ src/lib/libpthread/pthread_cond.3	Sat Jul 28 14:00:19 2018
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_cond.3,v 1.8 2017/10/22 16:37:24 abhinav Exp $
+.\" $NetBSD: pthread_cond.3,v 1.9 2018/07/28 14:00:19 kre Exp $
 .\"
 .\" Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -128,7 +128,7 @@ The difference between
 and
 .Fn pthread_cond_signal
 is that the former unblocks all threads waiting for the condition variable,
-whereas the latter blocks only one waiting thread.
+whereas the latter unblocks only one waiting thread.
 If no threads are waiting on
 .Fa cond ,
 neither function has any effect.



CVS commit: src/lib/libpthread

2018-06-09 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jun  9 23:45:56 UTC 2018

Modified Files:
src/lib/libpthread: Makefile

Log Message:
But set NOSANITIZER


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/lib/libpthread/Makefile

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.89 src/lib/libpthread/Makefile:1.90
--- src/lib/libpthread/Makefile:1.89	Sat Jun  9 18:41:55 2018
+++ src/lib/libpthread/Makefile	Sat Jun  9 19:45:56 2018
@@ -1,7 +1,7 @@
-#	$NetBSD: Makefile,v 1.89 2018/06/09 22:41:55 christos Exp $
+#	$NetBSD: Makefile,v 1.90 2018/06/09 23:45:56 christos Exp $
 #
 
-#NOSANITIZER=	# defined
+NOSANITIZER=	# defined
 WARNS?=	5
 LIB=	pthread
 



CVS commit: src/lib/libpthread

2018-02-25 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Feb 25 18:51:18 UTC 2018

Modified Files:
src/lib/libpthread: Makefile

Log Message:
remove hard-coded -fomit-frame-pointer for pthread stuff,
let these use the same setting as the rest of the tree.
the performance difference is marginal and this allows
dtrace ustack() to work better.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/lib/libpthread/Makefile

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.87 src/lib/libpthread/Makefile:1.88
--- src/lib/libpthread/Makefile:1.87	Sun Jul  3 14:24:58 2016
+++ src/lib/libpthread/Makefile	Sun Feb 25 18:51:18 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.87 2016/07/03 14:24:58 christos Exp $
+#	$NetBSD: Makefile,v 1.88 2018/02/25 18:51:18 chs Exp $
 #
 
 WARNS?=	5
@@ -90,31 +90,13 @@ SRCS+=		pthread_compat.c
 
 ALIGN_FUNCTIONS=	${${ACTIVE_CC} == "gcc":? -falign-functions=32 :}
 
-.if ${MACHINE_CPU} != "m68k" && ${MACHINE_CPU} != "sh3" && ${MACHINE_ARCH} != "vax"
-OMIT_FRAME_POINTER=	-fomit-frame-pointer
-.else
-OMIT_FRAME_POINTER=
-.endif
-
 # The TSD routines are used in the implementation of profiling, and so
 # can't be profiled themselves.
-COPTS.pthread_specific.c+=	${OMIT_FRAME_POINTER} ${ALIGN_FUNCTIONS}
+COPTS.pthread_specific.c+=	${ALIGN_FUNCTIONS}
 pthread_specific.po: pthread_specific.o
 	${_MKTARGET_CREATE}
 	cp pthread_specific.o pthread_specific.po
 
-# Internal spinlock routines are performance critical.  Don't profile them,
-# it's incompatibile with -fomit-frame-pointer.
-COPTS.pthread_lock.c+=	${OMIT_FRAME_POINTER} ${ALIGN_FUNCTIONS}
-pthread_lock.po: pthread_lock.o
-	${_MKTARGET_CREATE}
-	cp pthread_lock.o pthread_lock.po
-
-COPTS.pthread_mutex.c+=	${OMIT_FRAME_POINTER} ${ALIGN_FUNCTIONS}
-pthread_mutex.po: pthread_mutex.o
-	${_MKTARGET_CREATE}
-	cp pthread_mutex.o pthread_mutex.po
-
 COPTS.pthread.c += -Wno-stack-protector -Wno-format-nonliteral
 COPTS.pthread_attr.c += -Wno-format-nonliteral
 



CVS commit: src/lib/libpthread

2018-02-19 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Feb 20 05:10:52 UTC 2018

Modified Files:
src/lib/libpthread: pthread.h

Log Message:
Remove namespace restriction from pthread_condattr_{g,s}etclock(3)

These functions were marked as _NETBSD_SOURCE when introduced to the
sources. In fact they are regular POSIX threading functions available
since the 2001 standard. There is an older mention about alignment with
"IEEE Std 1003.1j-2000".

This corrects usage of these functions when a source code is compiled
with a POSIX namespace option.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/lib/libpthread/pthread.h

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/pthread.h
diff -u src/lib/libpthread/pthread.h:1.40 src/lib/libpthread/pthread.h:1.41
--- src/lib/libpthread/pthread.h:1.40	Tue Feb  6 20:22:23 2018
+++ src/lib/libpthread/pthread.h	Tue Feb 20 05:10:51 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.h,v 1.40 2018/02/06 20:22:23 christos Exp $	*/
+/*	$NetBSD: pthread.h,v 1.41 2018/02/20 05:10:51 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -135,11 +135,9 @@ int	pthread_cond_timedwait(pthread_cond_
 int	pthread_cond_signal(pthread_cond_t *);
 int	pthread_cond_broadcast(pthread_cond_t *);
 int	pthread_condattr_init(pthread_condattr_t *);
-#if defined(_NETBSD_SOURCE)
 int pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
 int	pthread_condattr_getclock(const pthread_condattr_t * __restrict,
 	clockid_t * __restrict);
-#endif
 int	pthread_condattr_destroy(pthread_condattr_t *);
 #ifdef _PTHREAD_PSHARED
 int	pthread_condattr_getpshared(const pthread_condattr_t * __restrict,



CVS commit: src/lib/libpthread

2018-02-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb  6 20:22:23 UTC 2018

Modified Files:
src/lib/libpthread: pthread.h

Log Message:
fix duplicate declaration of pthread_atfork in unistd.h


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/lib/libpthread/pthread.h

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/pthread.h
diff -u src/lib/libpthread/pthread.h:1.39 src/lib/libpthread/pthread.h:1.40
--- src/lib/libpthread/pthread.h:1.39	Tue Dec 26 12:00:50 2017
+++ src/lib/libpthread/pthread.h	Tue Feb  6 15:22:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.h,v 1.39 2017/12/26 17:00:50 christos Exp $	*/
+/*	$NetBSD: pthread.h,v 1.40 2018/02/06 20:22:23 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -41,7 +41,10 @@
 #include 
 
 __BEGIN_DECLS
+#ifndef __PTHREAD_ATFORK_DECLARED
+#define __PTHREAD_ATFORK_DECLARED
 int	pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
+#endif
 int	pthread_create(pthread_t * __restrict,
 	const pthread_attr_t * __restrict, void *(*)(void *),
 	void * __restrict);



CVS commit: src/lib/libpthread

2017-12-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Dec 26 17:00:51 UTC 2017

Modified Files:
src/lib/libpthread: pthread.h

Log Message:
Needs to be protected since it has a timespec argument. Found by lint(1)


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/lib/libpthread/pthread.h

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/pthread.h
diff -u src/lib/libpthread/pthread.h:1.38 src/lib/libpthread/pthread.h:1.39
--- src/lib/libpthread/pthread.h:1.38	Sun Oct 30 19:26:33 2016
+++ src/lib/libpthread/pthread.h	Tue Dec 26 12:00:50 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.h,v 1.38 2016/10/30 23:26:33 kamil Exp $	*/
+/*	$NetBSD: pthread.h,v 1.39 2017/12/26 17:00:50 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -94,8 +94,10 @@ int	pthread_mutex_destroy(pthread_mutex_
 int	pthread_mutex_lock(pthread_mutex_t *);
 int	pthread_mutex_trylock(pthread_mutex_t *);
 int	pthread_mutex_unlock(pthread_mutex_t *);
+#ifndef __LIBC12_SOURCE__
 int	pthread_mutex_timedlock(pthread_mutex_t * __restrict,
 	const struct timespec * __restrict);
+#endif
 int	pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict,
 	int * __restrict);
 int	pthread_mutex_setprioceiling(pthread_mutex_t * __restrict, int,



CVS commit: src/lib/libpthread

2017-12-08 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Dec  8 09:59:26 UTC 2017

Modified Files:
src/lib/libpthread: pthread_compat.c

Log Message:
Revert last 2 updates - these are, of course, not needed at all...


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libpthread/pthread_compat.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/pthread_compat.c
diff -u src/lib/libpthread/pthread_compat.c:1.5 src/lib/libpthread/pthread_compat.c:1.6
--- src/lib/libpthread/pthread_compat.c:1.5	Fri Dec  8 09:41:16 2017
+++ src/lib/libpthread/pthread_compat.c	Fri Dec  8 09:59:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_compat.c,v 1.5 2017/12/08 09:41:16 kre Exp $	*/
+/*	$NetBSD: pthread_compat.c,v 1.6 2017/12/08 09:59:26 kre Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_compat.c,v 1.5 2017/12/08 09:41:16 kre Exp $");
+__RCSID("$NetBSD: pthread_compat.c,v 1.6 2017/12/08 09:59:26 kre Exp $");
 
 #include 
 #include 
@@ -89,12 +89,7 @@ _lwp_park(clockid_t a, int b, const stru
 const void *e, const void *f)
 {
 
-	if (c != NULL) {
-		struct timespec t = *c;
-
-		return syscall(SYSlwp_park60, a, b, , d, e, f);
-	} else
-		return syscall(SYSlwp_park60, a, b, NULL, d, e, f);
+	return syscall(SYSlwp_park60, a, b, c, d, e, f);
 }
 
 int



CVS commit: src/lib/libpthread

2017-12-08 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Dec  8 09:41:16 UTC 2017

Modified Files:
src/lib/libpthread: pthread_compat.c

Log Message:
This time do _lwp_park() timeout unconsting correctly not just compilably.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libpthread/pthread_compat.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/pthread_compat.c
diff -u src/lib/libpthread/pthread_compat.c:1.4 src/lib/libpthread/pthread_compat.c:1.5
--- src/lib/libpthread/pthread_compat.c:1.4	Fri Dec  8 09:24:31 2017
+++ src/lib/libpthread/pthread_compat.c	Fri Dec  8 09:41:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_compat.c,v 1.4 2017/12/08 09:24:31 kre Exp $	*/
+/*	$NetBSD: pthread_compat.c,v 1.5 2017/12/08 09:41:16 kre Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_compat.c,v 1.4 2017/12/08 09:24:31 kre Exp $");
+__RCSID("$NetBSD: pthread_compat.c,v 1.5 2017/12/08 09:41:16 kre Exp $");
 
 #include 
 #include 
@@ -89,9 +89,12 @@ _lwp_park(clockid_t a, int b, const stru
 const void *e, const void *f)
 {
 
-	struct timespec t = *c;
+	if (c != NULL) {
+		struct timespec t = *c;
 
-	return syscall(SYSlwp_park60, a, b, , d, e, f);
+		return syscall(SYSlwp_park60, a, b, , d, e, f);
+	} else
+		return syscall(SYSlwp_park60, a, b, NULL, d, e, f);
 }
 
 int



CVS commit: src/lib/libpthread

2017-12-08 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Dec  8 09:24:31 UTC 2017

Modified Files:
src/lib/libpthread: pthread.c pthread_compat.c pthread_mutex.c

Log Message:
Deal with more lwp_park() timestamp unconsting


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libpthread/pthread_compat.c
cvs rdiff -u -r1.63 -r1.64 src/lib/libpthread/pthread_mutex.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.150 src/lib/libpthread/pthread.c:1.151
--- src/lib/libpthread/pthread.c:1.150	Tue Jul 11 15:21:35 2017
+++ src/lib/libpthread/pthread.c	Fri Dec  8 09:24:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.150 2017/07/11 15:21:35 joerg Exp $	*/
+/*	$NetBSD: pthread.c,v 1.151 2017/12/08 09:24:31 kre Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.150 2017/07/11 15:21:35 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.151 2017/12/08 09:24:31 kre Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -1202,8 +1202,8 @@ pthread__park(pthread_t self, pthread_mu
 		 * If we deferred unparking a thread, arrange to
 		 * have _lwp_park() restart it before blocking.
 		 */
-		error = _lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, abstime,
-		self->pt_unpark, hint, hint);
+		error = _lwp_park(CLOCK_REALTIME, TIMER_ABSTIME,
+		__UNCONST(abstime), self->pt_unpark, hint, hint);
 		self->pt_unpark = 0;
 		if (error != 0) {
 			switch (rv = errno) {

Index: src/lib/libpthread/pthread_compat.c
diff -u src/lib/libpthread/pthread_compat.c:1.3 src/lib/libpthread/pthread_compat.c:1.4
--- src/lib/libpthread/pthread_compat.c:1.3	Fri Jan 31 20:44:01 2014
+++ src/lib/libpthread/pthread_compat.c	Fri Dec  8 09:24:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_compat.c,v 1.3 2014/01/31 20:44:01 christos Exp $	*/
+/*	$NetBSD: pthread_compat.c,v 1.4 2017/12/08 09:24:31 kre Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_compat.c,v 1.3 2014/01/31 20:44:01 christos Exp $");
+__RCSID("$NetBSD: pthread_compat.c,v 1.4 2017/12/08 09:24:31 kre Exp $");
 
 #include 
 #include 
@@ -89,7 +89,9 @@ _lwp_park(clockid_t a, int b, const stru
 const void *e, const void *f)
 {
 
-	return syscall(SYSlwp_park60, a, b, c, d, e, f);
+	struct timespec t = *c;
+
+	return syscall(SYSlwp_park60, a, b, , d, e, f);
 }
 
 int

Index: src/lib/libpthread/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.63 src/lib/libpthread/pthread_mutex.c:1.64
--- src/lib/libpthread/pthread_mutex.c:1.63	Mon Oct 31 23:53:12 2016
+++ src/lib/libpthread/pthread_mutex.c	Fri Dec  8 09:24:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.63 2016/10/31 23:53:12 christos Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.64 2017/12/08 09:24:31 kre Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.63 2016/10/31 23:53:12 christos Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.64 2017/12/08 09:24:31 kre Exp $");
 
 #include 
 #include 
@@ -394,8 +394,9 @@ pthread__mutex_lock_slow(pthread_mutex_t
 		 */
 		while (self->pt_mutexwait) {
 			self->pt_blocking++;
-			error = _lwp_park(CLOCK_REALTIME, TIMER_ABSTIME, ts,
-			self->pt_unpark, __UNVOLATILE(>ptm_waiters),
+			error = _lwp_park(CLOCK_REALTIME, TIMER_ABSTIME,
+			__UNCONST(ts), self->pt_unpark,
+			__UNVOLATILE(>ptm_waiters),
 			__UNVOLATILE(>ptm_waiters));
 			self->pt_unpark = 0;
 			self->pt_blocking--;



CVS commit: src/lib/libpthread

2017-12-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Dec  8 03:08:19 UTC 2017

Modified Files:
src/lib/libpthread: pthread_cond.c

Log Message:
unconst the timestamp


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/lib/libpthread/pthread_cond.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/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.64 src/lib/libpthread/pthread_cond.c:1.65
--- src/lib/libpthread/pthread_cond.c:1.64	Sun Jul  3 10:24:58 2016
+++ src/lib/libpthread/pthread_cond.c	Thu Dec  7 22:08:19 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.64 2016/07/03 14:24:58 christos Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.65 2017/12/08 03:08:19 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_cond.c,v 1.64 2016/07/03 14:24:58 christos Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.65 2017/12/08 03:08:19 christos Exp $");
 
 #include 
 #include 
@@ -166,8 +166,9 @@ pthread_cond_timedwait(pthread_cond_t *c
 		self->pt_willpark = 0;
 		self->pt_blocking++;
 		do {
-			retval = _lwp_park(clkid, TIMER_ABSTIME, abstime,
-			self->pt_unpark, __UNVOLATILE(>ptm_waiters),
+			retval = _lwp_park(clkid, TIMER_ABSTIME,
+			__UNCONST(abstime), self->pt_unpark,
+			__UNVOLATILE(>ptm_waiters),
 			__UNVOLATILE(>ptm_waiters));
 			self->pt_unpark = 0;
 		} while (retval == -1 && errno == ESRCH);



CVS commit: src/lib/libpthread

2017-10-22 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Oct 23 01:03:23 UTC 2017

Modified Files:
src/lib/libpthread: pthread.3 pthread_attr_getdetachstate.3
pthread_attr_getscope.3 pthread_attr_getstack.3 pthread_self.3

Log Message:
Remove superfluous Tn.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libpthread/pthread.3
cvs rdiff -u -r1.3 -r1.4 src/lib/libpthread/pthread_attr_getdetachstate.3 \
src/lib/libpthread/pthread_attr_getscope.3
cvs rdiff -u -r1.7 -r1.8 src/lib/libpthread/pthread_attr_getstack.3
cvs rdiff -u -r1.4 -r1.5 src/lib/libpthread/pthread_self.3

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/pthread.3
diff -u src/lib/libpthread/pthread.3:1.17 src/lib/libpthread/pthread.3:1.18
--- src/lib/libpthread/pthread.3:1.17	Wed Feb  8 03:44:41 2017
+++ src/lib/libpthread/pthread.3	Mon Oct 23 01:03:23 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread.3,v 1.17 2017/02/08 03:44:41 kamil Exp $
+.\"	$NetBSD: pthread.3,v 1.18 2017/10/23 01:03:23 wiz Exp $
 .\"
 .\" Copyright (c) 2003, 2007, 2009 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -46,9 +46,8 @@
 .Sh DESCRIPTION
 The
 .Nm
-library provides an implementation of the standard
-.Tn POSIX
-threads library.
+library provides an implementation of the standard POSIX threads
+library.
 .Pp
 The
 .Nx
@@ -63,8 +62,7 @@ In order to remain compatible with futur
 .Nx
 releases, programs must be linked against the dynamic version of the
 thread library.
-Statically linked programs using the
-.Tn POSIX
+Statically linked programs using the POSIX
 threads framework may not work when run on a future version of the system.
 .Sh FUNCTIONS
 The following functions comprise the core of the

Index: src/lib/libpthread/pthread_attr_getdetachstate.3
diff -u src/lib/libpthread/pthread_attr_getdetachstate.3:1.3 src/lib/libpthread/pthread_attr_getdetachstate.3:1.4
--- src/lib/libpthread/pthread_attr_getdetachstate.3:1.3	Sun Oct 22 15:48:11 2017
+++ src/lib/libpthread/pthread_attr_getdetachstate.3	Mon Oct 23 01:03:23 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread_attr_getdetachstate.3,v 1.3 2017/10/22 15:48:11 abhinav Exp $
+.\"	$NetBSD: pthread_attr_getdetachstate.3,v 1.4 2017/10/23 01:03:23 wiz Exp $
 .\"
 .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -89,9 +89,7 @@ and the thread will not be joined.
 .El
 .Pp
 If the thread is created as detached,
-it is an error to use the thread
-.Tn ID
-with
+it is an error to use the thread ID with
 .Xr pthread_detach 3
 or
 .Xr pthread_join 3 .
Index: src/lib/libpthread/pthread_attr_getscope.3
diff -u src/lib/libpthread/pthread_attr_getscope.3:1.3 src/lib/libpthread/pthread_attr_getscope.3:1.4
--- src/lib/libpthread/pthread_attr_getscope.3:1.3	Sun Oct 22 16:37:24 2017
+++ src/lib/libpthread/pthread_attr_getscope.3	Mon Oct 23 01:03:23 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_attr_getscope.3,v 1.3 2017/10/22 16:37:24 abhinav Exp $
+.\" $NetBSD: pthread_attr_getscope.3,v 1.4 2017/10/23 01:03:23 wiz Exp $
 .\"
 .\" Copyright (c) 2010 Jukka Ruohonen 
 .\" All rights reserved.
@@ -57,8 +57,7 @@ It is only possible to set the scope of 
 There are two possible contention scopes:
 .Bl -tag -width PTHREAD_SCOPE_PROCESS -offset 2n
 .It Dv PTHREAD_SCOPE_SYSTEM
-The thread will contend for
-.Tn CPU
+The thread will contend for CPU
 resources with all other processes and threads in the system.
 Generally this means that the user thread is bound directly to the
 kernel scheduling for its entire lifetime.
@@ -67,8 +66,7 @@ The thread will contend with other threa
 In general, this means that all
 .Dv PTHREAD_SCOPE_PROCESS
 threads are grouped together and this group of threads contends for
-.Tn CPU
-resources.
+CPU resources.
 This is commonly seen to require a hybrid
 .Pq Dq M:N
 threading model in order to multiplex the user and kernel space scheduling.

Index: src/lib/libpthread/pthread_attr_getstack.3
diff -u src/lib/libpthread/pthread_attr_getstack.3:1.7 src/lib/libpthread/pthread_attr_getstack.3:1.8
--- src/lib/libpthread/pthread_attr_getstack.3:1.7	Sun Oct 22 16:37:24 2017
+++ src/lib/libpthread/pthread_attr_getstack.3	Mon Oct 23 01:03:23 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread_attr_getstack.3,v 1.7 2017/10/22 16:37:24 abhinav Exp $
+.\"	$NetBSD: pthread_attr_getstack.3,v 1.8 2017/10/23 01:03:23 wiz Exp $
 .\"
 .\" Copyright (c) 2010 Jukka Ruohonen 
 .\" All rights reserved.
@@ -110,8 +110,7 @@ and the use of these functions should be
 At least few potential caveats can be mentioned.
 .Bl -bullet -offset 2n
 .It
-There is a certain degree of ambiguity in the
-.Tn POSIX
+There is a certain degree of ambiguity in the POSIX
 standard with respect to thread stack.
 .It
 The exact behavior of the functions may vary

Index: src/lib/libpthread/pthread_self.3
diff -u src/lib/libpthread/pthread_self.3:1.4 

CVS commit: src/lib/libpthread

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 18:37:01 UTC 2017

Modified Files:
src/lib/libpthread: pthread_barrierattr.3

Log Message:
All the four functions described in the man page conform to POSIX.1


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libpthread/pthread_barrierattr.3

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/pthread_barrierattr.3
diff -u src/lib/libpthread/pthread_barrierattr.3:1.12 src/lib/libpthread/pthread_barrierattr.3:1.13
--- src/lib/libpthread/pthread_barrierattr.3:1.12	Sun Oct 22 18:26:46 2017
+++ src/lib/libpthread/pthread_barrierattr.3	Sun Oct 22 18:37:01 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_barrierattr.3,v 1.12 2017/10/22 18:26:46 abhinav Exp $
+.\" $NetBSD: pthread_barrierattr.3,v 1.13 2017/10/22 18:37:01 abhinav Exp $
 .\"
 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -103,7 +103,7 @@ is invalid.
 .Sh SEE ALSO
 .Xr pthread_barrier_init 3
 .Sh STANDARDS
-Both functions conform to
+These functions conform to
 .St -p1003.1-2001 .
 .Sh BUGS
 The



CVS commit: src/lib/libpthread

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 18:26:46 UTC 2017

Modified Files:
src/lib/libpthread: pthread_barrierattr.3

Log Message:
Add missing word in the sentence


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libpthread/pthread_barrierattr.3

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/pthread_barrierattr.3
diff -u src/lib/libpthread/pthread_barrierattr.3:1.11 src/lib/libpthread/pthread_barrierattr.3:1.12
--- src/lib/libpthread/pthread_barrierattr.3:1.11	Tue Jul  5 10:04:17 2016
+++ src/lib/libpthread/pthread_barrierattr.3	Sun Oct 22 18:26:46 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_barrierattr.3,v 1.11 2016/07/05 10:04:17 wiz Exp $
+.\" $NetBSD: pthread_barrierattr.3,v 1.12 2017/10/22 18:26:46 abhinav Exp $
 .\"
 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -93,7 +93,7 @@ The
 .Fn pthread_barrierattr_getpshared
 and
 .Fn pthread_barrierattr_setpshared
-may fail if:
+functions may fail if:
 .Bl -tag -width Er
 .It Bq Er EINVAL
 The value specified by



CVS commit: src/lib/libpthread

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 16:37:24 UTC 2017

Modified Files:
src/lib/libpthread: pthread_attr_getguardsize.3
pthread_attr_getinheritsched.3 pthread_attr_getname_np.3
pthread_attr_getschedparam.3 pthread_attr_getscope.3
pthread_attr_getstack.3 pthread_cond.3 pthread_getname_np.3
pthread_getspecific.3 pthread_key_create.3 pthread_mutex.3
pthread_rwlock.3 pthread_spin.3

Log Message:
Add missing function names in the NAME section for rest of the man pages in 
libpthread


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libpthread/pthread_attr_getguardsize.3 \
src/lib/libpthread/pthread_getname_np.3
cvs rdiff -u -r1.3 -r1.4 src/lib/libpthread/pthread_attr_getinheritsched.3
cvs rdiff -u -r1.6 -r1.7 src/lib/libpthread/pthread_attr_getname_np.3 \
src/lib/libpthread/pthread_attr_getstack.3 \
src/lib/libpthread/pthread_rwlock.3
cvs rdiff -u -r1.2 -r1.3 src/lib/libpthread/pthread_attr_getschedparam.3 \
src/lib/libpthread/pthread_attr_getscope.3
cvs rdiff -u -r1.7 -r1.8 src/lib/libpthread/pthread_cond.3
cvs rdiff -u -r1.5 -r1.6 src/lib/libpthread/pthread_getspecific.3 \
src/lib/libpthread/pthread_spin.3
cvs rdiff -u -r1.8 -r1.9 src/lib/libpthread/pthread_key_create.3
cvs rdiff -u -r1.9 -r1.10 src/lib/libpthread/pthread_mutex.3

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/pthread_attr_getguardsize.3
diff -u src/lib/libpthread/pthread_attr_getguardsize.3:1.4 src/lib/libpthread/pthread_attr_getguardsize.3:1.5
--- src/lib/libpthread/pthread_attr_getguardsize.3:1.4	Sun Jul  2 16:41:32 2017
+++ src/lib/libpthread/pthread_attr_getguardsize.3	Sun Oct 22 16:37:24 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread_attr_getguardsize.3,v 1.4 2017/07/02 16:41:32 joerg Exp $
+.\"	$NetBSD: pthread_attr_getguardsize.3,v 1.5 2017/10/22 16:37:24 abhinav Exp $
 .\"
 .\" Copyright (c) 2010 Jukka Ruohonen 
 .\" All rights reserved.
@@ -29,7 +29,8 @@
 .Dt PTHREAD_ATTR_GETGUARDSIZE 3
 .Os
 .Sh NAME
-.Nm pthread_attr_getguardsize
+.Nm pthread_attr_getguardsize ,
+.Nm pthread_attr_setguardsize
 .Nd get and set thread guard size
 .Sh LIBRARY
 .Lb libpthread
Index: src/lib/libpthread/pthread_getname_np.3
diff -u src/lib/libpthread/pthread_getname_np.3:1.4 src/lib/libpthread/pthread_getname_np.3:1.5
--- src/lib/libpthread/pthread_getname_np.3:1.4	Fri Jul  9 07:31:01 2010
+++ src/lib/libpthread/pthread_getname_np.3	Sun Oct 22 16:37:24 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_getname_np.3,v 1.4 2010/07/09 07:31:01 jruoho Exp $
+.\" $NetBSD: pthread_getname_np.3,v 1.5 2017/10/22 16:37:24 abhinav Exp $
 .\"
 .\" Copyright (c)2007 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -29,7 +29,8 @@
 .Dt PTHREAD_GETNAME_NP 3
 .Os
 .Sh NAME
-.Nm pthread_getname_np
+.Nm pthread_getname_np ,
+.Nm pthread_setname_np
 .Nd get and set descriptive name of a thread
 .\" 
 .Sh LIBRARY

Index: src/lib/libpthread/pthread_attr_getinheritsched.3
diff -u src/lib/libpthread/pthread_attr_getinheritsched.3:1.3 src/lib/libpthread/pthread_attr_getinheritsched.3:1.4
--- src/lib/libpthread/pthread_attr_getinheritsched.3:1.3	Fri May 10 21:06:14 2013
+++ src/lib/libpthread/pthread_attr_getinheritsched.3	Sun Oct 22 16:37:24 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread_attr_getinheritsched.3,v 1.3 2013/05/10 21:06:14 christos Exp $
+.\"	$NetBSD: pthread_attr_getinheritsched.3,v 1.4 2017/10/22 16:37:24 abhinav Exp $
 .\"
 .\" Copyright (c) 2010 Jukka Ruohonen 
 .\" All rights reserved.
@@ -29,7 +29,8 @@
 .Dt PTHREAD_ATTR_GETINHERITSCHED 3
 .Os
 .Sh NAME
-.Nm pthread_attr_getinheritsched
+.Nm pthread_attr_getinheritsched ,
+.Nm pthread_attr_setinheritsched
 .Nd get and set
 .Dq inheritsched
 attribute

Index: src/lib/libpthread/pthread_attr_getname_np.3
diff -u src/lib/libpthread/pthread_attr_getname_np.3:1.6 src/lib/libpthread/pthread_attr_getname_np.3:1.7
--- src/lib/libpthread/pthread_attr_getname_np.3:1.6	Fri Jul  9 10:55:57 2010
+++ src/lib/libpthread/pthread_attr_getname_np.3	Sun Oct 22 16:37:24 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_attr_getname_np.3,v 1.6 2010/07/09 10:55:57 jruoho Exp $
+.\" $NetBSD: pthread_attr_getname_np.3,v 1.7 2017/10/22 16:37:24 abhinav Exp $
 .\"
 .\" Copyright (c)2007 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -29,7 +29,8 @@
 .Dt PTHREAD_ATTR_GETNAME_NP 3
 .Os
 .Sh NAME
-.Nm pthread_attr_getname_np
+.Nm pthread_attr_getname_np ,
+.Nm pthread_attr_setname_np
 .Nd get and set descriptive name of an attribute
 .\" 
 .Sh LIBRARY
Index: src/lib/libpthread/pthread_attr_getstack.3
diff -u src/lib/libpthread/pthread_attr_getstack.3:1.6 src/lib/libpthread/pthread_attr_getstack.3:1.7
--- 

CVS commit: src/lib/libpthread

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 16:15:02 UTC 2017

Modified Files:
src/lib/libpthread: pthread_barrier.3

Log Message:
Remove description of pthread_barrierattr_getpshared and 
pthread_barrierattr_setpshared

These functions are described in pthread_barrierattr(3) man page


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libpthread/pthread_barrier.3

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/pthread_barrier.3
diff -u src/lib/libpthread/pthread_barrier.3:1.7 src/lib/libpthread/pthread_barrier.3:1.8
--- src/lib/libpthread/pthread_barrier.3:1.7	Sun Oct 22 16:09:22 2017
+++ src/lib/libpthread/pthread_barrier.3	Sun Oct 22 16:15:02 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_barrier.3,v 1.7 2017/10/22 16:09:22 abhinav Exp $
+.\" $NetBSD: pthread_barrier.3,v 1.8 2017/10/22 16:15:02 abhinav Exp $
 .\"
 .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -25,7 +25,7 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\" 
-.Dd June 12, 2016
+.Dd October 22, 2017
 .Dt PTHREAD_BARRIER 3
 .Os
 .Sh NAME
@@ -45,12 +45,6 @@
 .Fn pthread_barrier_destroy "pthread_barrier_t *barrier"
 .Ft int
 .Fn pthread_barrier_wait "pthread_barrier_t *barrier"
-.Ft int
-.Fn pthread_barrierattr_getpshared "const pthread_barrierattr_t * __restrict attr" \
-"int * __restrict pshared"
-.Ft int
-.Fn pthread_barrierattr_setpshared "pthread_barrierattr_t * attr" \
-"int pshared"
 .\" 
 .Sh DESCRIPTION
 The
@@ -96,16 +90,7 @@ call have called
 all threads will wake up, return from their respective
 .Fn pthread_barrier_wait
 calls and continue execution.
-.Pp
 .\" -
-The
-.Fn pthread_barrierattr_getpshared
-function shall obtain the value of the process-shared attribute from the
-attributes object referenced by attr.
-The
-.Fn pthread_barrierattr_setpshared
-function shall set the process-shared attribute in an initialized attributes
-object referenced by attr.
 .\" 
 .Sh RETURN VALUES
 If successful,
@@ -132,21 +117,6 @@ It is the responsibility of this thread 
 and atomicity of any updates to shared data with respect to the
 other threads participating in the barrier.
 In the case of failure, an error value will be returned.
-.Pp
-.\" -
-If successful,
-.Fn pthread_barrierattr_getpshared
-shall return zero and store the value of the process-shared attribute of attr
-into the object referenced by the
-.Fa pshared
-parameter.
-Otherwise, an error number shall be returned to indicate the error.
-.Pp
-.\" -
-If successful,
-.Fn pthread_barrierattr_setpshared
-shall return zero;
-Otherwise, an error number shall be returned to indicate the error.
 .\" 
 .Sh ERRORS
 The
@@ -186,20 +156,6 @@ The value specified by
 .Fa barrier
 is invalid.
 .El
-.Pp
-.\" -
-The
-.Fn pthread_barrierattr_setpshared
-function and
-the
-.Fn pthread_barrierattr_getpshared
-function may fail if:
-.Bl -tag -width Er
-.It Bq Er EINVAL
-The value specified by
-.Fa attr
-is invalid.
-.El
 .\" ---
 .Sh SEE ALSO
 .Xr pthread_barrierattr 3 ,
@@ -208,10 +164,3 @@ is invalid.
 .Sh STANDARDS
 These functions conform to
 .St -p1003.1-2001 .
-.Sh BUGS
-The
-.Fn pthread_barrierattr_getpshared
-and
-.Fn pthread_barrierattr_setpshared
-functions are hidden by default since only thread shared attributes
-are supported.



CVS commit: src/lib/libpthread

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 16:09:22 UTC 2017

Modified Files:
src/lib/libpthread: pthread_barrier.3

Log Message:
Add rest of the pthread_barrier functions in the NAME section


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libpthread/pthread_barrier.3

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/pthread_barrier.3
diff -u src/lib/libpthread/pthread_barrier.3:1.6 src/lib/libpthread/pthread_barrier.3:1.7
--- src/lib/libpthread/pthread_barrier.3:1.6	Tue Jul  5 10:04:17 2016
+++ src/lib/libpthread/pthread_barrier.3	Sun Oct 22 16:09:22 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_barrier.3,v 1.6 2016/07/05 10:04:17 wiz Exp $
+.\" $NetBSD: pthread_barrier.3,v 1.7 2017/10/22 16:09:22 abhinav Exp $
 .\"
 .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -29,7 +29,10 @@
 .Dt PTHREAD_BARRIER 3
 .Os
 .Sh NAME
-.Nm pthread_barrier
+.Nm pthread_barrier ,
+.Nm pthread_barrier_init ,
+.Nm pthread_barrier_destroy ,
+.Nm pthread_barrier_wait
 .Nd barrier interface
 .Sh LIBRARY
 .Lb libpthread



CVS commit: src/lib/libpthread

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 15:48:11 UTC 2017

Modified Files:
src/lib/libpthread: pthread_attr_getdetachstate.3

Log Message:
Add pthread_attr_setdetachstate to NAME section


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libpthread/pthread_attr_getdetachstate.3

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/pthread_attr_getdetachstate.3
diff -u src/lib/libpthread/pthread_attr_getdetachstate.3:1.2 src/lib/libpthread/pthread_attr_getdetachstate.3:1.3
--- src/lib/libpthread/pthread_attr_getdetachstate.3:1.2	Fri Jul  9 08:51:28 2010
+++ src/lib/libpthread/pthread_attr_getdetachstate.3	Sun Oct 22 15:48:11 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread_attr_getdetachstate.3,v 1.2 2010/07/09 08:51:28 jruoho Exp $
+.\"	$NetBSD: pthread_attr_getdetachstate.3,v 1.3 2017/10/22 15:48:11 abhinav Exp $
 .\"
 .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -57,7 +57,8 @@
 .Dt PTHREAD_ATTR_GETDETACHSTATE 3
 .Os
 .Sh NAME
-.Nm pthread_attr_getdetachstate
+.Nm pthread_attr_getdetachstate ,
+.Nm pthread_attr_setdetachstate
 .Nd get and set the
 .Dq detach state
 attribute



CVS commit: src/lib/libpthread

2017-10-22 Thread Abhinav Upadhyay
Module Name:src
Committed By:   abhinav
Date:   Sun Oct 22 15:44:21 UTC 2017

Modified Files:
src/lib/libpthread: pthread_attr_get_np.3

Log Message:
Add pthread_getattr_np to the NAME section


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libpthread/pthread_attr_get_np.3

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/pthread_attr_get_np.3
diff -u src/lib/libpthread/pthread_attr_get_np.3:1.4 src/lib/libpthread/pthread_attr_get_np.3:1.5
--- src/lib/libpthread/pthread_attr_get_np.3:1.4	Fri Aug  6 05:35:42 2010
+++ src/lib/libpthread/pthread_attr_get_np.3	Sun Oct 22 15:44:21 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_attr_get_np.3,v 1.4 2010/08/06 05:35:42 christos Exp $
+.\" $NetBSD: pthread_attr_get_np.3,v 1.5 2017/10/22 15:44:21 abhinav Exp $
 .\"
 .\" Copyright (c) 2010 Jukka Ruohonen 
 .\" All rights reserved.
@@ -29,7 +29,8 @@
 .Dt PTHREAD_ATTR_GET_NP 3
 .Os
 .Sh NAME
-.Nm pthread_attr_get_np
+.Nm pthread_attr_get_np ,
+.Nm pthread_getattr_np
 .Nd get attributes of existing thread
 .Sh LIBRARY
 .Lb libpthread



CVS commit: src/lib/libpthread

2017-09-09 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sat Sep  9 23:21:45 UTC 2017

Modified Files:
src/lib/libpthread: pthread_types.h

Log Message:
Support  on C89 compilers

Clang 5.0.0(svn) reports warnings on  for C99 constructs
when used with strict -std=c89.

Restrict designated initializers usage to C99 or newer code.
C89 and C++ will share the same code without extension of designated
initializers.

PR 52285


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libpthread/pthread_types.h

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/pthread_types.h
diff -u src/lib/libpthread/pthread_types.h:1.22 src/lib/libpthread/pthread_types.h:1.23
--- src/lib/libpthread/pthread_types.h:1.22	Wed Jul 20 21:02:04 2016
+++ src/lib/libpthread/pthread_types.h	Sat Sep  9 23:21:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_types.h,v 1.22 2016/07/20 21:02:04 christos Exp $	*/
+/*	$NetBSD: pthread_types.h,v 1.23 2017/09/09 23:21:45 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -114,10 +114,10 @@ struct	__pthread_mutex_st {
 	__pthread_spin_t ptm_errorcheck;
 #ifdef __CPU_SIMPLE_LOCK_PAD
 	uint8_t		ptm_pad1[3];
-#ifdef __cplusplus
-#define _PTHREAD_MUTEX_PAD(a)	{ 0, 0, 0 },
-#else
+#if (__STDC_VERSION__ - 0) >= 199901L
 #define _PTHREAD_MUTEX_PAD(a)	.a = { 0, 0, 0 },
+#else
+#define _PTHREAD_MUTEX_PAD(a)	{ 0, 0, 0 },
 #endif
 #else
 #define _PTHREAD_MUTEX_PAD(a)
@@ -138,12 +138,12 @@ struct	__pthread_mutex_st {
 #define	_PT_MUTEX_MAGIC	0x0003
 #define	_PT_MUTEX_DEAD	0xDEAD0003
 
-#ifdef __cplusplus
-#define _PTHREAD_MUTEX_INI(a, b) b
-#define _PTHREAD_MUTEX_UNI(a) { 0 }
-#else
+#if (__STDC_VERSION__ - 0) >= 199901L
 #define _PTHREAD_MUTEX_INI(a, b) .a = b
 #define _PTHREAD_MUTEX_UNI(a) .a = 0
+#else
+#define _PTHREAD_MUTEX_INI(a, b) b
+#define _PTHREAD_MUTEX_UNI(a) { 0 }
 #endif
 
 #define _PTHREAD_MUTEX_INITIALIZER {	\



CVS commit: src/lib/libpthread

2017-08-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Aug  1 12:31:45 UTC 2017

Modified Files:
src/lib/libpthread: pthread_attr.c

Log Message:
pthread__attr_init_private:
malloc+memset -> calloc. Also initialize all values to the proper
defaults.
This fixes the "rustc panic" discussed on pkgsrc-users.
OK: joerg


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/lib/libpthread/pthread_attr.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/pthread_attr.c
diff -u src/lib/libpthread/pthread_attr.c:1.17 src/lib/libpthread/pthread_attr.c:1.18
--- src/lib/libpthread/pthread_attr.c:1.17	Sun Jul  2 16:41:32 2017
+++ src/lib/libpthread/pthread_attr.c	Tue Aug  1 12:31:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_attr.c,v 1.17 2017/07/02 16:41:32 joerg Exp $	*/
+/*	$NetBSD: pthread_attr.c,v 1.18 2017/08/01 12:31:45 martin Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_attr.c,v 1.17 2017/07/02 16:41:32 joerg Exp $");
+__RCSID("$NetBSD: pthread_attr.c,v 1.18 2017/08/01 12:31:45 martin Exp $");
 
 #include 
 #include 
@@ -58,11 +58,12 @@ pthread__attr_init_private(pthread_attr_
 	if ((p = attr->pta_private) != NULL)
 		return p;
 
-	p = malloc(sizeof(*p));
+	p = calloc(1, sizeof(*p));
 	if (p != NULL) {
-		memset(p, 0, sizeof(*p));
 		attr->pta_private = p;
 		p->ptap_policy = SCHED_OTHER;
+		p->ptap_stacksize = pthread__stacksize;
+		p->ptap_guardsize = pthread__guardsize;
 	}
 	return p;
 }



CVS commit: src/lib/libpthread/arch/arm

2017-07-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Jul 17 20:24:07 UTC 2017

Modified Files:
src/lib/libpthread/arch/arm: pthread_md.h

Log Message:
Typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libpthread/arch/arm/pthread_md.h

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/arch/arm/pthread_md.h
diff -u src/lib/libpthread/arch/arm/pthread_md.h:1.9 src/lib/libpthread/arch/arm/pthread_md.h:1.10
--- src/lib/libpthread/arch/arm/pthread_md.h:1.9	Thu Aug 15 22:37:29 2013
+++ src/lib/libpthread/arch/arm/pthread_md.h	Mon Jul 17 20:24:07 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_md.h,v 1.9 2013/08/15 22:37:29 matt Exp $	*/
+/*	$NetBSD: pthread_md.h,v 1.10 2017/07/17 20:24:07 skrll Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -72,7 +72,7 @@ pthread__sp(void)
 	(ucp)->uc_mcontext.__gregs[_REG_PC] =\
 	 ((ucp)->uc_mcontext.__gregs[_REG_PC] & 0x3fc) | 0x0;
 #else
-/* Set CPSR to PSR_USE32_MODE (0x10) from arm/armreg.h */
+/* Set CPSR to PSR_USR32_MODE (0x10) from arm/armreg.h */
 #define _INITCONTEXT_U_MD(ucp)		\
 	(ucp)->uc_mcontext.__gregs[_REG_CPSR] = 0x10;
 #endif



CVS commit: src/lib/libpthread

2017-07-09 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jul  9 20:21:08 UTC 2017

Modified Files:
src/lib/libpthread: pthread_tsd.c

Log Message:
PR/52386: Use the number of iterations we document.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libpthread/pthread_tsd.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/pthread_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.15 src/lib/libpthread/pthread_tsd.c:1.16
--- src/lib/libpthread/pthread_tsd.c:1.15	Tue Aug 25 09:46:23 2015
+++ src/lib/libpthread/pthread_tsd.c	Sun Jul  9 16:21:08 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_tsd.c,v 1.15 2015/08/25 13:46:23 pooka Exp $	*/
+/*	$NetBSD: pthread_tsd.c,v 1.16 2017/07/09 20:21:08 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_tsd.c,v 1.15 2015/08/25 13:46:23 pooka Exp $");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.16 2017/07/09 20:21:08 christos Exp $");
 
 /* Functions and structures dealing with thread-specific data */
 #include 
@@ -332,7 +332,8 @@ pthread__destroy_tsd(pthread_t self)
 	 * a while.''
 	 */
 
-	iterations = 4; /* We're not required to try very hard */
+	/* We're not required to try very hard */
+	iterations = PTHREAD_DESTRUCTOR_ITERATIONS;
 	do {
 		done = 1;
 		for (i = 0; i < pthread_keys_max; i++) {
@@ -356,7 +357,7 @@ pthread__destroy_tsd(pthread_t self)
 (*destructor)(val);
 			}
 		}
-	} while (!done && iterations--);
+	} while (!done && --iterations);
 
 	self->pt_havespecific = 0;
 	pthread_mutex_lock(>pt_lock);



CVS commit: src/lib/libpthread

2017-07-02 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Jul  2 17:13:08 UTC 2017

Modified Files:
src/lib/libpthread: pthread.c

Log Message:
Do not look at environmental variables for suid/guid binaries.


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/lib/libpthread/pthread.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/pthread.c
diff -u src/lib/libpthread/pthread.c:1.148 src/lib/libpthread/pthread.c:1.149
--- src/lib/libpthread/pthread.c:1.148	Sun Jul  2 16:41:32 2017
+++ src/lib/libpthread/pthread.c	Sun Jul  2 17:13:07 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.c,v 1.148 2017/07/02 16:41:32 joerg Exp $	*/
+/*	$NetBSD: pthread.c,v 1.149 2017/07/02 17:13:07 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread.c,v 1.148 2017/07/02 16:41:32 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.149 2017/07/02 17:13:07 joerg Exp $");
 
 #define	__EXPOSE_STACK	1
 
@@ -1386,6 +1386,9 @@ pthread__getenv(const char *name)
 	extern char **environ;
 	size_t l_name, offset;
 
+	if (issetugid())
+		return (NULL);
+
 	l_name = strlen(name);
 	for (offset = 0; environ[offset] != NULL; offset++) {
 		if (strncmp(name, environ[offset], l_name) == 0 &&



CVS commit: src/lib/libpthread

2017-03-28 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Tue Mar 28 17:42:52 UTC 2017

Modified Files:
src/lib/libpthread: pthread_condattr.3

Log Message:
Remove outdated CAVEATS.

Not sure everything is standards compliant, but I've been told non-default
values are supported and pshared exists.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libpthread/pthread_condattr.3

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/pthread_condattr.3
diff -u src/lib/libpthread/pthread_condattr.3:1.11 src/lib/libpthread/pthread_condattr.3:1.12
--- src/lib/libpthread/pthread_condattr.3:1.11	Tue Jul  5 10:04:17 2016
+++ src/lib/libpthread/pthread_condattr.3	Tue Mar 28 17:42:52 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_condattr.3,v 1.11 2016/07/05 10:04:17 wiz Exp $
+.\" $NetBSD: pthread_condattr.3,v 1.12 2017/03/28 17:42:52 maya Exp $
 .\"
 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -50,7 +50,7 @@
 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\" $FreeBSD: src/lib/libpthread/man/pthread_condattr.3,v 1.10 2002/09/16 19:29:28 mini Exp $
-.Dd June 12, 2016
+.Dd March 28, 2017
 .Dt PTHREAD_CONDATTR 3
 .Os
 .Sh NAME
@@ -158,14 +158,6 @@ is invalid.
 .Sh STANDARDS
 Both functions conform to
 .St -p1003.1-2001 .
-.Sh CAVEATS
-The usefulness of the functions is questionable as the
-.Nx
-implementation does not support any non-default attributes.
-These functions do not conform to the
-.St -p1003.1-2008
-revision of the standard, which mandates two additional attributes,
-the clock attribute and the process-shared attribute.
 .Sh BUGS
 The
 .Fn pthread_condattr_getpshared



CVS commit: src/lib/libpthread

2017-02-02 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Thu Feb  2 10:48:22 UTC 2017

Modified Files:
src/lib/libpthread: pthread_mutexattr.3

Log Message:
Fix a typo : pthread_mutexaddr_init -> pthread_mutexattr_init.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libpthread/pthread_mutexattr.3

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/pthread_mutexattr.3
diff -u src/lib/libpthread/pthread_mutexattr.3:1.13 src/lib/libpthread/pthread_mutexattr.3:1.14
--- src/lib/libpthread/pthread_mutexattr.3:1.13	Tue Jul  5 10:04:17 2016
+++ src/lib/libpthread/pthread_mutexattr.3	Thu Feb  2 10:48:22 2017
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_mutexattr.3,v 1.13 2016/07/05 10:04:17 wiz Exp $
+.\" $NetBSD: pthread_mutexattr.3,v 1.14 2017/02/02 10:48:22 njoly Exp $
 .\"
 .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -173,7 +173,7 @@ Attempts to unlock an already unlocked
 mutex will result in undefined behavior.
 .Pp
 This is the default mutex type for
-.Fn pthread_mutexaddr_init .
+.Fn pthread_mutexattr_init .
 .El
 .Pp
 The



CVS commit: src/lib/libpthread

2016-11-24 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Nov 24 12:19:28 UTC 2016

Modified Files:
src/lib/libpthread: pthread.3

Log Message:
Bump date for previous.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libpthread/pthread.3

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/pthread.3
diff -u src/lib/libpthread/pthread.3:1.15 src/lib/libpthread/pthread.3:1.16
--- src/lib/libpthread/pthread.3:1.15	Tue Nov 22 00:32:09 2016
+++ src/lib/libpthread/pthread.3	Thu Nov 24 12:19:28 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread.3,v 1.15 2016/11/22 00:32:09 kamil Exp $
+.\"	$NetBSD: pthread.3,v 1.16 2016/11/24 12:19:28 wiz Exp $
 .\"
 .\" Copyright (c) 2003, 2007, 2009 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 16, 2010
+.Dd November 22, 2016
 .Dt PTHREAD 3
 .Os
 .Sh NAME



CVS commit: src/lib/libpthread

2016-11-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Nov 22 00:32:09 UTC 2016

Modified Files:
src/lib/libpthread: pthread.3

Log Message:
Add reference in SEE ALSO to pthread_dbg(3)

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/lib/libpthread/pthread.3

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/pthread.3
diff -u src/lib/libpthread/pthread.3:1.14 src/lib/libpthread/pthread.3:1.15
--- src/lib/libpthread/pthread.3:1.14	Sun May 16 12:23:32 2010
+++ src/lib/libpthread/pthread.3	Tue Nov 22 00:32:09 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread.3,v 1.14 2010/05/16 12:23:32 jruoho Exp $
+.\"	$NetBSD: pthread.3,v 1.15 2016/11/22 00:32:09 kamil Exp $
 .\"
 .\" Copyright (c) 2003, 2007, 2009 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -157,6 +157,7 @@ for
 .Xr sh 1 ) .
 .El
 .Sh SEE ALSO
+.Xr pthread_dbg 3
 .Rs
 .%A David R. Butenhof
 .%T Programming with POSIX(R) Threads



CVS commit: src/lib/libpthread

2016-10-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 31 23:53:12 UTC 2016

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
Don't spin if we already own the mutex, otherwise we will get stuck spinning
forever, fixes timemutex{1,2} tests.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.62 src/lib/libpthread/pthread_mutex.c:1.63
--- src/lib/libpthread/pthread_mutex.c:1.62	Sun Jul 17 09:49:43 2016
+++ src/lib/libpthread/pthread_mutex.c	Mon Oct 31 19:53:12 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.62 2016/07/17 13:49:43 skrll Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.63 2016/10/31 23:53:12 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.62 2016/07/17 13:49:43 skrll Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.63 2016/10/31 23:53:12 christos Exp $");
 
 #include 
 #include 
@@ -298,7 +298,8 @@ again:
 	 * we see that the holder is running again.
 	 */
 	membar_sync();
-	pthread__mutex_spin(ptm, owner);
+	if (MUTEX_OWNER(owner) != (uintptr_t)self)
+		pthread__mutex_spin(ptm, owner);
 
 	if (membar_consumer(), !MUTEX_HAS_WAITERS(ptm->ptm_owner)) {
 		goto again;
@@ -338,7 +339,8 @@ pthread__mutex_lock_slow(pthread_mutex_t
 	serrno = errno;
 	for (;; owner = ptm->ptm_owner) {
 		/* Spin while the owner is running. */
-		owner = pthread__mutex_spin(ptm, owner);
+		if (MUTEX_OWNER(owner) != (uintptr_t)self)
+			owner = pthread__mutex_spin(ptm, owner);
 
 		/* If it has become free, try to acquire it again. */
 		if (MUTEX_OWNER(owner) == 0) {



CVS commit: src/lib/libpthread

2016-10-30 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Oct 30 23:26:33 UTC 2016

Modified Files:
src/lib/libpthread: pthread.h pthread_mutex.3

Log Message:
POSIX harder the pthread_mutex_timedlock(3) prototype

Add missing __restrict keyword to the first pointer parameter.

It was already used for the second argument, should not be a functional
change and generated code should be the same.

This new form is now aligned with POSIX.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libpthread/pthread.h
cvs rdiff -u -r1.8 -r1.9 src/lib/libpthread/pthread_mutex.3

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/pthread.h
diff -u src/lib/libpthread/pthread.h:1.37 src/lib/libpthread/pthread.h:1.38
--- src/lib/libpthread/pthread.h:1.37	Sun Jul  3 14:24:58 2016
+++ src/lib/libpthread/pthread.h	Sun Oct 30 23:26:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.h,v 1.37 2016/07/03 14:24:58 christos Exp $	*/
+/*	$NetBSD: pthread.h,v 1.38 2016/10/30 23:26:33 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -94,7 +94,7 @@ int	pthread_mutex_destroy(pthread_mutex_
 int	pthread_mutex_lock(pthread_mutex_t *);
 int	pthread_mutex_trylock(pthread_mutex_t *);
 int	pthread_mutex_unlock(pthread_mutex_t *);
-int	pthread_mutex_timedlock(pthread_mutex_t *,
+int	pthread_mutex_timedlock(pthread_mutex_t * __restrict,
 	const struct timespec * __restrict);
 int	pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict,
 	int * __restrict);

Index: src/lib/libpthread/pthread_mutex.3
diff -u src/lib/libpthread/pthread_mutex.3:1.8 src/lib/libpthread/pthread_mutex.3:1.9
--- src/lib/libpthread/pthread_mutex.3:1.8	Tue Jul  5 10:04:17 2016
+++ src/lib/libpthread/pthread_mutex.3	Sun Oct 30 23:26:33 2016
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_mutex.3,v 1.8 2016/07/05 10:04:17 wiz Exp $
+.\" $NetBSD: pthread_mutex.3,v 1.9 2016/10/30 23:26:33 kamil Exp $
 .\"
 .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -76,7 +76,7 @@
 .Ft int
 .Fn pthread_mutex_unlock "pthread_mutex_t *mutex"
 .Ft int
-.Fn pthread_mutex_timedlock "pthread_mutex_t * mutex" "const struct timespec *__restrict timeout"
+.Fn pthread_mutex_timedlock "pthread_mutex_t *__restrict mutex" "const struct timespec *__restrict timeout"
 .Ft int
 .Fn pthread_mutex_getprioceiling "const pthread_mutex_t * __restrict mutex" "int * __restrict prioceiling"
 .Ft int



CVS commit: src/lib/libpthread

2016-07-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jul 20 21:02:04 UTC 2016

Modified Files:
src/lib/libpthread: pthread_types.h

Log Message:
unnamed unions need special treatment since they need braced initializers
for old style initializations.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libpthread/pthread_types.h

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/pthread_types.h
diff -u src/lib/libpthread/pthread_types.h:1.21 src/lib/libpthread/pthread_types.h:1.22
--- src/lib/libpthread/pthread_types.h:1.21	Wed Jul 20 16:06:04 2016
+++ src/lib/libpthread/pthread_types.h	Wed Jul 20 17:02:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_types.h,v 1.21 2016/07/20 20:06:04 christos Exp $	*/
+/*	$NetBSD: pthread_types.h,v 1.22 2016/07/20 21:02:04 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -140,15 +140,17 @@ struct	__pthread_mutex_st {
 
 #ifdef __cplusplus
 #define _PTHREAD_MUTEX_INI(a, b) b
+#define _PTHREAD_MUTEX_UNI(a) { 0 }
 #else
 #define _PTHREAD_MUTEX_INI(a, b) .a = b
+#define _PTHREAD_MUTEX_UNI(a) .a = 0
 #endif
 
 #define _PTHREAD_MUTEX_INITIALIZER {	\
 	_PTHREAD_MUTEX_INI(ptm_magic, _PT_MUTEX_MAGIC), 		\
 	_PTHREAD_MUTEX_INI(ptm_errorcheck, __SIMPLELOCK_UNLOCKED),	\
 	_PTHREAD_MUTEX_PAD(ptm_pad1)	\
-	_PTHREAD_MUTEX_INI(ptm_ceiling, 0),\
+	_PTHREAD_MUTEX_UNI(ptm_ceiling),\
 	_PTHREAD_MUTEX_PAD(ptm_pad2)	\
 	_PTHREAD_MUTEX_INI(ptm_owner, NULL),\
 	_PTHREAD_MUTEX_INI(ptm_waiters, NULL),\



CVS commit: src/lib/libpthread

2016-07-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jul 20 20:06:05 UTC 2016

Modified Files:
src/lib/libpthread: pthread_types.h

Log Message:
cplusplus does not like complex named initializers...


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libpthread/pthread_types.h

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/pthread_types.h
diff -u src/lib/libpthread/pthread_types.h:1.20 src/lib/libpthread/pthread_types.h:1.21
--- src/lib/libpthread/pthread_types.h:1.20	Wed Jul 20 15:26:52 2016
+++ src/lib/libpthread/pthread_types.h	Wed Jul 20 16:06:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_types.h,v 1.20 2016/07/20 19:26:52 christos Exp $	*/
+/*	$NetBSD: pthread_types.h,v 1.21 2016/07/20 20:06:04 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -114,7 +114,11 @@ struct	__pthread_mutex_st {
 	__pthread_spin_t ptm_errorcheck;
 #ifdef __CPU_SIMPLE_LOCK_PAD
 	uint8_t		ptm_pad1[3];
+#ifdef __cplusplus
+#define _PTHREAD_MUTEX_PAD(a)	{ 0, 0, 0 },
+#else
 #define _PTHREAD_MUTEX_PAD(a)	.a = { 0, 0, 0 },
+#endif
 #else
 #define _PTHREAD_MUTEX_PAD(a)
 #endif
@@ -134,16 +138,22 @@ struct	__pthread_mutex_st {
 #define	_PT_MUTEX_MAGIC	0x0003
 #define	_PT_MUTEX_DEAD	0xDEAD0003
 
-#define _PTHREAD_MUTEX_INITIALIZER {			\
-	.ptm_magic = _PT_MUTEX_MAGIC, 			\
-	.ptm_errorcheck = __SIMPLELOCK_UNLOCKED,	\
-	_PTHREAD_MUTEX_PAD(ptm_pad1)			\
-	.ptm_ceiling = 0,\
-	_PTHREAD_MUTEX_PAD(ptm_pad2)			\
-	.ptm_owner = NULL,\
-	.ptm_waiters = NULL,\
-	.ptm_recursed = 0,\
-	.ptm_spare2 = NULL,\
+#ifdef __cplusplus
+#define _PTHREAD_MUTEX_INI(a, b) b
+#else
+#define _PTHREAD_MUTEX_INI(a, b) .a = b
+#endif
+
+#define _PTHREAD_MUTEX_INITIALIZER {	\
+	_PTHREAD_MUTEX_INI(ptm_magic, _PT_MUTEX_MAGIC), 		\
+	_PTHREAD_MUTEX_INI(ptm_errorcheck, __SIMPLELOCK_UNLOCKED),	\
+	_PTHREAD_MUTEX_PAD(ptm_pad1)	\
+	_PTHREAD_MUTEX_INI(ptm_ceiling, 0),\
+	_PTHREAD_MUTEX_PAD(ptm_pad2)	\
+	_PTHREAD_MUTEX_INI(ptm_owner, NULL),\
+	_PTHREAD_MUTEX_INI(ptm_waiters, NULL),\
+	_PTHREAD_MUTEX_INI(ptm_recursed, 0),\
+	_PTHREAD_MUTEX_INI(ptm_spare2, NULL),\
 }
 
 struct	__pthread_mutexattr_st {



CVS commit: src/lib/libpthread

2016-07-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jul 20 19:26:52 UTC 2016

Modified Files:
src/lib/libpthread: pthread_types.h

Log Message:
use named initializers


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libpthread/pthread_types.h

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/pthread_types.h
diff -u src/lib/libpthread/pthread_types.h:1.19 src/lib/libpthread/pthread_types.h:1.20
--- src/lib/libpthread/pthread_types.h:1.19	Sun Jul 17 09:49:43 2016
+++ src/lib/libpthread/pthread_types.h	Wed Jul 20 15:26:52 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_types.h,v 1.19 2016/07/17 13:49:43 skrll Exp $	*/
+/*	$NetBSD: pthread_types.h,v 1.20 2016/07/20 19:26:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -114,6 +114,9 @@ struct	__pthread_mutex_st {
 	__pthread_spin_t ptm_errorcheck;
 #ifdef __CPU_SIMPLE_LOCK_PAD
 	uint8_t		ptm_pad1[3];
+#define _PTHREAD_MUTEX_PAD(a)	.a = { 0, 0, 0 },
+#else
+#define _PTHREAD_MUTEX_PAD(a)
 #endif
 	union {
 		unsigned char ptm_ceiling;
@@ -131,20 +134,17 @@ struct	__pthread_mutex_st {
 #define	_PT_MUTEX_MAGIC	0x0003
 #define	_PT_MUTEX_DEAD	0xDEAD0003
 
-#ifdef __CPU_SIMPLE_LOCK_PAD
-#define _PTHREAD_MUTEX_INITIALIZER { _PT_MUTEX_MAGIC, 			\
-__SIMPLELOCK_UNLOCKED, { 0, 0, 0 },	\
-{ 0 }, { 0, 0, 0 },			\
-NULL, NULL, 0, NULL			\
-  }
-#else
-#define _PTHREAD_MUTEX_INITIALIZER { _PT_MUTEX_MAGIC, 			\
-__SIMPLELOCK_UNLOCKED,		\
-{ 0 } ,\
-NULL, NULL, 0, NULL			\
-  }
-#endif /* __CPU_SIMPLE_LOCK_PAD */
-	
+#define _PTHREAD_MUTEX_INITIALIZER {			\
+	.ptm_magic = _PT_MUTEX_MAGIC, 			\
+	.ptm_errorcheck = __SIMPLELOCK_UNLOCKED,	\
+	_PTHREAD_MUTEX_PAD(ptm_pad1)			\
+	.ptm_ceiling = 0,\
+	_PTHREAD_MUTEX_PAD(ptm_pad2)			\
+	.ptm_owner = NULL,\
+	.ptm_waiters = NULL,\
+	.ptm_recursed = 0,\
+	.ptm_spare2 = NULL,\
+}
 
 struct	__pthread_mutexattr_st {
 	unsigned int	ptma_magic;



CVS commit: src/lib/libpthread

2016-07-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jul 17 13:49:43 UTC 2016

Modified Files:
src/lib/libpthread: pthread_mutex.c pthread_types.h

Log Message:
Use anonymous union for ptm_ceiling and old __pthread_spin_t field to
maintain backward compatibility and fix hppa build.  hppa has an non-
integer type __pthread_spin_t


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libpthread/pthread_types.h

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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.61 src/lib/libpthread/pthread_mutex.c:1.62
--- src/lib/libpthread/pthread_mutex.c:1.61	Sat Jul 16 12:58:11 2016
+++ src/lib/libpthread/pthread_mutex.c	Sun Jul 17 13:49:43 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.61 2016/07/16 12:58:11 skrll Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.62 2016/07/17 13:49:43 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.61 2016/07/16 12:58:11 skrll Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.62 2016/07/17 13:49:43 skrll Exp $");
 
 #include 
 #include 
@@ -796,7 +796,7 @@ pthread__mutex_deferwake(pthread_t self,
 int
 pthread_mutex_getprioceiling(const pthread_mutex_t *ptm, int *ceil) 
 {
-	*ceil = (unsigned int)ptm->ptm_ceiling;
+	*ceil = ptm->ptm_ceiling;
 	return 0;
 }
 
@@ -807,9 +807,9 @@ pthread_mutex_setprioceiling(pthread_mut
 
 	error = pthread_mutex_lock(ptm);
 	if (error == 0) {
-		*old_ceil = (unsigned int)ptm->ptm_ceiling;
+		*old_ceil = ptm->ptm_ceiling;
 		/*check range*/
-		ptm->ptm_ceiling = (unsigned char)ceil;
+		ptm->ptm_ceiling = ceil;
 		pthread_mutex_unlock(ptm);
 	}
 	return error;

Index: src/lib/libpthread/pthread_types.h
diff -u src/lib/libpthread/pthread_types.h:1.18 src/lib/libpthread/pthread_types.h:1.19
--- src/lib/libpthread/pthread_types.h:1.18	Sun Jul  3 14:24:58 2016
+++ src/lib/libpthread/pthread_types.h	Sun Jul 17 13:49:43 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_types.h,v 1.18 2016/07/03 14:24:58 christos Exp $	*/
+/*	$NetBSD: pthread_types.h,v 1.19 2016/07/17 13:49:43 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -115,7 +115,10 @@ struct	__pthread_mutex_st {
 #ifdef __CPU_SIMPLE_LOCK_PAD
 	uint8_t		ptm_pad1[3];
 #endif
-	__pthread_spin_t ptm_ceiling;
+	union {
+		unsigned char ptm_ceiling;
+		__pthread_spin_t ptm_unused;
+	};
 #ifdef __CPU_SIMPLE_LOCK_PAD
 	uint8_t		ptm_pad2[3];
 #endif
@@ -131,13 +134,13 @@ struct	__pthread_mutex_st {
 #ifdef __CPU_SIMPLE_LOCK_PAD
 #define _PTHREAD_MUTEX_INITIALIZER { _PT_MUTEX_MAGIC, 			\
 __SIMPLELOCK_UNLOCKED, { 0, 0, 0 },	\
-__SIMPLELOCK_UNLOCKED, { 0, 0, 0 },	\
+{ 0 }, { 0, 0, 0 },			\
 NULL, NULL, 0, NULL			\
   }
 #else
 #define _PTHREAD_MUTEX_INITIALIZER { _PT_MUTEX_MAGIC, 			\
 __SIMPLELOCK_UNLOCKED,		\
-__SIMPLELOCK_UNLOCKED,		\
+{ 0 } ,\
 NULL, NULL, 0, NULL			\
   }
 #endif /* __CPU_SIMPLE_LOCK_PAD */



CVS commit: src/lib/libpthread

2016-07-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Jul 16 12:58:12 UTC 2016

Modified Files:
src/lib/libpthread: pthread_mutex.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/lib/libpthread/pthread_mutex.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/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.60 src/lib/libpthread/pthread_mutex.c:1.61
--- src/lib/libpthread/pthread_mutex.c:1.60	Sun Jul  3 14:24:58 2016
+++ src/lib/libpthread/pthread_mutex.c	Sat Jul 16 12:58:11 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_mutex.c,v 1.60 2016/07/03 14:24:58 christos Exp $	*/
+/*	$NetBSD: pthread_mutex.c,v 1.61 2016/07/16 12:58:11 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: pthread_mutex.c,v 1.60 2016/07/03 14:24:58 christos Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.61 2016/07/16 12:58:11 skrll Exp $");
 
 #include 
 #include 
@@ -794,7 +794,7 @@ pthread__mutex_deferwake(pthread_t self,
 }
 
 int
-pthread_mutex_getprioceiling(const pthread_mutex_t *ptm, int*ceil) 
+pthread_mutex_getprioceiling(const pthread_mutex_t *ptm, int *ceil) 
 {
 	*ceil = (unsigned int)ptm->ptm_ceiling;
 	return 0;



CVS commit: src/lib/libpthread

2016-07-05 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Jul  5 10:04:17 UTC 2016

Modified Files:
src/lib/libpthread: pthread_attr_getstack.3 pthread_barrier.3
pthread_barrierattr.3 pthread_cond.3 pthread_condattr.3
pthread_mutex.3 pthread_mutexattr.3 pthread_once.3 pthread_rwlock.3
pthread_rwlockattr.3

Log Message:
Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libpthread/pthread_attr_getstack.3 \
src/lib/libpthread/pthread_barrier.3 src/lib/libpthread/pthread_rwlock.3
cvs rdiff -u -r1.10 -r1.11 src/lib/libpthread/pthread_barrierattr.3 \
src/lib/libpthread/pthread_condattr.3
cvs rdiff -u -r1.6 -r1.7 src/lib/libpthread/pthread_cond.3
cvs rdiff -u -r1.7 -r1.8 src/lib/libpthread/pthread_mutex.3
cvs rdiff -u -r1.12 -r1.13 src/lib/libpthread/pthread_mutexattr.3
cvs rdiff -u -r1.9 -r1.10 src/lib/libpthread/pthread_once.3 \
src/lib/libpthread/pthread_rwlockattr.3

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/pthread_attr_getstack.3
diff -u src/lib/libpthread/pthread_attr_getstack.3:1.5 src/lib/libpthread/pthread_attr_getstack.3:1.6
--- src/lib/libpthread/pthread_attr_getstack.3:1.5	Fri Jul  9 17:15:59 2010
+++ src/lib/libpthread/pthread_attr_getstack.3	Tue Jul  5 10:04:17 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread_attr_getstack.3,v 1.5 2010/07/09 17:15:59 jruoho Exp $
+.\"	$NetBSD: pthread_attr_getstack.3,v 1.6 2016/07/05 10:04:17 wiz Exp $
 .\"
 .\" Copyright (c) 2010 Jukka Ruohonen 
 .\" All rights reserved.
@@ -38,10 +38,10 @@
 .Ft int
 .Fn pthread_attr_getstack \
 "const pthread_attr_t * restrict attr" \
-"void ** restrict stackaddr, size_t * restrict stacksize"
+"void ** restrict stackaddr" "size_t * restrict stacksize"
 .Ft int
 .Fn pthread_attr_setstack \
-"pthread_attr_t * restrict attr" "void *stackaddr, size_t stacksize"
+"pthread_attr_t * restrict attr" "void *stackaddr" "size_t stacksize"
 .Ft int
 .Fn pthread_attr_getstacksize \
 "const pthread_attr_t * restrict attr" "size_t * restrict stacksize"
Index: src/lib/libpthread/pthread_barrier.3
diff -u src/lib/libpthread/pthread_barrier.3:1.5 src/lib/libpthread/pthread_barrier.3:1.6
--- src/lib/libpthread/pthread_barrier.3:1.5	Sun Jul  3 14:24:58 2016
+++ src/lib/libpthread/pthread_barrier.3	Tue Jul  5 10:04:17 2016
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_barrier.3,v 1.5 2016/07/03 14:24:58 christos Exp $
+.\" $NetBSD: pthread_barrier.3,v 1.6 2016/07/05 10:04:17 wiz Exp $
 .\"
 .\" Copyright (c) 2002, 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -25,7 +25,6 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\" 
-
 .Dd June 12, 2016
 .Dt PTHREAD_BARRIER 3
 .Os
@@ -48,9 +47,8 @@
 "int * __restrict pshared"
 .Ft int
 .Fn pthread_barrierattr_setpshared "pthread_barrierattr_t * attr" \
-"int pshared" 
+"int pshared"
 .\" 
-
 .Sh DESCRIPTION
 The
 .Fn pthread_barrier_init
@@ -98,15 +96,14 @@ calls and continue execution.
 .Pp
 .\" -
 The
-.Fn pthread_barrierattr_getpshared 
+.Fn pthread_barrierattr_getpshared
 function shall obtain the value of the process-shared attribute from the
-attributes object referenced by attr. 
+attributes object referenced by attr.
 The
 .Fn pthread_barrierattr_setpshared
 function shall set the process-shared attribute in an initialized attributes
-object referenced by attr. 
+object referenced by attr.
 .\" 
-
 .Sh RETURN VALUES
 If successful,
 .Fn pthread_barrier_init
@@ -136,7 +133,7 @@ In the case of failure, an error value w
 .\" -
 If successful,
 .Fn pthread_barrierattr_getpshared
-shall return zero and store the value of the process-shared attribute of attr 
+shall return zero and store the value of the process-shared attribute of attr
 into the object referenced by the
 .Fa pshared
 parameter.
@@ -146,9 +143,8 @@ Otherwise, an error number shall be retu
 If successful,
 .Fn pthread_barrierattr_setpshared
 shall return zero;
-Otherwise, an error number shall be returned to indicate the error. 
+Otherwise, an error number shall be returned to indicate the error.
 .\" 
-
 .Sh ERRORS
 The
 .Fn pthread_barrier_init
@@ -189,9 +185,9 @@ is invalid.
 .El
 .Pp
 .\" -
-The 
+The
 .Fn pthread_barrierattr_setpshared
-function and 
+function and
 the
 .Fn pthread_barrierattr_getpshared
 function may fail if:
@@ -200,7 +196,7 @@ function may fail if:
 The value specified by
 .Fa attr
 is invalid.
-
+.El
 .\" 

CVS commit: src/lib/libpthread

2016-04-24 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Apr 24 09:01:45 UTC 2016

Modified Files:
src/lib/libpthread: pthread_getcpuclockid.3

Log Message:
Formatting, typos, whitespace fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libpthread/pthread_getcpuclockid.3

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/pthread_getcpuclockid.3
diff -u src/lib/libpthread/pthread_getcpuclockid.3:1.2 src/lib/libpthread/pthread_getcpuclockid.3:1.3
--- src/lib/libpthread/pthread_getcpuclockid.3:1.2	Sun Apr 24 00:05:28 2016
+++ src/lib/libpthread/pthread_getcpuclockid.3	Sun Apr 24 09:01:45 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread_getcpuclockid.3,v 1.2 2016/04/24 00:05:28 christos Exp $
+.\"	$NetBSD: pthread_getcpuclockid.3,v 1.3 2016/04/24 09:01:45 wiz Exp $
 .\"
 .\" Copyright (c) 2016 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -28,11 +28,11 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .Dd April 23, 2016
-.Dt pthread_getcpuclockid 3
+.Dt PTHREAD_GETCPUCLOCKID 3
 .Os
 .Sh NAME
 .Nm pthread_getcpuclockid
-.Nd retrieve the clockid of the give thread
+.Nd retrieve the clockid of the given thread
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
@@ -47,7 +47,7 @@ function retrieves the
 for the specified
 .Fa thread .
 .Pp
-The 
+The
 .Xr clock_gettime 2
 function can be used with the returned
 .Fa clock_id
@@ -56,7 +56,7 @@ to retrieve LWP times.
 On success the
 .Fn pthread_getcpuclockid
 function returns 0, placing the requested
-.Fa clock_id 
+.Fa clock_id
 in the argument.
 On error, the value \-1 is returned
 and the value of
@@ -70,7 +70,7 @@ No thread with this id was found.
 .El
 .Sh SEE ALSO
 .Xr clock_getcpuclockid2 2 ,
-.Xr clock_gettime 2 ,
+.Xr clock_gettime 2
 .Sh STANDARDS
 The
 .Fn pthread_getcpuclockid



CVS commit: src/lib/libpthread

2016-04-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr 24 00:05:28 UTC 2016

Modified Files:
src/lib/libpthread: pthread_getcpuclockid.3

Log Message:
commit the right file.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libpthread/pthread_getcpuclockid.3

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/pthread_getcpuclockid.3
diff -u src/lib/libpthread/pthread_getcpuclockid.3:1.1 src/lib/libpthread/pthread_getcpuclockid.3:1.2
--- src/lib/libpthread/pthread_getcpuclockid.3:1.1	Sat Apr 23 19:12:19 2016
+++ src/lib/libpthread/pthread_getcpuclockid.3	Sat Apr 23 20:05:28 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread_getcpuclockid.3,v 1.1 2016/04/23 23:12:19 christos Exp $
+.\"	$NetBSD: pthread_getcpuclockid.3,v 1.2 2016/04/24 00:05:28 christos Exp $
 .\"
 .\" Copyright (c) 2016 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -28,64 +28,34 @@
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
 .Dd April 23, 2016
-.Dt clock_getcpuclockid2 2
+.Dt pthread_getcpuclockid 3
 .Os
 .Sh NAME
-.Nm clock_getcpuclockid2
-.Nd retrieve the clock id of a process or lwp
+.Nm pthread_getcpuclockid
+.Nd retrieve the clockid of the give thread
 .Sh LIBRARY
 .Lb libc
 .Sh SYNOPSIS
-.In time.h
+.In pthread.h
 .Ft int
-.Fn clock_getcpuclockid2 "idtype_t idtype" "id_t id" "clockid_t *clock_id"
-.Ft int
-.Fn clock_getcpuclockid "pid_t pid" "clockid_t *clock_id"
+.Fn pthread_getcpuclockid "pthread_t thread" "clockid_t *clock_id"
 .Sh DESCRIPTION
 The
-.Fn cpu_getcpuclockid2
+.Fn pthread_getcpuclockid
 function retrieves the
 .Fa clock_id
 for the specified
-.Fa id
-and
-.Fa idtype.
-Supported
-.Fa idtypes
-are:
-.Bl -tag -width P_LWPID
-.It Dv P_PID
-The specified process id or
-.Dv 0
-for the current process.
-.It Dv P_LWPID
-The specified LWP id or
-.Dv 0
-for the current LWP.
-.El
-.Pp
-The
-.Fn clock_getcpuclockid
-function is equivalent to calling
-.Fn clock_getcpuclockid2
-with
-.Fa idtype
-.Dv P_PID
-and
-.Fa id
-.Fa pid .
+.Fa thread .
 .Pp
-The
+The 
 .Xr clock_gettime 2
 function can be used with the returned
 .Fa clock_id
-to retrieve process and LWP times.
+to retrieve LWP times.
 .Sh RETURN VALUES
-The
-.Fn clock_getcpuclockid
-and
-.Fn clock_getcpuclockid2
-functions succeed and return 0, placing the requested
+On success the
+.Fn pthread_getcpuclockid
+function returns 0, placing the requested
 .Fa clock_id 
 in the argument.
 On error, the value \-1 is returned
@@ -95,27 +65,20 @@ is set to reflect what went wrong.
 .Sh ERRORS
 These functions fail if:
 .Bl -tag -width Er
-.It Bq Er EINVAL
-An unsuppored
-.Fa idtype
-was supplied.
+.It Bq Er ESRCH
+No thread with this id was found.
 .El
 .Sh SEE ALSO
-.Xr clock_gettime 2
+.Xr clock_getcpuclockid2 2 ,
+.Xr clock_gettime 2 ,
 .Sh STANDARDS
 The
-.Fn clock_getcpuclockid
+.Fn pthread_getcpuclockid
 function conforms to
 .St -p1003.1-2001 .
-The
-.Fn clock_getcpuclockid2
-is a
-.Nx
 extension.
 .Sh HISTORY
 The
-.Fn clock_getcpuclockid
-and
-.Fn clock_getcpuclockid2
-functions appeared in
+.Fn pthread_getcpuclockid
+function appeared in
 .Nx 8 .



CVS commit: src/lib/libpthread

2016-04-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 23 23:23:18 UTC 2016

Modified Files:
src/lib/libpthread: shlib_version

Log Message:
bump


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libpthread/shlib_version

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/shlib_version
diff -u src/lib/libpthread/shlib_version:1.16 src/lib/libpthread/shlib_version:1.17
--- src/lib/libpthread/shlib_version:1.16	Wed Apr  3 11:45:21 2013
+++ src/lib/libpthread/shlib_version	Sat Apr 23 19:23:17 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: shlib_version,v 1.16 2013/04/03 15:45:21 christos Exp $
+#	$NetBSD: shlib_version,v 1.17 2016/04/23 23:23:17 christos Exp $
 #	Remember to update distrib/sets/lists/base/shl.* when changing
 #
 # Things to do when bumping major version:
@@ -16,4 +16,4 @@
 #	without compat_netbsd32 shims??
 #
 major=1
-minor=2
+minor=3



CVS commit: src/lib/libpthread

2016-04-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 23 23:12:19 UTC 2016

Modified Files:
src/lib/libpthread: Makefile pthread.h
Added Files:
src/lib/libpthread: pthread_getcpuclockid.3 pthread_getcpuclockid.c

Log Message:
Add pthread_getcpuclockid(3)


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/lib/libpthread/Makefile
cvs rdiff -u -r1.35 -r1.36 src/lib/libpthread/pthread.h
cvs rdiff -u -r0 -r1.1 src/lib/libpthread/pthread_getcpuclockid.3 \
src/lib/libpthread/pthread_getcpuclockid.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.85 src/lib/libpthread/Makefile:1.86
--- src/lib/libpthread/Makefile:1.85	Tue Dec 16 15:05:54 2014
+++ src/lib/libpthread/Makefile	Sat Apr 23 19:12:19 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.85 2014/12/16 20:05:54 pooka Exp $
+#	$NetBSD: Makefile,v 1.86 2016/04/23 23:12:19 christos Exp $
 #
 
 WARNS?=	5
@@ -54,6 +54,7 @@ SRCS+=	pthread_barrier.c
 SRCS+=	pthread_cancelstub.c
 .endif
 SRCS+=	pthread_cond.c
+SRCS+=	pthread_getcpuclockid.c
 SRCS+=	pthread_lock.c 
 SRCS+=	${PTHREAD_MAKELWP}
 SRCS+=	pthread_misc.c
@@ -134,6 +135,7 @@ MAN+=	affinity.3 pthread.3 \
 	pthread_create.3 pthread_detach.3 pthread_equal.3 \
 	pthread_curcpu_np.3 \
 	pthread_exit.3 \
+	pthread_getcpuclockid.3 \
 	pthread_getname_np.3 \
 	pthread_getspecific.3 pthread_join.3 \
 	pthread_key_create.3 pthread_kill.3 \

Index: src/lib/libpthread/pthread.h
diff -u src/lib/libpthread/pthread.h:1.35 src/lib/libpthread/pthread.h:1.36
--- src/lib/libpthread/pthread.h:1.35	Fri Nov  2 23:10:50 2012
+++ src/lib/libpthread/pthread.h	Sat Apr 23 19:12:19 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.h,v 1.35 2012/11/03 03:10:50 christos Exp $	*/
+/*	$NetBSD: pthread.h,v 1.36 2016/04/23 23:12:19 christos Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -138,6 +138,8 @@ int	pthread_resume_np(pthread_t);
 
 unsigned int	pthread_curcpu_np(void);
 
+int	pthread_getcpuclockid(pthread_t, clockid_t *);
+
 struct pthread_cleanup_store {
 	void	*pad[4];
 };

Added files:

Index: src/lib/libpthread/pthread_getcpuclockid.3
diff -u /dev/null src/lib/libpthread/pthread_getcpuclockid.3:1.1
--- /dev/null	Sat Apr 23 19:12:19 2016
+++ src/lib/libpthread/pthread_getcpuclockid.3	Sat Apr 23 19:12:19 2016
@@ -0,0 +1,121 @@
+.\"	$NetBSD: pthread_getcpuclockid.3,v 1.1 2016/04/23 23:12:19 christos Exp $
+.\"
+.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Christos Zoulas.
+.\"
+.\" 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.
+.\"
+.\" 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.
+.\"
+.Dd April 23, 2016
+.Dt clock_getcpuclockid2 2
+.Os
+.Sh NAME
+.Nm clock_getcpuclockid2
+.Nd retrieve the clock id of a process or lwp
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In time.h
+.Ft int
+.Fn clock_getcpuclockid2 "idtype_t idtype" "id_t id" "clockid_t *clock_id"
+.Ft int
+.Fn clock_getcpuclockid "pid_t pid" "clockid_t *clock_id"
+.Sh DESCRIPTION
+The
+.Fn cpu_getcpuclockid2
+function retrieves the
+.Fa clock_id
+for the specified
+.Fa id
+and
+.Fa idtype.
+Supported
+.Fa idtypes
+are:
+.Bl -tag -width P_LWPID
+.It Dv P_PID
+The specified process id or
+.Dv 0
+for the current process.
+.It Dv P_LWPID
+The specified LWP id or
+.Dv 0
+for the current LWP.
+.El
+.Pp
+The
+.Fn clock_getcpuclockid
+function is equivalent to calling
+.Fn clock_getcpuclockid2
+with
+.Fa idtype
+.Dv P_PID
+and
+.Fa id
+.Fa pid .
+.Pp
+The
+.Xr clock_gettime 2
+function can be used with the returned
+.Fa clock_id
+to 

CVS commit: src/lib/libpthread

2016-04-07 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Apr  7 06:21:48 UTC 2016

Modified Files:
src/lib/libpthread: pthread_attr_getguardsize.3

Log Message:
_SC_PAGESIZE is not the page size; it's a symbolic code for retrieving
the page size.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libpthread/pthread_attr_getguardsize.3

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/pthread_attr_getguardsize.3
diff -u src/lib/libpthread/pthread_attr_getguardsize.3:1.2 src/lib/libpthread/pthread_attr_getguardsize.3:1.3
--- src/lib/libpthread/pthread_attr_getguardsize.3:1.2	Thu Jul  8 18:24:34 2010
+++ src/lib/libpthread/pthread_attr_getguardsize.3	Thu Apr  7 06:21:48 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: pthread_attr_getguardsize.3,v 1.2 2010/07/08 18:24:34 wiz Exp $
+.\"	$NetBSD: pthread_attr_getguardsize.3,v 1.3 2016/04/07 06:21:48 dholland Exp $
 .\"
 .\" Copyright (c) 2010 Jukka Ruohonen 
 .\" All rights reserved.
@@ -66,9 +66,12 @@ In
 .Nx
 the default
 .Fa guardsize
-is
-.Dv _SC_PAGESIZE ,
-the system page size.
+is the system page size.
+(This value is often 4096 bytes but varies on some ports; the
+precise value can be retrieved by using
+.Xr sysconf 3
+with
+.Dv _SC_PAGESIZE . )
 .Pp
 The rationale behind
 .Fa guardsize



  1   2   3   >