fix: remove fiber guard from non atomic section (#3381)

We might preempt when we serialize a big value and the code in journal was protected by an atomic guard triggering a check failed.

* remove fiber guard from non atomic section
* move LocalBlockingCounter to common

---------

Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
Kostas Kyrimis 2024-07-25 16:06:35 +03:00 committed by GitHub
parent e2d65a0900
commit 4b851be57a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 31 deletions

View file

@ -15,6 +15,7 @@
#include <string_view>
#include <vector>
#include "base/logging.h"
#include "facade/facade_types.h"
#include "facade/op_status.h"
#include "util/fibers/fibers.h"
@ -381,4 +382,28 @@ class ConditionGuard {
ConditionFlag* enclosing_;
};
class LocalBlockingCounter {
public:
void lock() {
++mutating_;
}
void unlock() {
DCHECK(mutating_ > 0);
--mutating_;
if (mutating_ == 0) {
cond_var_.notify_one();
}
}
void Wait() {
util::fb2::NoOpLock noop_lk_;
cond_var_.wait(noop_lk_, [this]() { return mutating_ == 0; });
}
private:
util::fb2::CondVarAny cond_var_;
size_t mutating_ = 0;
};
} // namespace dfly