diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/detached_tasks.cpp | 8 | ||||
| -rw-r--r-- | src/common/logging/backend.cpp | 6 | ||||
| -rw-r--r-- | src/common/thread.h | 10 | ||||
| -rw-r--r-- | src/common/threadsafe_queue.h | 4 |
4 files changed, 14 insertions, 14 deletions
diff --git a/src/common/detached_tasks.cpp b/src/common/detached_tasks.cpp index a347d9e02..f268d6021 100644 --- a/src/common/detached_tasks.cpp +++ b/src/common/detached_tasks.cpp | |||
| @@ -16,22 +16,22 @@ DetachedTasks::DetachedTasks() { | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | void DetachedTasks::WaitForAllTasks() { | 18 | void DetachedTasks::WaitForAllTasks() { |
| 19 | std::unique_lock<std::mutex> lock(mutex); | 19 | std::unique_lock lock{mutex}; |
| 20 | cv.wait(lock, [this]() { return count == 0; }); | 20 | cv.wait(lock, [this]() { return count == 0; }); |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | DetachedTasks::~DetachedTasks() { | 23 | DetachedTasks::~DetachedTasks() { |
| 24 | std::unique_lock<std::mutex> lock(mutex); | 24 | std::unique_lock lock{mutex}; |
| 25 | ASSERT(count == 0); | 25 | ASSERT(count == 0); |
| 26 | instance = nullptr; | 26 | instance = nullptr; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | void DetachedTasks::AddTask(std::function<void()> task) { | 29 | void DetachedTasks::AddTask(std::function<void()> task) { |
| 30 | std::unique_lock<std::mutex> lock(instance->mutex); | 30 | std::unique_lock lock{instance->mutex}; |
| 31 | ++instance->count; | 31 | ++instance->count; |
| 32 | std::thread([task{std::move(task)}]() { | 32 | std::thread([task{std::move(task)}]() { |
| 33 | task(); | 33 | task(); |
| 34 | std::unique_lock<std::mutex> lock(instance->mutex); | 34 | std::unique_lock lock{instance->mutex}; |
| 35 | --instance->count; | 35 | --instance->count; |
| 36 | std::notify_all_at_thread_exit(instance->cv, std::move(lock)); | 36 | std::notify_all_at_thread_exit(instance->cv, std::move(lock)); |
| 37 | }) | 37 | }) |
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 4462ff3fb..a03179520 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -46,12 +46,12 @@ public: | |||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | void AddBackend(std::unique_ptr<Backend> backend) { | 48 | void AddBackend(std::unique_ptr<Backend> backend) { |
| 49 | std::lock_guard<std::mutex> lock(writing_mutex); | 49 | std::lock_guard lock{writing_mutex}; |
| 50 | backends.push_back(std::move(backend)); | 50 | backends.push_back(std::move(backend)); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | void RemoveBackend(std::string_view backend_name) { | 53 | void RemoveBackend(std::string_view backend_name) { |
| 54 | std::lock_guard<std::mutex> lock(writing_mutex); | 54 | std::lock_guard lock{writing_mutex}; |
| 55 | const auto it = | 55 | const auto it = |
| 56 | std::remove_if(backends.begin(), backends.end(), | 56 | std::remove_if(backends.begin(), backends.end(), |
| 57 | [&backend_name](const auto& i) { return backend_name == i->GetName(); }); | 57 | [&backend_name](const auto& i) { return backend_name == i->GetName(); }); |
| @@ -80,7 +80,7 @@ private: | |||
| 80 | backend_thread = std::thread([&] { | 80 | backend_thread = std::thread([&] { |
| 81 | Entry entry; | 81 | Entry entry; |
| 82 | auto write_logs = [&](Entry& e) { | 82 | auto write_logs = [&](Entry& e) { |
| 83 | std::lock_guard<std::mutex> lock(writing_mutex); | 83 | std::lock_guard lock{writing_mutex}; |
| 84 | for (const auto& backend : backends) { | 84 | for (const auto& backend : backends) { |
| 85 | backend->Write(e); | 85 | backend->Write(e); |
| 86 | } | 86 | } |
diff --git a/src/common/thread.h b/src/common/thread.h index c5fc3533d..0cfd98be6 100644 --- a/src/common/thread.h +++ b/src/common/thread.h | |||
| @@ -15,7 +15,7 @@ namespace Common { | |||
| 15 | class Event { | 15 | class Event { |
| 16 | public: | 16 | public: |
| 17 | void Set() { | 17 | void Set() { |
| 18 | std::lock_guard<std::mutex> lk(mutex); | 18 | std::lock_guard lk{mutex}; |
| 19 | if (!is_set) { | 19 | if (!is_set) { |
| 20 | is_set = true; | 20 | is_set = true; |
| 21 | condvar.notify_one(); | 21 | condvar.notify_one(); |
| @@ -23,14 +23,14 @@ public: | |||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | void Wait() { | 25 | void Wait() { |
| 26 | std::unique_lock<std::mutex> lk(mutex); | 26 | std::unique_lock lk{mutex}; |
| 27 | condvar.wait(lk, [&] { return is_set; }); | 27 | condvar.wait(lk, [&] { return is_set; }); |
| 28 | is_set = false; | 28 | is_set = false; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | template <class Clock, class Duration> | 31 | template <class Clock, class Duration> |
| 32 | bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { | 32 | bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { |
| 33 | std::unique_lock<std::mutex> lk(mutex); | 33 | std::unique_lock lk{mutex}; |
| 34 | if (!condvar.wait_until(lk, time, [this] { return is_set; })) | 34 | if (!condvar.wait_until(lk, time, [this] { return is_set; })) |
| 35 | return false; | 35 | return false; |
| 36 | is_set = false; | 36 | is_set = false; |
| @@ -38,7 +38,7 @@ public: | |||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | void Reset() { | 40 | void Reset() { |
| 41 | std::unique_lock<std::mutex> lk(mutex); | 41 | std::unique_lock lk{mutex}; |
| 42 | // no other action required, since wait loops on the predicate and any lingering signal will | 42 | // no other action required, since wait loops on the predicate and any lingering signal will |
| 43 | // get cleared on the first iteration | 43 | // get cleared on the first iteration |
| 44 | is_set = false; | 44 | is_set = false; |
| @@ -56,7 +56,7 @@ public: | |||
| 56 | 56 | ||
| 57 | /// Blocks until all "count" threads have called Sync() | 57 | /// Blocks until all "count" threads have called Sync() |
| 58 | void Sync() { | 58 | void Sync() { |
| 59 | std::unique_lock<std::mutex> lk(mutex); | 59 | std::unique_lock lk{mutex}; |
| 60 | const std::size_t current_generation = generation; | 60 | const std::size_t current_generation = generation; |
| 61 | 61 | ||
| 62 | if (++waiting == count) { | 62 | if (++waiting == count) { |
diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h index 821e8536a..e714ba5b3 100644 --- a/src/common/threadsafe_queue.h +++ b/src/common/threadsafe_queue.h | |||
| @@ -78,7 +78,7 @@ public: | |||
| 78 | 78 | ||
| 79 | T PopWait() { | 79 | T PopWait() { |
| 80 | if (Empty()) { | 80 | if (Empty()) { |
| 81 | std::unique_lock<std::mutex> lock(cv_mutex); | 81 | std::unique_lock lock{cv_mutex}; |
| 82 | cv.wait(lock, [this]() { return !Empty(); }); | 82 | cv.wait(lock, [this]() { return !Empty(); }); |
| 83 | } | 83 | } |
| 84 | T t; | 84 | T t; |
| @@ -137,7 +137,7 @@ public: | |||
| 137 | 137 | ||
| 138 | template <typename Arg> | 138 | template <typename Arg> |
| 139 | void Push(Arg&& t) { | 139 | void Push(Arg&& t) { |
| 140 | std::lock_guard<std::mutex> lock(write_lock); | 140 | std::lock_guard lock{write_lock}; |
| 141 | spsc_queue.Push(t); | 141 | spsc_queue.Push(t); |
| 142 | } | 142 | } |
| 143 | 143 | ||