Skip to content

Commit

Permalink
Introduce getWaitCount() method for FiberLock
Browse files Browse the repository at this point in the history
  - Determines the number of fibers waiting on the lock
  • Loading branch information
finneyj committed Oct 12, 2020
1 parent 72d3175 commit e0089a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions inc/core/CodalFiber.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ namespace codal
* Release the lock, and signal to all waiting fibers to continue
*/
void notifyAll();

/**
* Determine the number of fibers currently blocked on this lock
*/
int getWaitCount();
};
}

Expand Down
18 changes: 18 additions & 0 deletions source/core/CodalFiber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,4 +1067,22 @@ void FiberLock::notifyAll()
}

locked = false;
}


/**
* Determine the number of fibers currently blocked on this lock
*/
int FiberLock::getWaitCount()
{
Fiber *f = queue;
int count = 0;

while (f)
{
count++;
f = f->qnext;
}

return count;
}

0 comments on commit e0089a9

Please sign in to comment.