/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Host/LockFileBase.h
Line | Count | Source |
1 | | //===-- LockFileBase.h ------------------------------------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #ifndef LLDB_HOST_LOCKFILEBASE_H |
10 | | #define LLDB_HOST_LOCKFILEBASE_H |
11 | | |
12 | | #include "lldb/Utility/Status.h" |
13 | | |
14 | | #include <functional> |
15 | | |
16 | | namespace lldb_private { |
17 | | |
18 | | class LockFileBase { |
19 | | public: |
20 | 18 | virtual ~LockFileBase() = default; |
21 | | |
22 | | bool IsLocked() const; |
23 | | |
24 | | Status WriteLock(const uint64_t start, const uint64_t len); |
25 | | Status TryWriteLock(const uint64_t start, const uint64_t len); |
26 | | |
27 | | Status ReadLock(const uint64_t start, const uint64_t len); |
28 | | Status TryReadLock(const uint64_t start, const uint64_t len); |
29 | | |
30 | | Status Unlock(); |
31 | | |
32 | | protected: |
33 | | using Locker = std::function<Status(const uint64_t, const uint64_t)>; |
34 | | |
35 | | LockFileBase(int fd); |
36 | | |
37 | | virtual bool IsValidFile() const; |
38 | | |
39 | | virtual Status DoWriteLock(const uint64_t start, const uint64_t len) = 0; |
40 | | virtual Status DoTryWriteLock(const uint64_t start, const uint64_t len) = 0; |
41 | | |
42 | | virtual Status DoReadLock(const uint64_t start, const uint64_t len) = 0; |
43 | | virtual Status DoTryReadLock(const uint64_t start, const uint64_t len) = 0; |
44 | | |
45 | | virtual Status DoUnlock() = 0; |
46 | | |
47 | | Status DoLock(const Locker &locker, const uint64_t start, const uint64_t len); |
48 | | |
49 | | int m_fd; // not owned. |
50 | | bool m_locked; |
51 | | uint64_t m_start; |
52 | | uint64_t m_len; |
53 | | }; |
54 | | } |
55 | | |
56 | | #endif |