| | |
| | | bool TryWrite(const D &d) { return queue_.push_back(d); } |
| | | |
| | | private: |
| | | typedef Circular<D> Queue; |
| | | Queue queue_; |
| | | Circular<D> queue_; |
| | | }; |
| | | |
| | | template <int Power = 4> |
| | | class SharedQ63 |
| | | { |
| | | public: |
| | | typedef int64_t Data; |
| | | bool Read(Data &d, const int timeout_ms) |
| | | { |
| | | using namespace std::chrono; |
| | | auto end_time = steady_clock::now() + milliseconds(timeout_ms); |
| | | do { |
| | | if (TryRead(d)) { |
| | | return true; |
| | | } else { |
| | | robust::QuickSleep(); |
| | | } |
| | | } while (steady_clock::now() < end_time); |
| | | return false; |
| | | } |
| | | bool TryRead(Data &d, const bool try_more = true) { return queue_.pop_front(d, try_more); } |
| | | bool TryWrite(const Data d, const bool try_more = true) { return queue_.push_back(d, try_more); } |
| | | |
| | | private: |
| | | robust::AtomicQueue<Power, Data> queue_; |
| | | }; |
| | | |
| | | } // namespace bhome_shm |