atomic_container Class Reference

Inherited by atomic_preallocated_pool [protected].

Inheritance diagram for atomic_container:

Inheritance graph
[legend]
List of all members.

Detailed Description

A thread-safe, lock-free, almost wait-free atomic container for untyped items.

This class takes care of pushing and popping elements from the container for multiple concurrent threads. It is up to the user (client code) to allocate and deallocate the storage for items pushed on this container.

The objects being stored here must have an embedded next pointer. The offset given in the constructor tells the container the offset of the "next" pointer in the objects being stored here. The offset can be + or - from the pointer being given in push().

WARNING: in order to avoid the so-called "ABA" problem, the container must begin with and maintain a reasonably large pool. There is the possibility of recently-freed objects being reused very quickly, in turn enabling internal corruption from a possible race where a thread begins to allocate an object, but other threads do enough pops and pushes to cycle through 8 version numbers, and all this happens before the first thread finishes. It's unlikely but possible.

Definition at line 85 of file atomic_container.h.

Public Types

typedef long int offset_typ

Public Member Functions

 atomic_container (offset_typ offset)
void * pop ()
void push (void *v)
 Push an item onto the stack.
offset_typ offset () const
 Only for debugging.
 ~atomic_container ()

Protected Member Functions

template<class Union>
void * prepare (Union rval)
 Strip off the pointer's version number and hide the header.
void * null ()
 Return a null pointer (i.e., it contains the offset only).

Protected Attributes

offset_typ const _offset


Member Function Documentation

void* atomic_container::pop (  )  [inline]

Pop an item off the stack. If we don't find any to pop, return a null ptr. We do not go to the global heap. The client must do that.

Definition at line 104 of file atomic_container.h.

References prepare().

Referenced by atomic_preallocated_pool::alloc(), and atomic_preallocated_pool::~atomic_preallocated_pool().

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file:
Generated on Wed Jul 7 17:22:42 2010 for Shore Storage Manager by  doxygen 1.4.7