From owner-svn-src-head@FreeBSD.ORG Wed Oct 27 04:19:08 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D96D106564A; Wed, 27 Oct 2010 04:19:08 +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 2C57F8FC14; Wed, 27 Oct 2010 04:19:08 +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 o9R4J8Tl088083; Wed, 27 Oct 2010 04:19:08 GMT (envelope-from davidxu@svn.freebsd.org) Received: (from davidxu@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o9R4J8Mj088081; Wed, 27 Oct 2010 04:19:08 GMT (envelope-from davidxu@svn.freebsd.org) Message-Id: <201010270419.o9R4J8Mj088081@svn.freebsd.org> From: David Xu Date: Wed, 27 Oct 2010 04:19:08 +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: r214410 - head/lib/libthr/thread X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Oct 2010 04:19:08 -0000 Author: davidxu Date: Wed Oct 27 04:19:07 2010 New Revision: 214410 URL: http://svn.freebsd.org/changeset/base/214410 Log: Remove locking and unlock in pthread_mutex_destroy, because it can not fix race condition in application code, as a result, the problem described in PR threads/151767 is avoided. Modified: head/lib/libthr/thread/thr_mutex.c Modified: head/lib/libthr/thread/thr_mutex.c ============================================================================== --- head/lib/libthr/thread/thr_mutex.c Wed Oct 27 02:32:54 2010 (r214409) +++ head/lib/libthr/thread/thr_mutex.c Wed Oct 27 04:19:07 2010 (r214410) @@ -257,10 +257,8 @@ _mutex_fork(struct pthread *curthread) int _pthread_mutex_destroy(pthread_mutex_t *mutex) { - struct pthread *curthread = _get_curthread(); pthread_mutex_t m; - uint32_t id; - int ret = 0; + int ret; m = *mutex; if (m < THR_MUTEX_DESTROYED) { @@ -268,34 +266,13 @@ _pthread_mutex_destroy(pthread_mutex_t * } else if (m == THR_MUTEX_DESTROYED) { ret = EINVAL; } else { - id = TID(curthread); - - /* - * Try to lock the mutex structure, we only need to - * try once, if failed, the mutex is in used. - */ - ret = _thr_umutex_trylock(&m->m_lock, id); - if (ret) - return (ret); - /* - * Check mutex other fields to see if this mutex is - * in use. Mostly for prority mutex types, or there - * are condition variables referencing it. - */ if (m->m_owner != NULL || m->m_refcount != 0) { - if (m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) - set_inherited_priority(curthread, m); - _thr_umutex_unlock(&m->m_lock, id); ret = EBUSY; } else { *mutex = THR_MUTEX_DESTROYED; - - if (m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) - set_inherited_priority(curthread, m); - _thr_umutex_unlock(&m->m_lock, id); - MUTEX_ASSERT_NOT_OWNED(m); free(m); + ret = 0; } }