why use INP_WLOCK instead of INP_RLOCK

John Baldwin jhb at freebsd.org
Fri Mar 25 21:01:36 UTC 2011


On Tuesday, February 01, 2011 12:54:33 am Jim wrote:
> Hi All,
> 
> I am not sure if anybody has asked it before. I could not find answer by
> doing rough search on Internet, if it is duplicate question, sorry in
> advance.
> 
> My question is that, for getting socket options in tcp_ctloutput() in
> tcp_usrreq.c, why do we need to do lock with INP_WLOCK(inp) as setting
> socket options does. Why do we just use INP_RLOCK(inp), as it looks not
> changing anything in tcp control block?
> 
> Thank you for your kindly answer.

I think mostly it is just because no one has bothered to change it.  
Realistically it probably won't make any noticable difference unless your 
workload consists of doing lots of calls to getsockopt() but not sending any 
actual traffic on the associated sockets. :)  (Almost all of the other 
operations on a TCP connection require a write lock on the pcb.)

-- 
John Baldwin


More information about the freebsd-net mailing list