Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:49

0001 //===-- LockFileBase.h ------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_HOST_LOCKFILEBASE_H
0010 #define LLDB_HOST_LOCKFILEBASE_H
0011 
0012 #include "lldb/Utility/Status.h"
0013 
0014 #include <functional>
0015 
0016 namespace lldb_private {
0017 
0018 class LockFileBase {
0019 public:
0020   virtual ~LockFileBase() = default;
0021 
0022   bool IsLocked() const;
0023 
0024   Status WriteLock(const uint64_t start, const uint64_t len);
0025   Status TryWriteLock(const uint64_t start, const uint64_t len);
0026 
0027   Status ReadLock(const uint64_t start, const uint64_t len);
0028   Status TryReadLock(const uint64_t start, const uint64_t len);
0029 
0030   Status Unlock();
0031 
0032 protected:
0033   using Locker = std::function<Status(const uint64_t, const uint64_t)>;
0034 
0035   LockFileBase(int fd);
0036 
0037   virtual bool IsValidFile() const;
0038 
0039   virtual Status DoWriteLock(const uint64_t start, const uint64_t len) = 0;
0040   virtual Status DoTryWriteLock(const uint64_t start, const uint64_t len) = 0;
0041 
0042   virtual Status DoReadLock(const uint64_t start, const uint64_t len) = 0;
0043   virtual Status DoTryReadLock(const uint64_t start, const uint64_t len) = 0;
0044 
0045   virtual Status DoUnlock() = 0;
0046 
0047   Status DoLock(const Locker &locker, const uint64_t start, const uint64_t len);
0048 
0049   int m_fd; // not owned.
0050   bool m_locked;
0051   uint64_t m_start;
0052   uint64_t m_len;
0053 };
0054 }
0055 
0056 #endif