36 #ifndef LOCKFREE_FREE_LIST_H 37 #define LOCKFREE_FREE_LIST_H 43 #include <boost/thread.hpp> 46 #define ROSRT_CACHELINE_SIZE 64 // TODO: actually determine this. 49 #define FREELIST_DEBUG_YIELD() sched_yield() 51 #define FREELIST_DEBUG_YIELD() 79 FreeList(uint32_t block_size, uint32_t block_count);
87 void initialize(uint32_t block_size, uint32_t block_count);
98 void free(
void const* mem);
104 bool owns(
void const* mem);
173 return (uint32_t)(val >> 32);
178 return (uint32_t)val & 0xffffffff;
181 inline void setTag(uint64_t& val, uint32_t tag)
183 val =
getVal(val) | ((uint64_t)tag << 32);
186 inline void setVal(uint64_t& val, uint32_t v)
188 val = ((uint64_t)
getTag(val) << 32) | v;
212 , new_head(0xffffffff)
225 std::vector<Item> items;
233 debug_.reset(
new Debug);
234 std::stringstream ss;
235 ss << boost::this_thread::get_id();
236 debug_->thread = ss.str();
240 boost::thread_specific_ptr<Debug> debug_;
246 #endif // LOCKFREE_FREE_LIST_H void destructAll()
Destruct all the objects in this FreeList. You must have called constructAll() first.
void free(void const *mem)
Free a block of memory allocated from this FreeList.
void * allocate()
Allocate a single block from this FreeList.
FreeList()
Default constructor. You must call initialize() if you use this constructor.
bool owns(void const *mem)
Returns whether or not this FreeList owns a block of memory.
uint32_t getVal(uint64_t val)
ros::atomic_uint32_t alloc_count_
void setVal(uint64_t &val, uint32_t v)
ros::atomic_uint32_t * next_
bool hasOutstandingAllocations()
Returns whether or not this FreeList currently has any outstanding allocations.
void setTag(uint64_t &val, uint32_t tag)
void constructAll()
Construct all the blocks with a default constructor. If you call this you must call destructAll() pri...
uint32_t getTag(uint64_t val)
A lock-free (not wait-free) statically-sized free-list implemented with CAS.
ros::atomic_uint64_t head_
void initialize(uint32_t block_size, uint32_t block_count)
Initialize this FreeList. Only use if you used to default constructor.
void constructAll(const T &tmpl)
Construct all the blocks with a specific template. If you call this you must call destructAll() prior...