diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2016-06-28 14:47:01 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2016-06-28 14:47:01 +0000 |
commit | 18166ac04a02243614424ec36c8a4574343ace5c (patch) | |
tree | 9312f0c8fc2208533212bf8c5ab9327f7dadfa14 /sys/kern | |
parent | aa2988a49ff376868fdb53910724b28e2b7629f6 (diff) |
introduce rwlock for socketbuf instead of the old flag and tsleep dance.
ok mikeb bluhm
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/uipc_socket2.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index dc8f23c9b2b..f86e3546b0c 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.63 2015/10/06 14:38:32 claudio Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.64 2016/06/28 14:47:00 tedu Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -185,6 +185,9 @@ sonewconn(struct socket *head, int connstatus) so->so_rcv.sb_lowat = head->so_rcv.sb_lowat; so->so_rcv.sb_timeo = head->so_rcv.sb_timeo; + rw_init(&so->so_rcv.sb_lock, "sbsndl"); + rw_init(&so->so_snd.sb_lock, "sbrcvl"); + soqinsque(head, so, soqueue); if ((*so->so_proto->pr_usrreq)(so, PRU_ATTACH, NULL, NULL, NULL, curproc)) { @@ -286,22 +289,26 @@ sbwait(struct sockbuf *sb) * return any error returned from sleep (EINTR). */ int -sb_lock(struct sockbuf *sb) +sblock(struct sockbuf *sb, int wf) { int error; - while (sb->sb_flags & SB_LOCK) { - sb->sb_flags |= SB_WANT; - error = tsleep(&sb->sb_flags, - (sb->sb_flags & SB_NOINTR) ? - PSOCK : PSOCK|PCATCH, "netlck", 0); - if (error) - return (error); - } - sb->sb_flags |= SB_LOCK; - return (0); + error = rw_enter(&sb->sb_lock, RW_WRITE | + (sb->sb_flags & SB_NOINTR ? 0 : RW_INTR) | + (wf == M_WAITOK ? 0 : RW_NOSLEEP)); + + if (error == EBUSY) + error = EWOULDBLOCK; + return (error); } +void +sbunlock(struct sockbuf *sb) +{ + rw_exit(&sb->sb_lock); +} + + /* * Wakeup processes waiting on a socket buffer. * Do asynchronous notification via SIGIO @@ -827,7 +834,7 @@ void sbflush(struct sockbuf *sb) { - KASSERT((sb->sb_flags & SB_LOCK) == 0); + rw_assert_unlocked(&sb->sb_lock); while (sb->sb_mbcnt) sbdrop(sb, (int)sb->sb_cc); |