46 #ifndef RTT_TSPOOL_HPP_ 47 #define RTT_TSPOOL_HPP_ 49 #include "../os/CAS.hpp" 105 TsPool(
unsigned int ssize,
const T& sample = T()) :
106 pool_size(0), pool_capacity(ssize)
108 pool =
new Item[ssize];
116 unsigned int i = 0, endseen = 0;
119 if (pool[i].next.ptr.index == (
unsigned short) -1)
124 assert( endseen == 1);
125 assert(
size() == pool_capacity &&
"TsPool: not all pieces were deallocated !" );
141 pool[i].next.ptr.index = i + 1;
143 pool[pool_capacity - 1].next.ptr.index = (
unsigned short) -1;
144 head.next.ptr.index = 0;
155 pool[i].
value = sample;
161 volatile Pointer_t oldval;
162 volatile Pointer_t newval;
166 oldval.value = head.next.value;
168 if (oldval.ptr.index == (
unsigned short) -1)
172 item = &pool[oldval.ptr.index];
173 newval.ptr.index = item->next.ptr.index;
174 newval.ptr.tag = oldval.ptr.tag + 1;
175 }
while (!
os::CAS(&head.next.value, oldval.value, newval.value));
185 assert(Value >= (T*) &pool[0] && Value <= (T*) &pool[pool_capacity]);
186 volatile Pointer_t oldval;
188 Item* item =
reinterpret_cast<Item*
> (Value);
191 oldval.value = head.next.value;
192 item->next.value = oldval.value;
193 head_next.ptr.index = (item -
pool);
194 head_next.ptr.tag = oldval.ptr.tag + 1;
195 }
while (!
os::CAS(&head.next.value, oldval.value, head_next.value));
207 unsigned int ret = 0;
208 volatile Item* oldval;
210 while ( oldval->next.ptr.index != (
unsigned short) -1) {
212 oldval = &pool[oldval->next.ptr.index];
213 assert(ret <= pool_capacity);
TsPool(unsigned int ssize, const T &sample=T())
void data_sample(const T &sample)
unsigned int pool_capacity
bool CAS(volatile T *addr, const V &expected, const W &value)
bool deallocate(T *Value)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
struct RTT::internal::TsPool::Pointer_t::_ptr_type ptr