about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-07-13 10:32:46 +0000
committerEric Wong <normalperson@yhbt.net>2013-07-13 10:36:11 +0000
commitf3ff911f3cfeb6af3e32513c4301be389a936d76 (patch)
treea93d07a4b4347c5f6031df0e74e3c731b0faad72
parent6333dc06a23a80690f60f3659428df88bd19d736 (diff)
downloadcmogstored-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.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/ioq.c b/ioq.c
index 0a32c71..772da38 100644
--- a/ioq.c
+++ b/ioq.c
@@ -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;