-
Notifications
You must be signed in to change notification settings - Fork 93
Description
The current buffer implementation is not lock-free and does not support writes from the real-time part.
I have written a proof-of-concept implementation that might be a viable replacement.
It enforces a last-write-wins strategy, since this is what we need for the controlles, right?
You can find it here: https://gist.github.com/mathias-luedtke/773f043a31b3bcce3598
It is based on boost::atomic and boost::lockfree and requires a recent boost installation (14.04/indigo works).
rosrt backported both to hydro, but is not maintained anymore.
It is divided into two parts: LockfreeBuffer and LockedBuffer.
LockfreeBuffer maintains a pre-allocated lock-free freelist and provides the most recent data (push) to one single reader (pop).
- all calls should be lock-free, thread-safe and realtime-safe (if the payload copy constructor is!)
- Concurrent reads will lead to an empty pointer for one reader.
- The data is provided with RAII pointers to prevent misuses.
- The freelist must be big enough (number of writers + 1 reader) to work without starvation.
- Data can be pushed and pop from real-time and non-real-time parts.
However, the LockfreeBuffer only works for single consumers (sufficient for all current ros_controllers).
Therefore I have provided a LockedBuffer implementation, that runs on top of the LockfreeBuffer.
- blocking read (~ ReatimeBuffer::readFromNonRT)
- non-blocking try_read (~ ReatimeBuffer::readFromRT).
- write is just an alias for LockfreeBuffer::push
It is not ready for release yet, but I would really appreciate your comments on this.