this repo has no description
1/* Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) */
2#pragma once
3
4#include "globals.h"
5
6namespace py {
7
8class Mutex {
9 public:
10 Mutex();
11 ~Mutex();
12 void lock();
13 bool tryLock();
14 void unlock();
15
16 private:
17 union Data {
18 char data[64];
19 word _; // here to increase alignment.
20 };
21 Data data_;
22
23 void* mutex();
24};
25
26class MutexGuard {
27 public:
28 MutexGuard(Mutex* mutex);
29 ~MutexGuard();
30 Mutex* mutex_;
31};
32
33inline void* Mutex::mutex() { return &data_.data; }
34
35inline MutexGuard::MutexGuard(Mutex* mutex) : mutex_(mutex) { mutex_->lock(); }
36
37inline MutexGuard::~MutexGuard() { mutex_->unlock(); }
38
39} // namespace py