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
16namespace lldb_private {
17
19public:
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
32protected:
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.
51 uint64_t m_start;
52 uint64_t m_len;
53};
54}
55
56#endif
std::function< Status(const uint64_t, const uint64_t)> Locker
Definition: LockFileBase.h:33
virtual ~LockFileBase()=default
virtual bool IsValidFile() const
Status TryWriteLock(const uint64_t start, const uint64_t len)
virtual Status DoTryReadLock(const uint64_t start, const uint64_t len)=0
Status WriteLock(const uint64_t start, const uint64_t len)
Status TryReadLock(const uint64_t start, const uint64_t len)
virtual Status DoTryWriteLock(const uint64_t start, const uint64_t len)=0
Status ReadLock(const uint64_t start, const uint64_t len)
Status DoLock(const Locker &locker, const uint64_t start, const uint64_t len)
virtual Status DoUnlock()=0
virtual Status DoWriteLock(const uint64_t start, const uint64_t len)=0
virtual Status DoReadLock(const uint64_t start, const uint64_t len)=0
An error handling class.
Definition: Status.h:44
A class that represents a running process on the host machine.