From owner-p4-projects@FreeBSD.ORG Sat Nov 20 05:08:46 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4FAE316A4D0; Sat, 20 Nov 2004 05:08:46 +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 1424116A4CE for ; Sat, 20 Nov 2004 05:08:46 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id EC30343D46 for ; Sat, 20 Nov 2004 05:08:45 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id iAK58jUY013728 for ; Sat, 20 Nov 2004 05:08:45 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id iAK58juA013725 for perforce@freebsd.org; Sat, 20 Nov 2004 05:08:45 GMT (envelope-from davidxu@freebsd.org) Date: Sat, 20 Nov 2004 05:08:45 GMT Message-Id: <200411200508.iAK58juA013725@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 65530 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: Sat, 20 Nov 2004 05:08:46 -0000 http://perforce.freebsd.org/chv.cgi?CH=65530 Change 65530 by davidxu@davidxu_alona on 2004/11/20 05:08:07 Use rwlock for rtld, current it is not used. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_rtld.c#2 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_rtld.c#2 (text+ko) ==== @@ -41,7 +41,6 @@ static int _thr_rtld_set_flag(int); static void _thr_rtld_wlock_acquire(void *); -#ifdef NOTYET static void * _thr_rtld_lock_create(void) { @@ -145,156 +144,3 @@ { _rtld_thread_init(NULL); } -#endif - -struct rtld_kse_lock { - struct lock lck; - struct kse *owner; - kse_critical_t crit; - int count; - int write; -}; - -static void * -_thr_rtld_lock_create(void) -{ - struct rtld_kse_lock *l; - - l = malloc(sizeof(struct rtld_kse_lock)); - _lock_init(&l->lck, LCK_ADAPTIVE, _kse_lock_wait, _kse_lock_wakeup); - l->owner = NULL; - l->count = 0; - l->write = 0; - return (l); -} - -static void -_thr_rtld_lock_destroy(void *lock) -{ - /* XXX We really can not free memory after a fork() */ -#if 0 - struct rtld_kse_lock *l; - - l = (struct rtld_kse_lock *)lock; - _lock_destroy(&l->lck); - free(l); -#endif - return; -} - -static void -_thr_rtld_rlock_acquire(void *lock) -{ - struct rtld_kse_lock *l; - kse_critical_t crit; - struct kse *curkse; - - l = (struct rtld_kse_lock *)lock; - crit = _kse_critical_enter(); - curkse = _get_curkse(); - if (l->owner == curkse) { - l->count++; - _kse_critical_leave(crit); /* probably not necessary */ - } else { - KSE_LOCK_ACQUIRE(curkse, &l->lck); - l->crit = crit; - l->owner = curkse; - l->count = 1; - l->write = 0; - } -} - -static void -_thr_rtld_wlock_acquire(void *lock) -{ - struct rtld_kse_lock *l; - kse_critical_t crit; - struct kse *curkse; - - l = (struct rtld_kse_lock *)lock; - crit = _kse_critical_enter(); - curkse = _get_curkse(); - if (l->owner == curkse) { - _kse_critical_leave(crit); - PANIC("Recursive write lock attempt on rtld lock"); - } else { - KSE_LOCK_ACQUIRE(curkse, &l->lck); - l->crit = crit; - l->owner = curkse; - l->count = 1; - l->write = 1; - } -} - -static void -_thr_rtld_lock_release(void *lock) -{ - struct rtld_kse_lock *l; - kse_critical_t crit; - struct kse *curkse; - - l = (struct rtld_kse_lock *)lock; - crit = _kse_critical_enter(); - curkse = _get_curkse(); - if (l->owner != curkse) { - /* - * We might want to forcibly unlock the rtld lock - * and/or disable threaded mode so there is better - * chance that the panic will work. Otherwise, - * we could end up trying to take the rtld lock - * again. - */ - _kse_critical_leave(crit); - PANIC("Attempt to unlock rtld lock when not owner."); - } else { - l->count--; - if (l->count == 0) { - /* - * If there ever is a count associated with - * _kse_critical_leave(), we'll need to add - * another call to it here with the crit - * value from above. - */ - crit = l->crit; - l->owner = NULL; - l->write = 0; - KSE_LOCK_RELEASE(curkse, &l->lck); - } - _kse_critical_leave(crit); - } -} - - -static int -_thr_rtld_set_flag(int mask) -{ - return (0); -} - -static int -_thr_rtld_clr_flag(int mask) -{ - return (0); -} - -void -_thr_rtld_init(void) -{ - struct RtldLockInfo li; - - li.lock_create = _thr_rtld_lock_create; - li.lock_destroy = _thr_rtld_lock_destroy; - li.rlock_acquire = _thr_rtld_rlock_acquire; - li.wlock_acquire = _thr_rtld_wlock_acquire; - li.lock_release = _thr_rtld_lock_release; - li.thread_set_flag = _thr_rtld_set_flag; - li.thread_clr_flag = _thr_rtld_clr_flag; - li.at_fork = NULL; - _rtld_thread_init(&li); -} - -void -_thr_rtld_fini(void) -{ - _rtld_thread_init(NULL); -}