Lunchbox  1.6.0
Classes | Functions | Typedefs | Enumerations
lunchbox Namespace Reference

Abstraction layer and common utilities for multi-threaded programming. More...

Classes

class  Any
 A class which can hold instances of any type. More...
class  bad_any_cast
 A specialization for exceptions thrown by an unsuccessful any_cast. More...
struct  registerWrapper
 Utility struct for registering types for lunchbox::Any from a type list. More...
class  Atomic
 A variable with atomic semantics and standalone atomic operations. More...
class  Buffer
 A simple memory buffer with some helper functions. More...
class  Clock
 A class for time measurements. More...
class  Condition
 A condition variable and associated lock. More...
class  DSO
 Helper to access dynamic shared objects (DSO) More...
class  PtrHash
 A hash for pointer keys. More...
struct  hashRefPtr
 A hash function for RefPtr keys. More...
class  RefPtrHash
 A hash for RefPtr keys. More...
class  UUIDHash
 A hash for UUID keys. More...
class  IndexIterator
 Counter-based, as opposed to pointer-based, iterator for any container. More...
class  Launcher
 The launcher executes a command from a separate process. More...
class  LFQueue
 A thread-safe, lock-free queue with non-blocking access. More...
class  LFVector
 STL-like vector implementation providing certain thread-safety guarantees. More...
class  LFVectorIterator
class  Lock
 A lock (mutex) primitive. More...
class  Lockable
 A convenience structure to hold data together with a lock for access. More...
class  LogBuffer
class  Log
 The logging class. More...
class  MemoryMap
 Helper to map a file to a memory address (mmap) More...
class  Monitor
 A monitor primitive. More...
class  MTQueue
 A thread-safe queue with a blocking read access. More...
class  NonCopyable
 Base class to make objects non-copyable. More...
class  OMP
 Base class for OpenMP functionality. More...
class  PerThread
 Implements thread-specific storage for C++ objects. More...
class  PerThreadRef
 Thread-specific storage for a RefPtr. More...
class  Pool
 An object allocation pool. More...
class  Referenced
 Base class for referenced objects. More...
class  RefPtr
 A smart reference pointer, aka boost::intrusive_ptr. More...
class  RequestHandler
 A thread-safe request handler. More...
class  RNG
 A random number generator. More...
class  ScopedMutex
 A scoped mutex. More...
class  Servus
 Simple wrapper for ZeroConf key/value pairs. More...
class  SpinLock
 A fast lock for uncontended memory access. More...
class  Thread
 An utility class to execute code in a separate execution thread. More...
class  ThreadID
 An utility class to wrap OS-specific thread identifiers. More...
class  TimedLock
 A mutex with timeout capabilities. More...
class  uint128_t
 A base type for 128 bit unsigned integer values. More...
class  UUID
 Provides a universally unique identifier. More...
class  Version
 Information about the current LunchBox version. More...

Functions

template<typename ValueType >
ValueType * any_cast (Any *operand)
 Retrieve the value stored in an Any including type checking.
template<typename ValueType >
const ValueType * any_cast (const Any *operand)
 Retrieve the value stored in an Any including type checking.
template<typename ValueType >
ValueType any_cast (Any &operand)
 Retrieve the value stored in an Any including type checking.
template<typename ValueType >
ValueType any_cast (const Any &operand)
 Retrieve the value stored in an Any including type checking.
template<typename ValueType >
ValueType * unsafe_any_cast (Any *operand)
 Retrieve the value stored in an Any without type checking.
template<typename ValueType >
const ValueType * unsafe_any_cast (const Any *operand)
 Retrieve the value stored in an Any without type checking.
template<typename ValueType >
ValueType unsafe_any_cast (Any &operand)
 Retrieve the value stored in an Any without type checking.
template<typename ValueType >
ValueType unsafe_any_cast (const Any &operand)
 Retrieve the value stored in an Any without type checking.
template<class TypeList , class Archive >
void registerTypelist (Archive &ar)
 Registers the types from the given type list for serializing it inside a lunchbox::Any through the given archive.
template<class Archive , class Object , class Stream >
void serializeAny (Object &object, Stream &stream)
 Serializes the given object which can be a lunchbox::Any through the given archive type to/from the given stream.
template<class Archive , class Object , class Stream >
void saveAny (Object &object, Stream &stream)
 Saves the given object which can be a lunchbox::Any through the given archive type to/from the given stream.
template<class Archive , class Object , class Stream >
void loadAny (Object &object, Stream &stream)
 Loads the given object which can be a lunchbox::Any through the given archive type to/from the given stream.
void memoryBarrier ()
 Perform a full memory barrier.
void memoryBarrierAcquire ()
 Perform a load-with-acquire memory barrier.
void memoryBarrierRelease ()
 Perform a store-with-release memory barrier.
template<class T >
int32_t getIndexOfLastBit (T value)
template<class T >
void byteswap (T &value)
 Swap the byte order of the given value.
template<>
int32_t getIndexOfLastBit< uint32_t > (uint32_t value)
template<>
int32_t getIndexOfLastBit< uint64_t > (uint64_t value)
template<>
void byteswap (void *&value)
template<>
void byteswap (bool &value)
template<>
void byteswap (char &value)
template<>
void byteswap (signed char &value)
template<>
void byteswap (unsigned char &value)
template<>
void byteswap (uint32_t &value)
template<>
void byteswap (int32_t &value)
template<>
void byteswap (float &value)
template<>
void byteswap (uint16_t &value)
template<>
void byteswap (int16_t &value)
template<>
void byteswap (uint64_t &value)
template<>
void byteswap (int64_t &value)
template<>
void byteswap (double &value)
template<>
void byteswap (uint128_t &value)
template<>
void byteswap (UUID &value)
template<typename T >
void byteswap (typename std::vector< T > &value)
bool daemonize ()
 Turn the calling process into a daemon.
void abort ()
void checkHeap ()
std::ostream & sysError (std::ostream &os)
 Print a textual description of the current system error.
std::ostream & backtrace (std::ostream &os)
 Print the current call stack.
std::string demangleTypeID (const char *mangled)
template<class T >
std::string className (T *object)
 Print the RTTI name of the given class.
template<class T >
std::string className (T &object)
 Print the RTTI name of the given class.
Strings searchDirectory (const std::string &directory, const std::string &pattern)
 Retrieve a list of files in a directory matching a pattern.
std::string getFilename (const std::string &filename)
std::string getDirname (const std::string &filename)
bool init (const int argc, char **argv)
 Initialize the Lunchbox base classes.
bool exit ()
 De-initialize the Lunchbox base classes.
template<class T >
std::ostream & operator<< (std::ostream &os, const LFVector< T > &v)
 Output the vector and up to 256 items to the ostream.
template<class D , class L >
std::ostream & operator<< (std::ostream &os, const Lockable< D, L > &l)
 Print the data to the given output stream.
std::ostream & indent (std::ostream &os)
 Increases the indentation level of the Log stream, causing subsequent lines to be intended by four characters.
std::ostream & exdent (std::ostream &os)
 Decrease the indent of the Log stream.
std::ostream & disableFlush (std::ostream &os)
 Disable flushing of the Log stream.
std::ostream & enableFlush (std::ostream &os)
 Re-enable flushing of the Log stream.
std::ostream & forceFlush (std::ostream &os)
 Flush the Log stream regardless of the auto-flush state.
std::ostream & disableHeader (std::ostream &os)
 Disable printing of the Log header for subsequent lines.
std::ostream & enableHeader (std::ostream &os)
 Re-enable printing of the Log header.
template<typename T >
std::ostream & operator<< (std::ostream &os, const Monitor< T > &monitor)
 Print the monitor to the given output stream.
template<class T >
void perThreadDelete (T *object)
 Default PerThread destructor deleting the object.
template<class T >
void perThreadNoDelete (T *object)
 Empty PerThread destructor.
template<class T >
std::ostream & operator<< (std::ostream &os, RefPtr< T > rp)
 Print the reference pointer to the given output stream.
template<class T >
std::string className (const RefPtr< T > &rp)
std::ostream & operator<< (std::ostream &, const RequestHandler &)
std::ostream & operator<< (std::ostream &, const Servus &)
 Output the servus instance in human-readable format.
void sleep (const uint32_t milliSeconds)
 Sleep the current thread for a number of milliseconds.
std::ostream & operator<< (std::ostream &, const ThreadID &)
 Print the thread to the given output stream.
std::ostream & operator<< (std::ostream &os, const uint128_t &id)
 ostream operator for 128 bit unsigned integers.
uint128_t operator+ (const uint128_t &a, const uint64_t &b)
 Add a 64 bit value to a 128 bit value.
uint128_t operator+ (const uint128_t &a, const uint128_t &b)
 Add two 128 bit values.
uint128_t operator- (const uint128_t &a, const uint64_t &b)
 Subtract a 64 bit value from a 128 bit value.
uint128_t operator& (const uint128_t &a, const uint128_t &b)
 Bitwise and operation on two 128 bit values.
uint128_t operator| (const uint128_t &a, const uint128_t &b)
 Bitwise or operation on two 128 bit values.
uint128_t make_uint128 (const char *string)
 Create a 128 bit integer based on a string.

Typedefs

typedef boost::mpl::list
< int8_t, uint8_t, int16_t,
uint16_t, int32_t, uint32_t,
int64_t, uint64_t, float,
double, bool, std::string,
uint128_t
podTypes
 List of supported POD types for lunchbox::Any serialization.
typedef Monitor< bool > Monitorb
 A boolean monitor variable.
typedef Monitor< uint32_t > Monitoru
 An unsigned 32bit integer monitor.
typedef ScopedMutex< SpinLock,
ReadOp > 
ScopedFastRead
 A scoped mutex for a fast uncontended read operation.
typedef ScopedMutex< SpinLock,
WriteOp > 
ScopedFastWrite
 A scoped mutex for a fast uncontended write operation.
typedef ScopedMutex< Lock, ReadOp > ScopedRead
 A scoped mutex for a read operation.
typedef ScopedMutex< Lock,
WriteOp > 
ScopedWrite
 A scoped mutex for a write operation.
typedef ScopedMutex< Condition,
WriteOp > 
ScopedCondition
 A scoped mutex for a write operation on a condition.
typedef std::vector< std::string > Strings
 A vector of std::strings.
typedef Strings::const_iterator StringsCIter
typedef Atomic< int32_t > a_int32_t
 An atomic 32 bit integer variable.
typedef Atomic< ssize_t > a_ssize_t
 An atomic signed size variable.
typedef Buffer< uint8_t > Bufferb
 a byte buffer

Enumerations

enum  LogLevel {
  LOG_ERROR = 1, LOG_WARN, LOG_INFO, LOG_VERB,
  LOG_ALL
}
 The logging levels. More...
enum  LogTopic { LOG_CUSTOM = 0x10, LOG_ANY = 0xffffu }
 The logging topics. More...

Detailed Description

Abstraction layer and common utilities for multi-threaded programming.

Lunchbox provides C++ classes to abstract the underlying operating system and to implement common utilities for multi-threaded C++ programs. Classes with non-virtual destructors are not intended to be subclassed.


Function Documentation

template<typename ValueType >
ValueType* lunchbox::any_cast ( Any *  operand)

Retrieve the value stored in an Any including type checking.

Returns:
the value stored in the given Any, 0 if types are not matching
Version:
1.5.0

Definition at line 232 of file any.h.

References lunchbox::Any::type().

Referenced by any_cast().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename ValueType >
const ValueType* lunchbox::any_cast ( const Any *  operand) [inline]

Retrieve the value stored in an Any including type checking.

Returns:
the value stored in the given Any, 0 if types are not matching
Version:
1.5.0

Definition at line 251 of file any.h.

References any_cast().

+ Here is the call graph for this function:

template<typename ValueType >
ValueType lunchbox::any_cast ( Any &  operand)

Retrieve the value stored in an Any including type checking.

Returns:
the value stored in the given Any
Exceptions:
bad_any_castif types are not matching
Version:
1.5.0

Definition at line 264 of file any.h.

References any_cast(), and lunchbox::Any::type().

+ Here is the call graph for this function:

template<typename ValueType >
ValueType lunchbox::any_cast ( const Any &  operand) [inline]

Retrieve the value stored in an Any including type checking.

Returns:
the value stored in the given Any
Exceptions:
bad_any_castif types are not matching
Version:
1.5.0

Definition at line 284 of file any.h.

References any_cast().

+ Here is the call graph for this function:

std::ostream& lunchbox::backtrace ( std::ostream &  os)

Print the current call stack.

May not be implemented on all platforms.

Version:
1.0

Referenced by lunchbox::Referenced::ref().

+ Here is the caller graph for this function:

template<class T >
void lunchbox::byteswap ( T &  value)

Swap the byte order of the given value.

Version:
1.5.1
template<class T >
std::string lunchbox::className ( T *  object) [inline]

Print the RTTI name of the given class.

Version:
1.0

Definition at line 62 of file debug.h.

Referenced by lunchbox::PerThread< T, D >::operator*(), lunchbox::RefPtr< T >::operator*(), lunchbox::RefPtr< T >::operator->(), and operator<<().

+ Here is the caller graph for this function:

template<class T >
std::string lunchbox::className ( T &  object) [inline]

Print the RTTI name of the given class.

Version:
1.0

Definition at line 66 of file debug.h.

bool lunchbox::daemonize ( ) [inline]

Turn the calling process into a daemon.

Only the forked child process returns from this function. A new session is created and the standard file descriptors are closed. The current working directory is unchanged, and the Log output is not redirected to a file.

Returns:
true on success, false on error.
Version:
1.5.1

Definition at line 39 of file daemon.h.

References exit(), LBWARN, and sysError().

+ Here is the call graph for this function:

std::ostream& lunchbox::disableFlush ( std::ostream &  os)

Disable flushing of the Log stream.

Version:
1.0

Referenced by operator<<().

+ Here is the caller graph for this function:

std::ostream& lunchbox::disableHeader ( std::ostream &  os)

Disable printing of the Log header for subsequent lines.

Version:
1.0
std::ostream& lunchbox::enableFlush ( std::ostream &  os)

Re-enable flushing of the Log stream.

Version:
1.0

Referenced by operator<<().

+ Here is the caller graph for this function:

std::ostream& lunchbox::enableHeader ( std::ostream &  os)

Re-enable printing of the Log header.

Version:
1.0
std::ostream& lunchbox::exdent ( std::ostream &  os)

Decrease the indent of the Log stream.

Version:
1.0
bool lunchbox::exit ( )

De-initialize the Lunchbox base classes.

Returns:
true if the library was successfully de-initialised, false otherwise.
Version:
1.0

Referenced by daemonize().

+ Here is the caller graph for this function:

std::ostream& lunchbox::forceFlush ( std::ostream &  os)

Flush the Log stream regardless of the auto-flush state.

Version:
1.0
std::string lunchbox::getDirname ( const std::string &  filename)
Returns:
the directory name part of a path.
Version:
1.0
std::string lunchbox::getFilename ( const std::string &  filename)
Returns:
the file name part of a path.
Version:
1.0
template<class T >
int32_t lunchbox::getIndexOfLastBit ( value)
Returns:
the position of the last (most significant) set bit, or -1.

Referenced by lunchbox::LFVector< T, nSlots >::LFVector(), and lunchbox::LFVector< T, nSlots >::operator[]().

+ Here is the caller graph for this function:

std::ostream& lunchbox::indent ( std::ostream &  os)

Increases the indentation level of the Log stream, causing subsequent lines to be intended by four characters.

Version:
1.0
bool lunchbox::init ( const int  argc,
char **  argv 
)

Initialize the Lunchbox base classes.

Parameters:
argcthe command line argument count.
argvthe command line argument values.
Returns:
true if the library was successfully initialised, false otherwise
Version:
1.0
uint128_t lunchbox::make_uint128 ( const char *  string)

Create a 128 bit integer based on a string.

The MD5 hash of the given text is used to form the uint128_t.

Parameters:
stringthe string to form the uint128_t from.
Version:
1.3.2
void lunchbox::memoryBarrier ( ) [inline]

Perform a full memory barrier.

Definition at line 38 of file atomic.h.

Referenced by memoryBarrierAcquire(), memoryBarrierRelease(), lunchbox::Atomic< T >::operator!=(), lunchbox::Atomic< T >::operator=(), and lunchbox::Atomic< T >::operator==().

+ Here is the caller graph for this function:

void lunchbox::memoryBarrierAcquire ( ) [inline]

Perform a load-with-acquire memory barrier.

Definition at line 54 of file atomic.h.

References memoryBarrier().

Referenced by lunchbox::Atomic< T >::addAndGet(), lunchbox::Atomic< T >::getAndAdd(), lunchbox::Atomic< T >::getAndSub(), lunchbox::Atomic< T >::operator T(), and lunchbox::Atomic< T >::subAndGet().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void lunchbox::memoryBarrierRelease ( ) [inline]

Perform a store-with-release memory barrier.

Definition at line 65 of file atomic.h.

References memoryBarrier().

Referenced by lunchbox::Atomic< T >::addAndGet(), lunchbox::Atomic< T >::getAndAdd(), lunchbox::Atomic< T >::getAndSub(), and lunchbox::Atomic< T >::subAndGet().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint128_t lunchbox::operator& ( const uint128_t &  a,
const uint128_t &  b 
) [inline]

Bitwise and operation on two 128 bit values.

Version:
1.1.5

Definition at line 266 of file uint128_t.h.

References lunchbox::uint128_t::high(), and lunchbox::uint128_t::low().

+ Here is the call graph for this function:

uint128_t lunchbox::operator+ ( const uint128_t &  a,
const uint64_t &  b 
) [inline]

Add a 64 bit value to a 128 bit value.

Version:
1.0

Definition at line 238 of file uint128_t.h.

References lunchbox::uint128_t::high(), and lunchbox::uint128_t::low().

+ Here is the call graph for this function:

uint128_t lunchbox::operator+ ( const uint128_t &  a,
const uint128_t &  b 
) [inline]

Add two 128 bit values.

Version:
1.5.1

Definition at line 248 of file uint128_t.h.

uint128_t lunchbox::operator- ( const uint128_t &  a,
const uint64_t &  b 
) [inline]

Subtract a 64 bit value from a 128 bit value.

Version:
1.0

Definition at line 256 of file uint128_t.h.

References lunchbox::uint128_t::high(), and lunchbox::uint128_t::low().

+ Here is the call graph for this function:

std::ostream & lunchbox::operator<< ( std::ostream &  os,
const uint128_t &  id 
) [inline]

ostream operator for 128 bit unsigned integers.

Version:
1.0

Definition at line 228 of file uint128_t.h.

std::ostream& lunchbox::operator<< ( std::ostream &  ,
const ThreadID &   
)

Print the thread to the given output stream.

template<class D , class L >
std::ostream& lunchbox::operator<< ( std::ostream &  os,
const Lockable< D, L > &  l 
) [inline]

Print the data to the given output stream.

Definition at line 68 of file lockable.h.

References disableFlush(), and enableFlush().

+ Here is the call graph for this function:

std::ostream& lunchbox::operator<< ( std::ostream &  ,
const Servus &   
)

Output the servus instance in human-readable format.

Version:
1.5.1
template<class T >
std::ostream& lunchbox::operator<< ( std::ostream &  os,
RefPtr< T >  rp 
) [inline]

Print the reference pointer to the given output stream.

Definition at line 177 of file refPtr.h.

References disableFlush(), and enableFlush().

+ Here is the call graph for this function:

template<class T >
std::ostream & lunchbox::operator<< ( std::ostream &  os,
const LFVector< T > &  v 
)

Output the vector and up to 256 items to the ostream.

Version:
0.1

Definition at line 398 of file lfVector.ipp.

References className().

+ Here is the call graph for this function:

template<typename T >
std::ostream& lunchbox::operator<< ( std::ostream &  os,
const Monitor< T > &  monitor 
) [inline]

Print the monitor to the given output stream.

Version:
1.0

Definition at line 381 of file monitor.h.

References lunchbox::Monitor< T >::get().

+ Here is the call graph for this function:

uint128_t lunchbox::operator| ( const uint128_t &  a,
const uint128_t &  b 
) [inline]

Bitwise or operation on two 128 bit values.

Version:
1.1.5

Definition at line 275 of file uint128_t.h.

References lunchbox::uint128_t::high(), and lunchbox::uint128_t::low().

+ Here is the call graph for this function:

template<class T >
void lunchbox::perThreadDelete ( T *  object)

Default PerThread destructor deleting the object.

Version:
1.1.2

Definition at line 31 of file perThread.h.

template<class T >
void lunchbox::perThreadNoDelete ( T *  object)

Empty PerThread destructor.

Version:
1.1.2

Definition at line 34 of file perThread.h.

Strings lunchbox::searchDirectory ( const std::string &  directory,
const std::string &  pattern 
)

Retrieve a list of files in a directory matching a pattern.

Only foo*bar pattern are implemented currently.

Returns:
all file names matching the given pattern in the given directory.
Version:
1.0
void lunchbox::sleep ( const uint32_t  milliSeconds)

Sleep the current thread for a number of milliseconds.

Version:
1.0
std::ostream& lunchbox::sysError ( std::ostream &  os)

Print a textual description of the current system error.

The current system error is OS-specific, e.g., errno or GetLastError().

Version:
1.0

Referenced by daemonize().

+ Here is the caller graph for this function:

template<typename ValueType >
ValueType* lunchbox::unsafe_any_cast ( Any *  operand) [inline]

Retrieve the value stored in an Any without type checking.

Returns:
the value stored in the given Any
Version:
1.5.0

Definition at line 298 of file any.h.

Referenced by unsafe_any_cast().

+ Here is the caller graph for this function:

template<typename ValueType >
const ValueType* lunchbox::unsafe_any_cast ( const Any *  operand) [inline]

Retrieve the value stored in an Any without type checking.

Returns:
the value stored in the given Any
Version:
1.5.0

Definition at line 311 of file any.h.

References unsafe_any_cast().

+ Here is the call graph for this function:

template<typename ValueType >
ValueType lunchbox::unsafe_any_cast ( Any &  operand)

Retrieve the value stored in an Any without type checking.

Returns:
the value stored in the given Any
Version:
1.5.0

Definition at line 323 of file any.h.

References unsafe_any_cast().

+ Here is the call graph for this function:

template<typename ValueType >
ValueType lunchbox::unsafe_any_cast ( const Any &  operand)

Retrieve the value stored in an Any without type checking.

Returns:
the value stored in the given Any
Version:
1.5.0

Definition at line 336 of file any.h.

References unsafe_any_cast().

+ Here is the call graph for this function:


Typedef Documentation

typedef boost::mpl::list< int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, float, double, bool, std::string, uint128_t > lunchbox::podTypes

List of supported POD types for lunchbox::Any serialization.

Definition at line 50 of file anySerialization.h.

A scoped mutex for a write operation on a condition.

Version:
1.3.6

Definition at line 125 of file scopedMutex.h.

A scoped mutex for a fast uncontended read operation.

Version:
1.1.2

Definition at line 113 of file scopedMutex.h.

A scoped mutex for a fast uncontended write operation.

Version:
1.1.2

Definition at line 116 of file scopedMutex.h.

A scoped mutex for a read operation.

Version:
1.1.5

Definition at line 119 of file scopedMutex.h.

typedef ScopedMutex< Lock, WriteOp > lunchbox::ScopedWrite

A scoped mutex for a write operation.

Version:
1.1.5

Definition at line 122 of file scopedMutex.h.

typedef std::vector< std::string > lunchbox::Strings

A vector of std::strings.

Version:
1.0

Definition at line 148 of file types.h.


Enumeration Type Documentation

The logging levels.

Version:
1.0
Enumerator:
LOG_ERROR 

Output critical errors.

LOG_WARN 

Output potentially critical warnings.

LOG_INFO 

Output informational messages.

LOG_VERB 

Be noisy.

Definition at line 41 of file log.h.

The logging topics.

See also:
net/log.h, client/log.h
Version:
1.0
Enumerator:
LOG_CUSTOM 

Log topics for other namespaces start here.

LOG_ANY 

Log all Lunchbox topics.

Definition at line 56 of file log.h.