Skip to content
Snippets Groups Projects
Commit d003e9c6 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Merge branch 'ubq' into 'master'

Improve code readability of UnboundedBlockingMpscQueue

See merge request i4/manycore/emper!52
parents 6f0509b6 e8fcfd97
No related branches found
No related tags found
No related merge requests found
...@@ -33,13 +33,14 @@ class UnboundedBlockingMpscQueue : public Blockable<LogSubsystem::U_B_MPSC_Q> { ...@@ -33,13 +33,14 @@ class UnboundedBlockingMpscQueue : public Blockable<LogSubsystem::U_B_MPSC_Q> {
// Therefore if we tryToGet a new 't' while 't' is available the current 't' // Therefore if we tryToGet a new 't' while 't' is available the current 't'
// would be overridden and dropped. // would be overridden and dropped.
assert(!tPopped); assert(!tPopped);
std::lock_guard<std::mutex> lock(queueMutex); std::lock_guard<std::mutex> lock(queueMutex);
if (!mpscQueue.empty()) { if (mpscQueue.empty()) return;
t = mpscQueue.front();
mpscQueue.pop(); t = mpscQueue.front();
tPopped = true; mpscQueue.pop();
postRetrieve(); tPopped = true;
} postRetrieve();
} }
public: public:
...@@ -54,7 +55,7 @@ class UnboundedBlockingMpscQueue : public Blockable<LogSubsystem::U_B_MPSC_Q> { ...@@ -54,7 +55,7 @@ class UnboundedBlockingMpscQueue : public Blockable<LogSubsystem::U_B_MPSC_Q> {
// Micro optimization, see if there is a blocked context // Micro optimization, see if there is a blocked context
// before performing the atomic exchange operation. // before performing the atomic exchange operation.
if (blockedContext.load() != nullptr) { if (blockedContext != nullptr) {
tryToWakeupBlockedContext<callerEnvironment>(); tryToWakeupBlockedContext<callerEnvironment>();
} }
} }
...@@ -82,10 +83,16 @@ class UnboundedBlockingMpscQueue : public Blockable<LogSubsystem::U_B_MPSC_Q> { ...@@ -82,10 +83,16 @@ class UnboundedBlockingMpscQueue : public Blockable<LogSubsystem::U_B_MPSC_Q> {
}); });
if (!tPopped) { if (!tPopped) {
std::lock_guard<std::mutex> lock(queueMutex); std::lock_guard<std::mutex> lock(queueMutex);
// If we observed tPopped to be false without holding the
// queueMutex, then the same must be true when holding the
// mutex.
assert(!tPopped);
// If 't' isn't already set, then mspcQueue.get() MUST // If 't' isn't already set, then mspcQueue.get() MUST
// return an element. Note that a non-lineralizabe // return an element. Note that a non-lineralizabe
// queue may break this invariant. // queue may break this invariant.
assert(!mpscQueue.empty()); assert(!mpscQueue.empty());
t = mpscQueue.front(); t = mpscQueue.front();
mpscQueue.pop(); mpscQueue.pop();
postRetrieve(); postRetrieve();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment