From owner-freebsd-hackers@FreeBSD.ORG Tue Jun 5 19:51:58 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C0E7316A469; Tue, 5 Jun 2007 19:51:58 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.freebsd.org (Postfix) with ESMTP id 5774113C465; Tue, 5 Jun 2007 19:51:58 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.13.8/8.13.8) with ESMTP id l55JphV2030407; Tue, 5 Jun 2007 15:51:54 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Tue, 5 Jun 2007 15:50:53 -0400 User-Agent: KMail/1.9.6 References: <465FF29B.3010307@latnet.lv> <46604877.7030007@errno.com> <4663DDD4.1020207@latnet.lv> In-Reply-To: <4663DDD4.1020207@latnet.lv> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200706051550.54460.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Tue, 05 Jun 2007 15:51:54 -0400 (EDT) X-Virus-Scanned: ClamAV 0.88.3/3362/Tue Jun 5 13:02:53 2007 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: hackers@freebsd.org, Artis Caune Subject: Re: stopping callouts X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jun 2007 19:51:58 -0000 On Monday 04 June 2007 05:39:32 am Artis Caune wrote: > Sam Leffler wrote: > > > > If you use callout_init_mtx then use callout_stop while holding my_mtx; > > if the callout is blocked waiting for my_mtx the request will be discarded. > > > > callout_drain should not be called while holding my_mtx because it can > > sleep. > > > > > Thanks, > than I will use: > > > MTX_LOCK; > ... > callout_stop(); > MTX_UNLOCK; During module unload (or device detach) you should still do a callout_drain() before destroying the mutex, to make sure softclock() doesn't race with the mtx_destroy(). Thus: foo_detach() { FOO_LOCK(sc); foo_stop(sc); callout_stop(&sc->callout); FOO_UNLOCK(sc); bus_teardown_intr(...) bus_release_resources(...); callout_drain(&sc->callout); mtx_destroy(&sc->lock); } -- John Baldwin