From owner-freebsd-hackers@FreeBSD.ORG Fri Jun 1 17:02:07 2007 Return-Path: X-Original-To: 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 E89DB16A530 for ; Fri, 1 Jun 2007 17:02:07 +0000 (UTC) (envelope-from sam@errno.com) Received: from ebb.errno.com (ebb.errno.com [69.12.149.25]) by mx1.freebsd.org (Postfix) with ESMTP id 7ACA013C465 for ; Fri, 1 Jun 2007 17:02:07 +0000 (UTC) (envelope-from sam@errno.com) Received: from trouble.errno.com (trouble.errno.com [10.0.0.248]) (authenticated bits=0) by ebb.errno.com (8.13.6/8.12.6) with ESMTP id l51GPRva097789 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 1 Jun 2007 09:25:29 -0700 (PDT) (envelope-from sam@errno.com) Message-ID: <46604877.7030007@errno.com> Date: Fri, 01 Jun 2007 09:25:27 -0700 From: Sam Leffler User-Agent: Thunderbird 2.0.0.0 (X11/20070528) MIME-Version: 1.0 To: Artis Caune References: <465FF29B.3010307@latnet.lv> In-Reply-To: <465FF29B.3010307@latnet.lv> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: hackers@freebsd.org 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: Fri, 01 Jun 2007 17:02:08 -0000 Artis Caune wrote: > Hello FreeBSD-hackers! > > what is the right way to stop callout which is initialized with mutex: > callout_init_mtx(&callout_function, &my_mtx, 0); > > should I lock mutex before calling callout_drain() or not? > > man page says: callout_drain() is identical to callout_stop() and > if the callout has an associated mutex, then that mutex must be held > when callout_stop() is called. > > > /* MOD_UNLOAD */ > > MTX_LOCK; > callout_drain() > MTX_UNLOCK; 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. Sam