Module Name:    src
Committed By:   riz
Date:           Wed Nov 28 23:47:38 UTC 2012

Modified Files:
        src/lib/libpthread [netbsd-6]: pthread.h pthread_cond.c
            pthread_condattr.3

Log Message:
Pull up following revision(s) (requested by christos in ticket #722):
        lib/libpthread/pthread_cond.c: revision 1.58
        lib/libpthread/pthread_condattr.3: revision 1.8
        lib/libpthread/pthread.h: revision 1.35
add pthread_condattr_setclock(3)


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.34.8.1 src/lib/libpthread/pthread.h
cvs rdiff -u -r1.56 -r1.56.8.1 src/lib/libpthread/pthread_cond.c
cvs rdiff -u -r1.7 -r1.7.8.1 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.h
diff -u src/lib/libpthread/pthread.h:1.34 src/lib/libpthread/pthread.h:1.34.8.1
--- src/lib/libpthread/pthread.h:1.34	Fri Aug  6 05:25:02 2010
+++ src/lib/libpthread/pthread.h	Wed Nov 28 23:47:38 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread.h,v 1.34 2010/08/06 05:25:02 christos Exp $	*/
+/*	$NetBSD: pthread.h,v 1.34.8.1 2012/11/28 23:47:38 riz Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -112,6 +112,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);
+#endif
 int	pthread_condattr_destroy(pthread_condattr_t *);
 
 int	pthread_once(pthread_once_t *, void (*)(void));

Index: src/lib/libpthread/pthread_cond.c
diff -u src/lib/libpthread/pthread_cond.c:1.56 src/lib/libpthread/pthread_cond.c:1.56.8.1
--- src/lib/libpthread/pthread_cond.c:1.56	Tue Nov  2 20:49:47 2010
+++ src/lib/libpthread/pthread_cond.c	Wed Nov 28 23:47:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pthread_cond.c,v 1.56 2010/11/02 20:49:47 skrll Exp $	*/
+/*	$NetBSD: pthread_cond.c,v 1.56.8.1 2012/11/28 23:47:37 riz Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,11 +46,12 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_cond.c,v 1.56 2010/11/02 20:49:47 skrll Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.56.8.1 2012/11/28 23:47:37 riz Exp $");
 
 #include <errno.h>
 #include <sys/time.h>
 #include <sys/types.h>
+#include <stdlib.h>
 
 #include "pthread.h"
 #include "pthread_int.h"
@@ -60,7 +61,7 @@ int	_sys___nanosleep50(const struct time
 extern int pthread__started;
 
 static int pthread_cond_wait_nothread(pthread_t, pthread_mutex_t *,
-    const struct timespec *);
+    pthread_cond_t *, const struct timespec *);
 
 int	_pthread_cond_has_waiters_np(pthread_cond_t *);
 
@@ -84,6 +85,14 @@ pthread_cond_init(pthread_cond_t *cond, 
 	pthread_lockinit(&cond->ptc_lock);
 	PTQ_INIT(&cond->ptc_waiters);
 	cond->ptc_mutex = NULL;
+	if (attr && attr->ptca_private) {
+		cond->ptc_private = malloc(sizeof(clockid_t));
+		if (cond->ptc_private == NULL)
+			return errno;
+		*(clockid_t *)cond->ptc_private =
+		    *(clockid_t *)attr->ptca_private;
+	} else
+		cond->ptc_private = NULL;
 
 	return 0;
 }
@@ -99,6 +108,7 @@ pthread_cond_destroy(pthread_cond_t *con
 	    cond->ptc_mutex == NULL);
 
 	cond->ptc_magic = _PT_COND_DEAD;
+	free(cond->ptc_private);
 
 	return 0;
 }
@@ -127,7 +137,7 @@ pthread_cond_timedwait(pthread_cond_t *c
 
 	/* 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, abstime);
+		return pthread_cond_wait_nothread(self, mutex, cond, abstime);
 	}
 	if (__predict_false(self->pt_cancel)) {
 		pthread__cancelled();
@@ -318,11 +328,29 @@ pthread_condattr_init(pthread_condattr_t
 {
 
 	attr->ptca_magic = _PT_CONDATTR_MAGIC;
+	attr->ptca_private = NULL;
 
 	return 0;
 }
 
 int
+pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clck)
+{
+	switch (clck) {
+	case CLOCK_MONOTONIC:
+	case CLOCK_REALTIME:
+		if (attr->ptca_private == NULL)
+			attr->ptca_private = malloc(sizeof(clockid_t));
+		if (attr->ptca_private == NULL)
+			return errno;
+		*(clockid_t *)attr->ptca_private = clck;
+		return 0;
+	default:
+		return EINVAL;
+	}
+}
+
+int
 pthread_condattr_destroy(pthread_condattr_t *attr)
 {
 
@@ -330,6 +358,7 @@ pthread_condattr_destroy(pthread_condatt
 	    attr->ptca_magic == _PT_CONDATTR_MAGIC);
 
 	attr->ptca_magic = _PT_CONDATTR_DEAD;
+	free(attr->ptca_private);
 
 	return 0;
 }
@@ -337,7 +366,7 @@ pthread_condattr_destroy(pthread_condatt
 /* 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,
-    const struct timespec *abstime)
+    pthread_cond_t *cond, const struct timespec *abstime)
 {
 	struct timespec now, diff;
 	int retval;
@@ -346,7 +375,9 @@ pthread_cond_wait_nothread(pthread_t sel
 		diff.tv_sec = 99999999;
 		diff.tv_nsec = 0;
 	} else {
-		clock_gettime(CLOCK_REALTIME, &now);
+		clockid_t clck = cond->ptc_private ?
+		    *(clockid_t *)cond->ptc_private : CLOCK_REALTIME;
+		clock_gettime(clck, &now);
 		if  (timespeccmp(abstime, &now, <))
 			timespecclear(&diff);
 		else

Index: src/lib/libpthread/pthread_condattr.3
diff -u src/lib/libpthread/pthread_condattr.3:1.7 src/lib/libpthread/pthread_condattr.3:1.7.8.1
--- src/lib/libpthread/pthread_condattr.3:1.7	Fri Jul  9 17:54:08 2010
+++ src/lib/libpthread/pthread_condattr.3	Wed Nov 28 23:47:38 2012
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_condattr.3,v 1.7 2010/07/09 17:54:08 jruoho Exp $
+.\" $NetBSD: pthread_condattr.3,v 1.7.8.1 2012/11/28 23:47:38 riz 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 July 9, 2010
+.Dd November 2, 2012
 .Dt PTHREAD_CONDATTR 3
 .Os
 .Sh NAME
@@ -63,6 +63,8 @@
 .Ft int
 .Fn pthread_condattr_init "pthread_condattr_t *attr"
 .Ft int
+.Fn pthread_condattr_init "pthread_condattr_t *attr" "clockid_t clock"
+.Ft int
 .Fn pthread_condattr_destroy "pthread_condattr_t *attr"
 .Sh DESCRIPTION
 Condition attribute objects are used to specify parameters to the
@@ -74,6 +76,16 @@ function initializes a condition attribu
 and the
 .Fn pthread_condattr_destroy
 function destroys a condition attribute object.
+The
+.Fn pthread_condattr_setclock
+function sets the system clock to be used for time comparisons to
+the one specified in
+.Fa clock .
+Valid clock values are
+.Dv CLOCK_MONOTONIC
+and
+.Dv CLOCK_REALTIME
+(the default).
 .Sh RETURN VALUES
 If successful, these functions return 0.
 Otherwise, an error number is returned to indicate the error.

Reply via email to