You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1008 B

4 months ago
  1. /*
  2. * IXSelectInterruptPipe.h
  3. * Author: Benjamin Sergeant
  4. * Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved.
  5. */
  6. #pragma once
  7. #include "IXSelectInterrupt.h"
  8. #include <mutex>
  9. #include <stdint.h>
  10. #include <string>
  11. namespace ix
  12. {
  13. class SelectInterruptPipe final : public SelectInterrupt
  14. {
  15. public:
  16. SelectInterruptPipe();
  17. virtual ~SelectInterruptPipe();
  18. bool init(std::string& errorMsg) final;
  19. bool notify(uint64_t value) final;
  20. bool clear() final;
  21. uint64_t read() final;
  22. int getFd() const final;
  23. private:
  24. // Store file descriptors used by the communication pipe. Communication
  25. // happens between a control thread and a background thread, which is
  26. // blocked on select.
  27. int _fildes[2];
  28. mutable std::mutex _fildesMutex;
  29. // Used to identify the read/write idx
  30. static const int kPipeReadIndex;
  31. static const int kPipeWriteIndex;
  32. };
  33. } // namespace ix