mirror of https://github.com/polybar/polybar.git
Remove unused spin_lock
This commit is contained in:
parent
0f72a2e0ea
commit
c922a94b67
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <moodycamel/blockingconcurrentqueue.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <map>
|
||||
|
@ -17,6 +18,7 @@ POLYBAR_NS
|
|||
|
||||
namespace chrono = std::chrono;
|
||||
using namespace std::chrono_literals;
|
||||
using std::atomic;
|
||||
using std::map;
|
||||
|
||||
#define DEFAULT_FORMAT "format"
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
|
@ -11,41 +8,12 @@
|
|||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace chrono =std::chrono;
|
||||
using namespace std::chrono_literals;
|
||||
namespace this_thread = std::this_thread;
|
||||
|
||||
using std::atomic;
|
||||
using std::map;
|
||||
using std::mutex;
|
||||
using std::thread;
|
||||
|
||||
class spin_lock : public non_copyable_mixin<spin_lock> {
|
||||
public:
|
||||
struct no_backoff_strategy {
|
||||
bool operator()();
|
||||
};
|
||||
struct yield_backoff_strategy {
|
||||
bool operator()();
|
||||
};
|
||||
|
||||
public:
|
||||
explicit spin_lock() = default;
|
||||
|
||||
template <typename Backoff>
|
||||
void lock(Backoff backoff) noexcept {
|
||||
while (m_locked.test_and_set(std::memory_order_acquire)) {
|
||||
backoff();
|
||||
}
|
||||
}
|
||||
|
||||
void lock() noexcept;
|
||||
void unlock() noexcept;
|
||||
|
||||
protected:
|
||||
std::atomic_flag m_locked{false};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class mutex_wrapper : public T {
|
||||
public:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
|
@ -31,6 +32,7 @@ POLYBAR_NS
|
|||
|
||||
namespace chrono = std::chrono;
|
||||
using namespace std::chrono_literals;
|
||||
using std::atomic;
|
||||
|
||||
// fwd declarations
|
||||
class connection;
|
||||
|
|
|
@ -1,31 +1,19 @@
|
|||
#include "utils/concurrency.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
#include <map>
|
||||
|
||||
bool spin_lock::no_backoff_strategy::operator()() {
|
||||
return true;
|
||||
}
|
||||
bool spin_lock::yield_backoff_strategy::operator()() {
|
||||
this_thread::yield();
|
||||
return false;
|
||||
}
|
||||
void spin_lock::lock() noexcept {
|
||||
lock(no_backoff_strategy{});
|
||||
}
|
||||
void spin_lock::unlock() noexcept {
|
||||
m_locked.clear(std::memory_order_release);
|
||||
}
|
||||
POLYBAR_NS
|
||||
|
||||
namespace concurrency_util {
|
||||
size_t thread_id(const thread::id id) {
|
||||
static size_t idx{1_z};
|
||||
static mutex_wrapper<map<thread::id, size_t>> ids;
|
||||
static mutex_wrapper<std::map<thread::id, size_t>> ids;
|
||||
std::lock_guard<decltype(ids)> lock(ids);
|
||||
if (ids.find(id) == ids.end()) {
|
||||
ids[id] = idx++;
|
||||
}
|
||||
return ids[id];
|
||||
}
|
||||
}
|
||||
} // namespace concurrency_util
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
|
Loading…
Reference in New Issue