1 #include "triplebuffer.hpp"
16 unsigned logic::get_read() throw()
18 threads::alock
h(lock
);
20 //We already are reading => The same as previously.
24 //We are beginning a new read => Pick last_complete.
26 current_read
= last_complete
;
31 void logic::put_read() throw(std::logic_error
)
33 threads::alock
h(lock
);
34 if(!count_read
) throw std::logic_error("Internal error: put_read() with 0 counter");
38 unsigned logic::get_write() throw()
40 const unsigned magic
= 0x010219;
41 threads::alock
h(lock
);
43 //We already are writing => The same as previously.
47 //We are beginning a new write => Pick one that isn't last_complete nor current_read.
49 unsigned tmp
= ((last_complete
<< 2) | current_read
) << 1;
50 current_write
= (magic
>> tmp
) & 3;
55 void logic::put_write() throw(std::logic_error
)
57 threads::alock
h(lock
);
58 if(!count_write
) throw std::logic_error("Internal error: put_write() with 0 counter");
60 //If we reached 0 counter, mark buffer as complete.
62 last_complete
= current_write
;
65 void logic::read_last_write_synchronous(std::function
<void(unsigned)> fn
) throw()
67 threads::alock
h(lock
);