40 #ifndef ORO_LIST_LOCKED_HPP 41 #define ORO_LIST_LOCKED_HPP 43 #include <boost/intrusive/list.hpp> 44 #include <boost/bind.hpp> 45 #include <boost/bind/protect.hpp> 49 #include "../os/Mutex.hpp" 50 #include "../os/MutexLock.hpp" 52 #ifdef ORO_PRAGMA_INTERFACE 78 struct Cont :
public boost::intrusive::list_base_hook<> {
83 typedef typename BufferType::iterator
Iterator;
84 typedef typename BufferType::const_iterator
CIterator;
99 for(
unsigned int i=0; i <lsize; ++i)
100 mreserved.push(
new Cont());
105 while( !mreserved.empty() ) {
106 delete mreserved.top();
114 return mreserved.size() + mlist.size();
126 return mlist.empty();
139 if (required > mreserved.size() + mlist.size() ) {
140 while ( mreserved.size() + mlist.size() < required * 2) {
141 mreserved.push(
new Cont() );
166 while ( mreserved.size() + mlist.size() < lsize) {
167 mreserved.push(
new Cont() );
185 if ( mreserved.empty() )
187 mlist.push_back( this->
get_item(item) );
197 return mlist.front().data;
206 return mlist.back().data;
214 size_t append(
const std::vector<T>& items)
217 unsigned int max = mreserved.size();
218 typename std::vector<T>::const_iterator it = items.begin();
219 for(; it != items.end() && max != 0; ++it, --max )
220 mlist.push_back( this->get_item(*it) );
221 return it - items.begin();
244 template<
typename Pred>
248 bool deleted =
false;
250 typename BufferType::iterator cur(mlist.begin());
251 typename BufferType::iterator last(mlist.end());
273 template<
class Function>
278 for (Iterator it = mlist.begin(); it != mlist.end(); ++it)
287 template<
class Function>
291 Iterator it = std::find_if(mlist.begin(), mlist.end(), boost::bind(func, boost::bind(&
ListLocked::get_data,
this,_1)));
292 if (it != mlist.end() )
304 mreserved.push( cont );
309 Cont* c = mreserved.top();
329 return item == cont.
data;
BufferType::iterator Iterator
BufferType::const_iterator CIterator
void reserve(size_t lsize)
ListLocked(unsigned int lsize, unsigned int unused=0)
void apply(Function func)
value_t & get_data(Cont &c)
size_t append(const std::vector< T > &items)
void grow(size_t items=1)
bool is_item(value_t item, const Cont &cont)
void give_back(Cont *cont)
value_t find_if(Function func, value_t blank=value_t())
bool delete_if(Pred pred)
boost::intrusive::list< Cont > BufferType
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
bool append(value_t item)
An object oriented wrapper around a recursive mutex.
std::stack< Cont * > StackType
void shrink(size_t items=1)
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...
Cont & get_item(value_t item)