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

Merge branch 'atomic-try-lock' into 'master'

[IO] replace the std::mutex.try_lock with our own std::atomic based implementation

See merge request !95
parents a61972a5 84734e5c
No related branches found
No related tags found
No related merge requests found
Pipeline #58293 passed
...@@ -179,7 +179,7 @@ template void IoContext::submit<CallerEnvironment::ANYWHERE>(Future &future); ...@@ -179,7 +179,7 @@ template void IoContext::submit<CallerEnvironment::ANYWHERE>(Future &future);
template <CallerEnvironment callerEnvironment> template <CallerEnvironment callerEnvironment>
void IoContext::reapCompletions() { void IoContext::reapCompletions() {
// Someone else is currently reaping completions // Someone else is currently reaping completions
if (unlikely(!cq_mutex.try_lock())) { if (unlikely(!cq_lock.try_lock())) {
return; return;
} }
...@@ -254,7 +254,7 @@ void IoContext::reapCompletions() { ...@@ -254,7 +254,7 @@ void IoContext::reapCompletions() {
} }
unlock: unlock:
cq_mutex.unlock(); cq_lock.unlock();
} }
// Show the compiler our template incarnations // Show the compiler our template incarnations
......
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
#include <cstdint> // for uint64_t #include <cstdint> // for uint64_t
#include <functional> // for less #include <functional> // for less
#include <memory> // for allocator #include <memory> // for allocator
#include <mutex> // for mutex
#include "CallerEnvironment.hpp" // for CallerEnvironment, EMPER #include "CallerEnvironment.hpp" // for CallerEnvironment, EMPER
#include "Debug.hpp" // for LogSubsystem, LogSubsystem::IO, Logger #include "Debug.hpp" // for LogSubsystem, LogSubsystem::IO, Logger
#include "Runtime.hpp" // for Runtime #include "Runtime.hpp" // for Runtime
#include "emper-config.h" // for EMPER_IO_WORKER_URING_ENTRIES #include "emper-config.h" // for EMPER_IO_WORKER_URING_ENTRIES
#include "io/Stats.hpp" // for Stats #include "io/Stats.hpp" // for Stats
#include "lib/adt/AtomicTryLock.hpp"
#include "lib/adt/LockedSet.hpp" // for LockedSet #include "lib/adt/LockedSet.hpp" // for LockedSet
namespace emper::io { namespace emper::io {
...@@ -44,9 +44,8 @@ class IoContext : public Logger<LogSubsystem::IO> { ...@@ -44,9 +44,8 @@ class IoContext : public Logger<LogSubsystem::IO> {
// to the global IoContext // to the global IoContext
static void startGlobalCompleter(IoContext &globalIo); static void startGlobalCompleter(IoContext &globalIo);
// Mutex protecting the completion queue of ring. // TryLock protecting the completion queue of ring.
// It is used with try_lock() in reapCompletions. lib::adt::AtomicTryLock cq_lock;
std::mutex cq_mutex;
struct io_uring ring; struct io_uring ring;
// eventfd registered with ring. // eventfd registered with ring.
......
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Fischer
#pragma once
#include <atomic>
#include "Common.hpp"
namespace emper::lib::adt {
class ALIGN_TO_CACHE_LINE AtomicTryLock {
private:
std::atomic<bool> locked;
public:
AtomicTryLock(bool locked = false) : locked(locked) {}
auto try_lock() -> bool {
bool previously_locked = locked.exchange(true, std::memory_order_acquire);
return !previously_locked;
}
void unlock() { locked.store(false, std::memory_order_release); }
};
} // namespace emper::lib::adt
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