From owner-p4-projects@FreeBSD.ORG Sun Jan 16 00:45:38 2005 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 53F1F16A4D0; Sun, 16 Jan 2005 00:45:38 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 155DF16A4CE for ; Sun, 16 Jan 2005 00:45:38 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id D59E843D39 for ; Sun, 16 Jan 2005 00:45:37 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j0G0jbvd007646 for ; Sun, 16 Jan 2005 00:45:37 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j0G0jbbp007643 for perforce@freebsd.org; Sun, 16 Jan 2005 00:45:37 GMT (envelope-from davidxu@freebsd.org) Date: Sun, 16 Jan 2005 00:45:37 GMT Message-Id: <200501160045.j0G0jbbp007643@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to davidxu@freebsd.org using -f From: David Xu To: Perforce Change Reviews Subject: PERFORCE change 69094 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Jan 2005 00:45:38 -0000 http://perforce.freebsd.org/chv.cgi?CH=69094 Change 69094 by davidxu@davidxu_tiger on 2005/01/16 00:45:34 Use umtx_wait and umtx_wake. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_barrier.c#3 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_barrierattr.c#3 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_barrier.c#3 (text+ko) ==== @@ -41,7 +41,6 @@ _pthread_barrier_destroy(pthread_barrier_t *barrier) { pthread_barrier_t bar; - int ret, ret2; if (barrier == NULL || *barrier == NULL) return (EINVAL); @@ -50,10 +49,8 @@ if (bar->b_waiters > 0) return (EBUSY); *barrier = NULL; - ret = _pthread_mutex_destroy(&bar->b_lock); - ret2 = _pthread_cond_destroy(&bar->b_cond); free(bar); - return (ret ? ret : ret2); + return (0); } int @@ -61,7 +58,6 @@ const pthread_barrierattr_t *attr, int count) { pthread_barrier_t bar; - int ret; if (barrier == NULL || count <= 0) return (EINVAL); @@ -70,20 +66,10 @@ if (bar == NULL) return (ENOMEM); - if ((ret = _pthread_mutex_init(&bar->b_lock, NULL)) != 0) { - free(bar); - return (ret); - } - - if ((ret = _pthread_cond_init(&bar->b_cond, NULL)) != 0) { - _pthread_mutex_destroy(&bar->b_lock); - free(bar); - return (ret); - } - + umtx_init(&bar->b_lock); + bar->b_cycle = 0; bar->b_waiters = 0; bar->b_count = count; - bar->b_cycle = 0; *barrier = bar; return (0); @@ -92,31 +78,31 @@ int _pthread_barrier_wait(pthread_barrier_t *barrier) { - int ret, cycle; + struct pthread *curthread = _get_curthread(); pthread_barrier_t bar; + long cycle; + int ret; if (barrier == NULL || *barrier == NULL) return (EINVAL); bar = *barrier; - if ((ret = _pthread_mutex_lock(&bar->b_lock)) != 0) - return (ret); - + THR_UMTX_LOCK(curthread, &bar->b_lock); if (++bar->b_waiters == bar->b_count) { /* Current thread is lastest thread */ + bar->b_waiters = 0; bar->b_cycle++; - bar->b_waiters = 0; - ret = _pthread_cond_broadcast(&bar->b_cond); - if (ret == 0) - ret = PTHREAD_BARRIER_SERIAL_THREAD; + umtx_wake((struct umtx *)&bar->b_cycle, INT_MAX); + THR_UMTX_UNLOCK(curthread, &bar->b_lock); + ret = PTHREAD_BARRIER_SERIAL_THREAD; } else { cycle = bar->b_cycle; + THR_UMTX_UNLOCK(curthread, &bar->b_lock); do { - ret = _pthread_cond_wait( - &bar->b_cond, &bar->b_lock); - /* test cycle to avoid bogus wakeup */ - } while (ret == 0 && cycle == bar->b_cycle); + umtx_wait((struct umtx *)&bar->b_cycle, cycle); + /* test cycle to avoid bogus wakeup */ + } while (cycle == bar->b_cycle); + ret = 0; } - _pthread_mutex_unlock(&bar->b_lock); return (ret); } ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_barrierattr.c#3 (text+ko) ====