From owner-svn-src-all@FreeBSD.ORG Tue Jan 5 03:39:31 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8F08E1065692; Tue, 5 Jan 2010 03:39:31 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7D3708FC0A; Tue, 5 Jan 2010 03:39:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o053dVdj075173; Tue, 5 Jan 2010 03:39:31 GMT (envelope-from davidxu@svn.freebsd.org) Received: (from davidxu@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o053dV1j075171; Tue, 5 Jan 2010 03:39:31 GMT (envelope-from davidxu@svn.freebsd.org) Message-Id: <201001050339.o053dV1j075171@svn.freebsd.org> From: David Xu Date: Tue, 5 Jan 2010 03:39:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r201547 - head/lib/libc/gen X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jan 2010 03:39:31 -0000 Author: davidxu Date: Tue Jan 5 03:39:31 2010 New Revision: 201547 URL: http://svn.freebsd.org/changeset/base/201547 Log: Don't check has_waiters twice, inline some small functions. performance result on my machine: mutex Elapsed: 902115 us; per iteration: 90 ns. semaphore Elapsed: 958780 us; per iteration: 95 ns. Modified: head/lib/libc/gen/sem_new.c Modified: head/lib/libc/gen/sem_new.c ============================================================================== --- head/lib/libc/gen/sem_new.c Tue Jan 5 02:37:59 2010 (r201546) +++ head/lib/libc/gen/sem_new.c Tue Jan 5 03:39:31 2010 (r201547) @@ -331,7 +331,7 @@ _libc_sem_getvalue(sem_t * __restrict se return (0); } -static int +static __inline int usem_wake(struct _usem *sem) { if (!sem->_has_waiters) @@ -339,7 +339,7 @@ usem_wake(struct _usem *sem) return _umtx_op(sem, UMTX_OP_SEM_WAKE, 0, NULL, NULL); } -static int +static __inline int usem_wait(struct _usem *sem, const struct timespec *timeout) { if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 && @@ -387,7 +387,7 @@ sem_cancel_handler(void *arg) } while (0) -static int +static __inline int enable_async_cancel(void) { int old; @@ -396,7 +396,7 @@ enable_async_cancel(void) return (old); } -static void +static __inline void restore_async_cancel(int val) { _pthread_setcanceltype(val, NULL); @@ -413,7 +413,6 @@ _libc_sem_timedwait(sem_t * __restrict s return (-1); retval = 0; - _pthread_testcancel(); for (;;) { while ((val = sem->_kern._count) > 0) { if (atomic_cmpset_acq_int(&sem->_kern._count, val, val - 1)) @@ -464,7 +463,5 @@ _libc_sem_post(sem_t *sem) return (-1); atomic_add_rel_int(&sem->_kern._count, 1); - if (sem->_kern._has_waiters) - return usem_wake(&sem->_kern); - return (0); + return usem_wake(&sem->_kern); }