Remove unused spin_lock

This commit is contained in:
patrick96 2021-09-21 20:59:48 +02:00 committed by Patrick Ziegler
parent 0f72a2e0ea
commit c922a94b67
5 changed files with 9 additions and 48 deletions

View File

@ -2,6 +2,7 @@
#include <moodycamel/blockingconcurrentqueue.h> #include <moodycamel/blockingconcurrentqueue.h>
#include <atomic>
#include <mutex> #include <mutex>
#include <thread> #include <thread>

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <atomic>
#include <chrono> #include <chrono>
#include <condition_variable> #include <condition_variable>
#include <map> #include <map>
@ -17,6 +18,7 @@ POLYBAR_NS
namespace chrono = std::chrono; namespace chrono = std::chrono;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using std::atomic;
using std::map; using std::map;
#define DEFAULT_FORMAT "format" #define DEFAULT_FORMAT "format"

View File

@ -1,8 +1,5 @@
#pragma once #pragma once
#include <atomic>
#include <chrono>
#include <map>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@ -11,41 +8,12 @@
POLYBAR_NS POLYBAR_NS
namespace chrono =std::chrono;
using namespace std::chrono_literals; using namespace std::chrono_literals;
namespace this_thread = std::this_thread; namespace this_thread = std::this_thread;
using std::atomic;
using std::map;
using std::mutex; using std::mutex;
using std::thread; 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> template <typename T>
class mutex_wrapper : public T { class mutex_wrapper : public T {
public: public:

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <atomic>
#include <chrono> #include <chrono>
#include <memory> #include <memory>
@ -31,6 +32,7 @@ POLYBAR_NS
namespace chrono = std::chrono; namespace chrono = std::chrono;
using namespace std::chrono_literals; using namespace std::chrono_literals;
using std::atomic;
// fwd declarations // fwd declarations
class connection; class connection;

View File

@ -1,31 +1,19 @@
#include "utils/concurrency.hpp" #include "utils/concurrency.hpp"
POLYBAR_NS #include <map>
bool spin_lock::no_backoff_strategy::operator()() { POLYBAR_NS
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);
}
namespace concurrency_util { namespace concurrency_util {
size_t thread_id(const thread::id id) { size_t thread_id(const thread::id id) {
static size_t idx{1_z}; 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); std::lock_guard<decltype(ids)> lock(ids);
if (ids.find(id) == ids.end()) { if (ids.find(id) == ids.end()) {
ids[id] = idx++; ids[id] = idx++;
} }
return ids[id]; return ids[id];
} }
} } // namespace concurrency_util
POLYBAR_NS_END POLYBAR_NS_END