1 #include "triplebuffer.hpp"
15 unsigned logic::get_read() throw()
17 threads::alock
h(lock
);
19 //We already are reading => The same as previously.
23 //We are beginning a new read => Pick last_complete.
25 current_read
= last_complete
;
30 void logic::put_read() throw(std::logic_error
)
32 threads::alock
h(lock
);
33 if(!count_read
) throw std::logic_error("Internal error: put_read() with 0 counter");
37 unsigned logic::get_write() throw()
39 const unsigned magic
= 0x010219;
40 threads::alock
h(lock
);
42 //We already are writing => The same as previously.
46 //We are beginning a new write => Pick one that isn't last_complete nor current_read.
48 unsigned tmp
= ((last_complete
<< 2) | current_read
) << 1;
49 current_write
= (magic
>> tmp
) & 3;
54 void logic::put_write() throw(std::logic_error
)
56 threads::alock
h(lock
);
57 if(!count_write
) throw std::logic_error("Internal error: put_write() with 0 counter");
59 //If we reached 0 counter, mark buffer as complete.
61 last_complete
= current_write
;
64 void logic::read_last_write_synchronous(std::function
<void(unsigned)> fn
) throw()
66 threads::alock
h(lock
);