Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. class LogBuffer
  2. {
  3. public:
  4. bool is_empty() const { return head_ == tail_; }
  5. bool is_full() const { return uint16_t(tail_ + 1) == head_; }
  6. LogLine& head() { return log_buffer_[head_]; }
  7. LogLine& tail() { return log_buffer_[tail_]; }
  8. void advance_head() { ++head_; }
  9. void advance_hail() { ++tail_; }
  10. private:
  11. volatile uint16_t tail_ = 0; // write position
  12. LogLine log_buffer_[0xffff + 1]; // relies on the uint16_t overflowing
  13. volatile uint16_t head_ = 0; // read position
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement