Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- PipePosix.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_POSIX_PIPEPOSIX_H
0010 #define LLDB_HOST_POSIX_PIPEPOSIX_H
0011 #include "lldb/Host/PipeBase.h"
0012 #include <mutex>
0013 
0014 namespace lldb_private {
0015 
0016 /// \class PipePosix PipePosix.h "lldb/Host/posix/PipePosix.h"
0017 /// A posix-based implementation of Pipe, a class that abtracts
0018 ///        unix style pipes.
0019 ///
0020 /// A class that abstracts the LLDB core from host pipe functionality.
0021 class PipePosix : public PipeBase {
0022 public:
0023   static int kInvalidDescriptor;
0024 
0025   PipePosix();
0026   PipePosix(lldb::pipe_t read, lldb::pipe_t write);
0027   PipePosix(const PipePosix &) = delete;
0028   PipePosix(PipePosix &&pipe_posix);
0029   PipePosix &operator=(const PipePosix &) = delete;
0030   PipePosix &operator=(PipePosix &&pipe_posix);
0031 
0032   ~PipePosix() override;
0033 
0034   Status CreateNew(bool child_process_inherit) override;
0035   Status CreateNew(llvm::StringRef name, bool child_process_inherit) override;
0036   Status CreateWithUniqueName(llvm::StringRef prefix,
0037                               bool child_process_inherit,
0038                               llvm::SmallVectorImpl<char> &name) override;
0039   Status OpenAsReader(llvm::StringRef name,
0040                       bool child_process_inherit) override;
0041   Status
0042   OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inherit,
0043                           const std::chrono::microseconds &timeout) override;
0044 
0045   bool CanRead() const override;
0046   bool CanWrite() const override;
0047 
0048   lldb::pipe_t GetReadPipe() const override {
0049     return lldb::pipe_t(GetReadFileDescriptor());
0050   }
0051   lldb::pipe_t GetWritePipe() const override {
0052     return lldb::pipe_t(GetWriteFileDescriptor());
0053   }
0054 
0055   int GetReadFileDescriptor() const override;
0056   int GetWriteFileDescriptor() const override;
0057   int ReleaseReadFileDescriptor() override;
0058   int ReleaseWriteFileDescriptor() override;
0059   void CloseReadFileDescriptor() override;
0060   void CloseWriteFileDescriptor() override;
0061 
0062   // Close both descriptors
0063   void Close() override;
0064 
0065   Status Delete(llvm::StringRef name) override;
0066 
0067   Status WriteWithTimeout(const void *buf, size_t size,
0068                           const std::chrono::microseconds &timeout,
0069                           size_t &bytes_written) override;
0070   Status ReadWithTimeout(void *buf, size_t size,
0071                          const std::chrono::microseconds &timeout,
0072                          size_t &bytes_read) override;
0073 
0074 private:
0075   bool CanReadUnlocked() const;
0076   bool CanWriteUnlocked() const;
0077 
0078   int GetReadFileDescriptorUnlocked() const;
0079   int GetWriteFileDescriptorUnlocked() const;
0080   int ReleaseReadFileDescriptorUnlocked();
0081   int ReleaseWriteFileDescriptorUnlocked();
0082   void CloseReadFileDescriptorUnlocked();
0083   void CloseWriteFileDescriptorUnlocked();
0084   void CloseUnlocked();
0085 
0086   int m_fds[2];
0087 
0088   /// Mutexes for m_fds;
0089   mutable std::mutex m_read_mutex;
0090   mutable std::mutex m_write_mutex;
0091 };
0092 
0093 } // namespace lldb_private
0094 
0095 #endif // LLDB_HOST_POSIX_PIPEPOSIX_H