38 #ifndef CORELIB_DATAOBJECT_LOCK_FREE_HPP 39 #define CORELIB_DATAOBJECT_LOCK_FREE_HPP 42 #include "../os/oro_arch.h" 44 #include "../Logger.hpp" 45 #include "../types/Types.hpp" 46 #include "../internal/DataSourceTypeInfo.hpp" 142 : MAX_THREADS(options.max_threads()), BUF_LEN( options.max_threads() + 2),
149 write_ptr = &data[1];
159 : MAX_THREADS(options.max_threads()), BUF_LEN( options.max_threads() + 2),
166 write_ptr = &data[1];
181 virtual value_t
Get()
const {
197 virtual FlowStatus Get( reference_t pull,
bool copy_old_data,
bool copy_sample )
const 199 if (!initialized && !copy_sample) {
211 if ( reading != read_ptr )
227 ((result ==
OldData) && copy_old_data) || copy_sample) {
228 pull = reading->
data;
247 return Get( pull, copy_old_data,
false );
255 virtual bool Set( param_t push )
259 <<
"This might not be real-time safe." <<
endlog();
277 if ( writing != write_ptr ) {
287 writing->
data = push;
292 PtrType next_write_ptr = writing->
next;
294 next_write_ptr == read_ptr )
296 next_write_ptr = next_write_ptr->
next;
297 if (next_write_ptr == writing) {
305 write_ptr = next_write_ptr;
311 if (!initialized || reset) {
313 for (
unsigned int i = 0; i <
BUF_LEN; ++i) {
314 data[i].
data = sample;
316 data[i].
next = &data[i+1];
318 data[BUF_LEN-1].
next = &data[0];
331 (void)
Get(sample,
true,
true);
338 if (!initialized)
return;
348 if ( reading != read_ptr )
virtual value_t Get() const
DataObjectInterface< T >::value_t value_t
virtual bool Set(param_t push)
virtual FlowStatus Get(reference_t pull, bool copy_old_data, bool copy_sample) const
virtual value_t data_sample() const
int oro_atomic_inc_and_test(oro_atomic_t *a)
virtual bool data_sample(param_t sample, bool reset=true)
DataBuf *volatile VolPtrType
oro_atomic_t read_counter
const unsigned int BUF_LEN
DataObjectLockFree(param_t initial_value, const Options &options=Options())
int oro_atomic_read(oro_atomic_t *a)
bool CAS(volatile T *addr, const V &expected, const W &value)
virtual FlowStatus Get(reference_t pull, bool copy_old_data=true) const
void oro_atomic_inc(oro_atomic_t *a)
This DataObject is a Lock-Free implementation, such that reads and writes can happen concurrently wit...
DataObjectInterface< T >::reference_t reference_t
DataObjectBase::Options Options
boost::call_traits< T >::param_type param_t
DataObjectInterface< T >::param_t param_t
const unsigned int MAX_THREADS
The maximum number of threads.
A DataObjectInterface implements multi-threaded read/write solutions.
void oro_atomic_set(oro_atomic_t *a, int n)
static const std::string & getType()
boost::call_traits< T >::reference reference_t
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
void oro_atomic_dec(oro_atomic_t *a)
static Logger::LogFunction endlog()
DataObjectLockFree(const Options &options=Options())