Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Jun 2017 23:49:57 -0700
From:      John-Mark Gurney <jmg@funkthat.com>
To:        Jia-Ju Bai <baijiaju1990@163.com>
Cc:        freebsd-drivers@freebsd.org
Subject:   Re: A question about in lock usage in FreeBSD
Message-ID:  <20170615064957.GA2042@funkthat.com>
In-Reply-To: <593FE1C9.2060706@163.com>
References:  <593FE1C9.2060706@163.com>

next in thread | previous in thread | raw e-mail | index | archive | help
dropped -quesetions as that isn't the best list for this question.

Jia-Ju Bai wrote this message on Tue, Jun 13, 2017 at 20:59 +0800:
> I am a freshman in developing FreeBSD drivers, and I have a question in 
> lock usage in FreeBSD.
> 
> The kernel provides some kinds of locks in developing drivers, such as 
> "mutex lock", "mutex spin lock", "rw lock" and "sx lock". I want to know 
> which locks should be held when the thread can sleep.
>  From my knowledge of FreeBSD document, I make the following points:
> (1) "rw lock" and "sx lock" can be used in this situation;
> (2) "mutex lock" and "mutex spin lock" are forbidden in this situation.
> 
> If my points are right, I will make another point:
> mutex_lock will let the thread sleep when the lock is requested, so the 
> mutex_lock can not be called in nested style (namely it is unsafe that 
> mutex_lock is called again when a "mutex lock" is held).
> 
> Are my points are right?
> I am looking forward to useful opinions and answers :)

Have you read the locking(9)[1] man page?  That should answer all of
your questions wrt locking.

[1] https://www.freebsd.org/cgi/man.cgi?query=locking&sektion=9&apropos=0&manpath=FreeBSD+11.0-RELEASE+and+Ports

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170615064957.GA2042>