]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/include/lldb/Host/LockFileBase.h
MFC r355940:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / include / lldb / Host / LockFileBase.h
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 liblldb_Host_LockFileBase_h_
10 #define liblldb_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   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