summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/LockFile.h
blob: 4a52f114a8072c0de46f7112258f05cfe6d68a4c (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
/*
 * Copyright (c) 2021, Peter Elliott <pelliott@ualberta.ca>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

namespace Core {

class LockFile {
public:
    enum class Type {
        Exclusive,
        Shared
    };

    LockFile(LockFile const& other) = delete;
    LockFile(char const* filename, Type type = Type::Exclusive);
    ~LockFile();

    bool is_held() const;
    int error_code() const { return m_errno; }
    void release();

private:
    int m_fd { -1 };
    int m_errno { 0 };
    char const* m_filename { nullptr };
};

}