polybar/include/utils/concurrency.hpp

42 lines
718 B
C++
Raw Normal View History

2016-06-15 03:32:35 +00:00
#pragma once
#include <mutex>
2016-11-20 22:04:31 +00:00
#include <thread>
2016-06-15 03:32:35 +00:00
#include "common.hpp"
#include "utils/mixins.hpp"
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-06-15 03:32:35 +00:00
2016-12-26 09:33:23 +00:00
using namespace std::chrono_literals;
2016-11-20 22:04:31 +00:00
namespace this_thread = std::this_thread;
2016-12-23 04:18:58 +00:00
using std::mutex;
2016-11-20 22:04:31 +00:00
using std::thread;
2022-03-06 16:44:48 +00:00
/**
* Types wrapped in this type can be used as locks (e.g. for lock_guard).
*/
2016-12-26 09:33:23 +00:00
template <typename T>
class mutex_wrapper : public T {
public:
template <typename... Args>
explicit mutex_wrapper(Args&&... args) : T(forward<Args>(args)...) {}
2016-06-15 03:32:35 +00:00
2016-12-26 09:33:23 +00:00
void lock() const noexcept {
m_mtx.lock();
}
void unlock() const noexcept {
m_mtx.unlock();
2016-06-15 03:32:35 +00:00
};
2016-12-23 04:18:58 +00:00
2016-12-26 09:33:23 +00:00
private:
mutable mutex m_mtx;
};
namespace concurrency_util {
2016-12-23 04:18:58 +00:00
size_t thread_id(const thread::id id);
2016-06-15 03:32:35 +00:00
}
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END