Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Nov 2010 01:52:10 +0000 (UTC)
From:      David Xu <davidxu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r215073 - user/davidxu/libthr/lib/libthr/thread
Message-ID:  <201011100152.oAA1qAKa071192@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: davidxu
Date: Wed Nov 10 01:52:10 2010
New Revision: 215073
URL: http://svn.freebsd.org/changeset/base/215073

Log:
  Remove debug code. Use same condition variable destroying code for
  FBSD_1.1 interface.

Modified:
  user/davidxu/libthr/lib/libthr/thread/thr_cond.c
  user/davidxu/libthr/lib/libthr/thread/thr_mutex.c

Modified: user/davidxu/libthr/lib/libthr/thread/thr_cond.c
==============================================================================
--- user/davidxu/libthr/lib/libthr/thread/thr_cond.c	Wed Nov 10 01:29:56 2010	(r215072)
+++ user/davidxu/libthr/lib/libthr/thread/thr_cond.c	Wed Nov 10 01:52:10 2010	(r215073)
@@ -97,23 +97,20 @@ _pthread_cond_init(pthread_cond_t *cond,
 	return (cond_init(cond, cond_attr));
 }
 
-int
-_pthread_cond_destroy(pthread_cond_t *cvp)
+static int
+cond_destroy_common(pthread_cond_t *cvp)
 {
 	int	error = 0;
 
 	if (cvp->__refcount == 0)
 		goto next;
 	_thr_umtx_lock_spin(&cvp->__lock);
+	if (cvp->__waiters > 0) {
+		_thr_umtx_unlock(&cvp->__lock);
+		return (EBUSY);
+	}
 	while (cvp->__refcount != 0) {
 		cvp->__destroying = 1;
-		if (cvp->__waiters > 0) {
-			cvp->__seq++;
-			cvp->__broadcast_seq++;
-			cvp->__waiters = 0;
-			cvp->__signals = 0;
-			_thr_umtx_wake(&cvp->__seq, INT_MAX, CV_PSHARED(cvp));
-		}
 		_thr_umtx_unlock(&cvp->__lock);
 		_thr_umtx_wait_uint((u_int *)&cvp->__destroying,
 				1, NULL, CV_PSHARED(cvp));
@@ -125,6 +122,12 @@ next:
 	return (error);
 }
 
+int
+_pthread_cond_destroy(pthread_cond_t *cvp)
+{
+	return cond_destroy_common(cvp);
+}
+
 /*
  * Cancellation behaivor:
  *   Thread may be canceled at start, if thread is canceled, it means it
@@ -282,7 +285,7 @@ cond_wait_common(struct pthread_cond *cv
 	 * Note that if it is robust type of mutex, we should not use
 	 * the internal lock too, because it is not robust.
 	 */
-	if (1 || curthread->attr.sched_policy != SCHED_OTHER ||
+	if (curthread->attr.sched_policy != SCHED_OTHER ||
 	    curthread->priority_mutex_count != 0  ||
 	    (mp->__lockflags & (UMUTEX_PRIO_PROTECT|UMUTEX_PRIO_INHERIT|
 		UMUTEX_ROBUST)) != 0)
@@ -451,13 +454,10 @@ _pthread_cond_destroy_1_0(pthread_cond_o
 		error = EINVAL;
 	else {
 		cvp = *cond;
-		/* XXX */
+		error = cond_destroy_common(cvp);
+		if (error)
+			return (error);
 		*cond = THR_COND_DESTROYED;
-
-		/*
-		 * Free the memory allocated for the condition
-		 * variable structure:
-		 */
 		free(cvp);
 	}
 	return (error);

Modified: user/davidxu/libthr/lib/libthr/thread/thr_mutex.c
==============================================================================
--- user/davidxu/libthr/lib/libthr/thread/thr_mutex.c	Wed Nov 10 01:29:56 2010	(r215072)
+++ user/davidxu/libthr/lib/libthr/thread/thr_mutex.c	Wed Nov 10 01:52:10 2010	(r215073)
@@ -1101,12 +1101,9 @@ _pthread_mutex_init_calloc_cb(pthread_mu
 		.m_robust = PTHREAD_MUTEX_STALLED
 	};
 	int	error;
-	_thread_printf(2, "%s mp=%p\n", __func__, mp);
 	error = mutex_init(mp, &attr);
-	if (error == 0) {
+	if (error == 0)
 		mp->__flags |= PMUTEX_FLAG_PRIVATE;
-	}
-	_thread_printf(2, "%s init erro=%dr\n", __func__, error);
 	return (error);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011100152.oAA1qAKa071192>