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.
This commit is contained in:
Bosko Milekic 2001-01-20 21:29:10 +00:00
parent 08b2398e6d
commit 56acb799b2
2 changed files with 6 additions and 9 deletions

View File

@ -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.

View File

@ -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)
/*