buddy: fix wait_pri for buddy_reqs_wait_cancel()

we did not lower buddy->wait_pri if the cancel resulted in an empty
priority list. This was no problem, but the stricter assertions from the
previous commit would trigger, because they now require that the
priority list for wait_pri is filled.
parent 0e7e0670
......@@ -1733,12 +1733,34 @@ buddy_reqs_wait_fini_unlock(struct i_wait *w)
AZ(pthread_mutex_destroy(&w->wait_mtx));
}
/*
* to be called if an i_wait with prio pri is removed
*/
static inline void
buddy_new_wait_pri(buddy_t *buddy, unsigned pri)
{
if (buddy->waiting == 0)
buddy->wait_pri = 0;
else if (pri == buddy->wait_pri) {
while (VTAILQ_EMPTY(&buddy->reqs_head[pri])) {
if (pri == 0)
break;
pri--;
}
buddy->wait_pri = pri;
buddy_wait_work(buddy);
}
}
static inline void
buddy_reqs_wait_cancel(struct buddy_reqs *reqs)
{
struct buddy_reqs_head *head;
struct i_wait *w;
buddy_t *buddy;
unsigned pri;
CHECK_OBJ_NOTNULL(reqs, BUDDY_REQS_MAGIC);
w = &reqs->i_wait;
......@@ -1751,8 +1773,9 @@ buddy_reqs_wait_cancel(struct buddy_reqs *reqs)
if (w->state == IW_WAITING) {
/* remove from wait list, w->state could be outdated ! */
pri = w->pri;
buddy = reqs->buddy;
head = &buddy->reqs_head[w->pri];
head = &buddy->reqs_head[pri];
AZ(pthread_mutex_lock(&reqs->buddy->map_mtx));
AZ(pthread_mutex_lock(&w->wait_mtx));
......@@ -1768,8 +1791,8 @@ buddy_reqs_wait_cancel(struct buddy_reqs *reqs)
VTAILQ_REMOVE(head, reqs, i_wait.list);
w->state = IW_SIGNALLED;
}
if (buddy->waiting && buddy->wait_pri == w->pri)
buddy_wait_work(buddy);
buddy_new_wait_pri(buddy, pri);
ASSERT_WAITQ(buddy);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment