clockUtils  1.1
Container

Namespaces

 clockUtils
 

Detailed Description

This library is a collection of container classes (currently only one). They serve for special purposes that are not or not easily handled by the STL. E.g. Threadsafe containers or complex structures. If possible, the containers offer at least the same API like the corresponding STL container. This allows a simple exchange without introducing new problems. Semantic changes and additional functionality is explained in the appropriate documentation.

How to use the container library

Currently the container library consists of two classes.

DoubleBufferQueue

The DoubleBufferQueue is used for threadsafe queue access. Besides the template parameter for the type you can specify whether there will be written to from multiple threads or not and whether there is read from multiple threads or not, which specifies the locking strategy. The API equals those of the std::queue or std::priority_queue with some exceptions.

ClockError pop();


pop() method basically returns ClockError::SUCCESS, except there is no element in the queue. In this case it returns ClockError::NO_ELEMENT; std::queue just returns void.

ClockError front(T & value);


The front() method has the same return behaviour as the pop() method. The real return value, the front element of the queue if existing, is returned by reference.

ClockError poll(T & value);


The poll() method has the same return behaviour as the pop() method. It returns the front element of the queue by reference as the front() method and pop's it in just one step.

LockFreeQueue

The LockFreeQueue is used for threadsafe queue access without locking. Besides the template parameter for the type you must specify the fixed size of the queue. The API equals those of the std::queue or std::priority_queue with some exceptions. Compared to the DoubleBufferQueue the LockFreeQueue should be faster as it doesn't lock access which is very expensive. Comparing the execution speed of the unit tests (LockFreeQueue and DoubleBufferQueue use exactly the same tests except that there are three more for the LockFreeQueue to test some special cases) shows a speedup of up to a factor of 2 to 3 using LockFreeQueue instead of DoubleBufferQueue.

ClockError push();


push() method basically returns ClockError::SUCCESS, except there is no space available in the queue. In this case it returns ClockError::NO_SPACE_AVAILABLE; std::queue just returns void.

ClockError pop();


pop() method basically returns ClockError::SUCCESS, except there is no element in the queue. In this case it returns ClockError::NO_ELEMENT; std::queue just returns void.

ClockError front(T & value);


The front() method has the same return behaviour as the pop() method. The real return value, the front element of the queue if existing, is returned by reference.

ClockError poll(T & value);


The poll() method has the same return behaviour as the pop() method. It returns the front element of the queue by reference as the front() method and pop's it in just one step.