aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/file_lock.h
blob: 2c0118484fbea14cb6690a3c5151659efa753cc5 (plain) (blame)
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
#pragma once

#include <util/generic/fwd.h>
#include <util/generic/noncopyable.h>
#include <util/system/file.h>

enum class EFileLockType { 
    Exclusive,
    Shared
};
 
class TFileLock: public TFile {
public:
    TFileLock(const TString& filename, const EFileLockType type = EFileLockType::Exclusive);

    void Acquire();
    bool TryAcquire();
    void Release();

    inline void lock() {
        Acquire();
    }

    inline bool try_lock() {
        return TryAcquire();
    }

    inline void unlock() {
        Release();
    }

private:
    EFileLockType Type;
};