| #ifndef PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_EVENT_QUEUE_H_ |
| #define PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_EVENT_QUEUE_H_ |
| |
| #include <memory> |
| #include <vector> |
| |
| #include "event.h" |
| #include "absl/status/statusor.h" |
| #include "absl/time/time.h" |
| |
| namespace safepower_agent { |
| |
| class EventQueue { |
| public: |
| EventQueue(); |
| ~EventQueue(); |
| |
| // Thread-safe / Fiber-safe push. |
| // Requires that Close() has not been called. Pushing to a closed queue |
| // is a programming error and will result in a fatal log (DFATAL). |
| void Push(Event event); |
| |
| // Closes the queue. Subsequent Pops will return an error once the queue is |
| // empty. |
| // Requires that Close() is called at most once. |
| // The caller must externally coordinate to ensure that no calls to Push() |
| // occur concurrently with or after Close(). |
| void Close(); |
| |
| // Blocks until events are available or timeout is reached. |
| // Returns all popped events, or an error if the queue/channel is closed. |
| absl::StatusOr<std::vector<Event>> PopAllWithTimeout(absl::Duration timeout); |
| |
| private: |
| struct Impl; |
| std::unique_ptr<Impl> impl_; |
| }; |
| |
| } // namespace safepower_agent |
| |
| #endif // PRODUCTION_BORG_MGMT_NODE_PROXY_SAFEPOWER_SAFEPOWER_AGENT_EVENT_QUEUE_H_ |