aboutsummaryrefslogblamecommitdiffstats
path: root/util/system/file_lock.h
blob: b2aaff5baf82b9cceb5f06452cbece81acde98b0 (plain) (tree)
1
2
3
4
5
6
7
            
                             
                                     
                             
 
                          






                                                                                            
                   
                      
                   
 










                            
                       
  
#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;
};