summaryrefslogtreecommitdiffstats
path: root/ml/Mutex.h
blob: fcdb75313500434f5d69baeb8dc3101962d88fc2 (plain)
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
#ifndef ML_MUTEX_H
#define ML_MUTEX_H

#include "ml-private.h"

class Mutex {
public:
    Mutex() {
        netdata_mutex_init(&M);
    }

    void lock() {
        netdata_mutex_lock(&M);
    }

    void unlock() {
        netdata_mutex_unlock(&M);
    }

    bool try_lock() {
        return netdata_mutex_trylock(&M) == 0;
    }

    netdata_mutex_t *inner() {
        return &M;
    }

    ~Mutex() {
        netdata_mutex_destroy(&M);
    }

private:
    netdata_mutex_t M;
};

#endif /* ML_MUTEX_H */