From owner-cvs-src@FreeBSD.ORG Wed Oct 15 15:04:22 2003 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E435F16A4B3; Wed, 15 Oct 2003 15:04:22 -0700 (PDT) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8695043FE1; Wed, 15 Oct 2003 15:04:21 -0700 (PDT) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (localhost [127.0.0.1]) by fledge.watson.org (8.12.9p2/8.12.9) with ESMTP id h9FM3gMg057292; Wed, 15 Oct 2003 18:03:42 -0400 (EDT) (envelope-from robert@fledge.watson.org) Received: from localhost (robert@localhost)h9FM3gPC057289; Wed, 15 Oct 2003 18:03:42 -0400 (EDT) (envelope-from robert@fledge.watson.org) Date: Wed, 15 Oct 2003 18:03:42 -0400 (EDT) From: Robert Watson X-Sender: robert@fledge.watson.org To: John Baldwin In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: Jeff Roberson cc: Jeff Roberson cc: src-committers@FreeBSD.org cc: cvs-all@FreeBSD.org cc: cvs-src@FreeBSD.org Subject: RE: cvs commit: src/sys/sys mutex.h X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Oct 2003 22:04:23 -0000 On Tue, 14 Oct 2003, John Baldwin wrote: > > I know it is racy in most contexts. I use it to check to see if a thread > > on the runq owns giant. Since I have the sched lock it isn't racy but > > even if it was it wouldn't matter in this case. > > sched lock doesn't keep it from being racy. Uncontested acquire and > releases don't go anywhere near sched lock. Are you checking a > non-curthread thread pointer? Maybe you could just do it for curthread > and that would be enough for your heuristic, i.e. > > if (thread == curthread && mtx_owned(&Giant)) { > ... > } > > I'm just worried that if this is there someone is going to use it. :( You mean like this? while (mtx_trylock(&my_favorite_mtx)) { int gotthebastard; struct thread *td; struct proc *p; gotthebastard = 0; sx_slock(&allproc_lock); LIST_FOREACH(p, &allproc, p_list) { PROC_LOCK(p); FOREACH_THREAD_IN_PROC(p, td) { if (mtx_ownedby(&my_favorite_mtx, td)) { psignal(p, SIGKILL); gotthebastard = 1; break; } } PROC_UNLOCK(p); if (gotthebastard) break; } sx_sunlock(&allproc_lock); printf("Someone else owned the mutex, but I got the bastard\n"); } Robert N M Watson FreeBSD Core Team, TrustedBSD Projects robert@fledge.watson.org Network Associates Laboratories