LLDB  mainline
LockFileBase.h
Go to the documentation of this file.
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  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
lldb_private::LockFileBase::IsLocked
bool IsLocked() const
Definition: LockFileBase.cpp:21
lldb_private::LockFileBase::DoReadLock
virtual Status DoReadLock(const uint64_t start, const uint64_t len)=0
lldb_private::LockFileBase::~LockFileBase
virtual ~LockFileBase()=default
lldb_private::LockFileBase::m_locked
bool m_locked
Definition: LockFileBase.h:50
lldb_private::LockFileBase::m_start
uint64_t m_start
Definition: LockFileBase.h:51
lldb_private::LockFileBase::Unlock
Status Unlock()
Definition: LockFileBase.cpp:47
lldb_private::LockFileBase::DoTryWriteLock
virtual Status DoTryWriteLock(const uint64_t start, const uint64_t len)=0
lldb_private::LockFileBase::DoLock
Status DoLock(const Locker &locker, const uint64_t start, const uint64_t len)
Definition: LockFileBase.cpp:62
lldb_private::LockFileBase::IsValidFile
virtual bool IsValidFile() const
Definition: LockFileBase.cpp:60
lldb_private::LockFileBase::DoTryReadLock
virtual Status DoTryReadLock(const uint64_t start, const uint64_t len)=0
lldb_private::LockFileBase::m_len
uint64_t m_len
Definition: LockFileBase.h:52
lldb_private::LockFileBase
Definition: LockFileBase.h:18
lldb_private::LockFileBase::ReadLock
Status ReadLock(const uint64_t start, const uint64_t len)
Definition: LockFileBase.cpp:35
lldb_private::LockFileBase::m_fd
int m_fd
Definition: LockFileBase.h:49
lldb_private::Status
Definition: Status.h:44
lldb_private::LockFileBase::Locker
std::function< Status(const uint64_t, const uint64_t)> Locker
Definition: LockFileBase.h:33
lldb_private::LockFileBase::WriteLock
Status WriteLock(const uint64_t start, const uint64_t len)
Definition: LockFileBase.cpp:23
lldb_private::LockFileBase::LockFileBase
LockFileBase(int fd)
Definition: LockFileBase.cpp:18
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::LockFileBase::TryWriteLock
Status TryWriteLock(const uint64_t start, const uint64_t len)
Definition: LockFileBase.cpp:29
lldb_private::LockFileBase::DoUnlock
virtual Status DoUnlock()=0
lldb_private::LockFileBase::TryReadLock
Status TryReadLock(const uint64_t start, const uint64_t len)
Definition: LockFileBase.cpp:41
lldb_private::LockFileBase::DoWriteLock
virtual Status DoWriteLock(const uint64_t start, const uint64_t len)=0