From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 29 18:07:02 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 55A6416A420; Thu, 29 Sep 2005 18:07:02 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from mv.twc.weather.com (mv.twc.weather.com [65.212.71.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8B54F43D4C; Thu, 29 Sep 2005 18:07:01 +0000 (GMT) (envelope-from jhb@FreeBSD.org) Received: from [10.50.41.233] (Not Verified[10.50.41.233]) by mv.twc.weather.com with NetIQ MailMarshal (v6, 0, 3, 8) id ; Thu, 29 Sep 2005 14:23:02 -0400 From: John Baldwin To: freebsd-hackers@freebsd.org, Poul-Henning Kamp Date: Thu, 29 Sep 2005 14:08:16 -0400 User-Agent: KMail/1.8 References: <20050929165538.GA20614@stud.fit.vutbr.cz> <20050929170425.GB3526@core.310.ru> In-Reply-To: <20050929170425.GB3526@core.310.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200509291408.18098.jhb@FreeBSD.org> Cc: Divacky Roman , Stanislav Sedov Subject: Re: dev_lock() question 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: Thu, 29 Sep 2005 18:07:02 -0000 On Thursday 29 September 2005 01:04 pm, Stanislav Sedov wrote: > On Thu, Sep 29, 2005 at 06:55:38PM +0200, Divacky Roman wrote: > > Hi, > > > > dev_lock() looks this way: > > > > void > > dev_lock(void) > > { > > if (!mtx_initialized(&devmtx)) > > mtx_init(&devmtx, "cdev", NULL, MTX_DEF); > > mtx_lock(&devmtx); > > } > > > > I wonder why is the mtx_initialized checking necessary? shouldnt explicit > > initialization be sufficient? > > > > thnx for answer > > > > roman > > Moving "mtx_initialized()" check into mtx_init will decrease speed of other > mutexes initialization. We must check if it's initialized here because of > it's not permiited to pass already initialized mutex to mtx_init(). Actually, you would think that it could be initialized either via an early SYSINIT() or in the init_mutexes() function in kern_mutex.c and thus not need the early check and avoid penalizing dev_lock(). phk, how early his dev_lock needed? -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org