diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-07-13 10:32:46 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-07-13 10:36:11 +0000 |
commit | f3ff911f3cfeb6af3e32513c4301be389a936d76 (patch) | |
tree | a93d07a4b4347c5f6031df0e74e3c731b0faad72 | |
parent | 6333dc06a23a80690f60f3659428df88bd19d736 (diff) | |
download | cmogstored-f3ff911f3cfeb6af3e32513c4301be389a936d76.tar.gz |
We could be completely out of threads upon acquiring an ioq, so the last thread to acquire a lock slot must trigger a yield soon to avoid starvation and fairness issues. Otherwise, all threads for a given device could remained pinned indefinitely.
-rw-r--r-- | ioq.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -46,8 +46,14 @@ bool mog_ioq_ready(struct mog_ioq *ioq, struct mog_fd *client_mfd) CHECK(int, 0, pthread_mutex_lock(&ioq->mtx)); good = ioq->cur > 0; - if (good) { /* uncontended case is simple */ - ioq->cur--; + if (good) { + /* + * assume the worst when we are the last one to + * acquire a free slot + */ + if (--ioq->cur == 0) + ioq_set_contended(ioq); + mog_ioq_current = ioq; } else { client_mfd->ioq_blocked = 1; |