From 56acb799b29fcc5cb5cf7ddb974f3aee9828fff2 Mon Sep 17 00:00:00 2001 From: Bosko Milekic Date: Sat, 20 Jan 2001 21:29:10 +0000 Subject: [PATCH] When short of mbufs or mbuf clusters, we sleep on appropriate "counters." The counters are incremented when a thread goes to sleep and decremented either when a thread is woken up by another thread or when the sleep times out. There existed a race where the sleep count could be decremented twice resulting in an eventual underflow. Move the decrementing of the "counters" to the thread initiating the sleep and thus remedy the problem. --- sys/kern/uipc_mbuf.c | 11 +++++------ sys/sys/mbuf.h | 4 +--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 9c2437020270..8a984ac26491 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -353,9 +353,9 @@ m_mballoc_wait(void) if (p == NULL) { m_mballoc_wid++; - if (msleep(&m_mballoc_wid, &mmbfree.m_mtx, PVM, "mballc", - mbuf_wait) == EWOULDBLOCK) - m_mballoc_wid--; + msleep(&m_mballoc_wid, &mmbfree.m_mtx, PVM, "mballc", + mbuf_wait); + m_mballoc_wid--; /* * Try again (one last time). @@ -463,9 +463,8 @@ m_clalloc_wait(void) caddr_t p = NULL; m_clalloc_wid++; - if (msleep(&m_clalloc_wid, &mclfree.m_mtx, PVM, "mclalc", mbuf_wait) - == EWOULDBLOCK) - m_clalloc_wid--; + msleep(&m_clalloc_wid, &mclfree.m_mtx, PVM, "mclalc", mbuf_wait); + m_clalloc_wid--; /* * Now that we (think) that we've got something, try again. diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 1643404b37af..eab24f2bc245 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -273,10 +273,8 @@ struct mcntfree_lst { * Must be called with the appropriate mutex held. */ #define MBWAKEUP(m_wid) do { \ - if ((m_wid)) { \ - m_wid--; \ + if ((m_wid)) \ wakeup_one(&(m_wid)); \ - } \ } while (0) /*