File: concurrency.hpp

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (41 lines) | stat: -rw-r--r-- 718 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once

#include <mutex>
#include <thread>

#include "common.hpp"
#include "utils/mixins.hpp"

POLYBAR_NS

using namespace std::chrono_literals;
namespace this_thread = std::this_thread;

using std::mutex;
using std::thread;

/**
 * Types wrapped in this type can be used as locks (e.g. for lock_guard).
 */
template <typename T>
class mutex_wrapper : public T {
 public:
  template <typename... Args>
  explicit mutex_wrapper(Args&&... args) : T(forward<Args>(args)...) {}

  void lock() const noexcept {
    m_mtx.lock();
  }
  void unlock() const noexcept {
    m_mtx.unlock();
  };

 private:
  mutable mutex m_mtx;
};

namespace concurrency_util {
  size_t thread_id(const thread::id id);
}

POLYBAR_NS_END