C/C++ Reference
Thread handling

Classes

struct  ThreadLock
 This class provides an easy and less error prone way of locking and releasing a mutex. More...
struct  ThreadReleaseLock
 This class provides an easy and less error prone way of temporarily releasing a locked mutex. More...
struct  ThreadMutex
 A mutual exclusion class. More...
struct  ThreadSemaphore
 A simple semaphore implementation. More...
struct  Thread
 A simple thread class. More...
struct  HttpCmdThreadPool
 An instance of this class provides a thread pool to an instance of the HttpServer class. More...
struct  MqMessage
 The abstract class MqMessage is the only message that can be sent using the MqInterf. More...
struct  MqInterf
 MqInterf is an implementation independent message queue. More...
struct  DefaultMq
 The default message queue is a simple implementation of the abstract interface MqInterf. More...

Typedefs

typedef void(* Thread_Run )(struct Thread *th)
 Prototype for the thread run method.
typedef struct HttpCmdThreadPool HttpCmdThreadPool
 An instance of this class provides a thread pool to an instance of the HttpServer class.
typedef void(* MqMessage_Runnable )(struct MqMessage *m)
 The Message runnable function.
typedef struct MqMessage MqMessage
 The abstract class MqMessage is the only message that can be sent using the MqInterf.
typedef int(* MqInterf_Send )(struct MqInterf *mq, MqMessage *msg)
 The send method implemented by the MqInterf sub-class.
typedef MqMessage *(* MqInterf_Receive )(struct MqInterf *mq)
 The receive method implemented by the MqInterf sub-class.
typedef struct MqInterf MqInterf
 MqInterf is an implementation independent message queue.
typedef DefaultMq DefaultMq
 The default message queue is a simple implementation of the abstract interface MqInterf.

Enumerations

enum  ThreadPriority
 Thread priority list. More...

Functions

 ThreadLock::ThreadLock (ThreadMutex &m)
 Lock a region of code.
 ThreadLock::ThreadLock (ThreadMutex *m)
 Lock a region of code.
 ThreadLock::~ThreadLock ()
 Unlock the mutex.
 ThreadReleaseLock::ThreadReleaseLock (struct HttpRequest *req)
 Temporarily unlock a locked mutex from within a resource.
 ThreadReleaseLock::ThreadReleaseLock (ThreadMutex &m)
 Temporarily unlock a locked mutex.
 ThreadReleaseLock::ThreadReleaseLock (ThreadMutex *m)
 Temporarily unlock a locked mutex.
 ThreadReleaseLock::ThreadReleaseLock (ThreadLock &tl)
 Temporarily unlock a locked mutex.
 ThreadReleaseLock::ThreadReleaseLock (ThreadLock *tl)
 Temporarily unlock a locked mutex.
 ThreadReleaseLock::~ThreadReleaseLock ()
 Lock the temporarily unlock mutex.
 HttpCmdThreadPool::HttpCmdThreadPool (HttpServer *server, ThreadPriority priority, int stackSize)
 Create an instance of HttpCmdThreadPool and bind the thread pool to an instance of the HttpServer class.
 HttpCmdThreadPool::~HttpCmdThreadPool ()
 Terminates all threads in the thread pool and deregisters the thread pool in the HttpServer instance.
 MqMessage::MqMessage (MqMessage_Runnable runnable)
 The abstract message constructor.
void MqMessage::run ()
 The receiver calls the run method when receiving a new message.
 MqInterf::MqInterf (MqInterf_Send send, MqInterf_Receive rec)
 Sub-classes implementing the message queue calls this constructor.
void MqInterf::sendmsg (MqMessage *m)
 Send a message.
MqMessageMqInterf::receivemsg ()
 block and wait for a message.
 DefaultMq::DefaultMq (AllocatorIntf *allocator=0)
 Create an instance of the message queue.

Detailed Description

See also:
Barracuda Introduction

Typedef Documentation

The default message queue is a simple implementation of the abstract interface MqInterf.

This is a generic implementation that should work on all platforms, though the implementation is slow compared to a native message queue in a real time operating system. The message queue is internally using the ThreadSemaphore for waiting and signaling the waiting thread. The data in the queue is protected by using a ThreadMutex.

An instance of this class provides a thread pool to an instance of the HttpServer class.

An instance of this class creates N threads where N is identical to the value set with method HttpServerConfig::setNoOfHttpCommands.

See the WebDAV example startup code for an example of how to use this class.

See the Http Command Thread Pool documentation for more information.

typedef struct MqInterf MqInterf

MqInterf is an implementation independent message queue.

This abstract interface class is used by some of the Barracuda classes when deferring the execution of a job to another thread.

The class should be sub-classed and implemented using the native message queue primitives provided by your platform.

typedef MqMessage*(* MqInterf_Receive)(struct MqInterf *mq)

The receive method implemented by the MqInterf sub-class.

Parameters:
mqa pointer to the base class. This should be upcast to the implementing class type.
Returns:
the message received.
typedef int(* MqInterf_Send)(struct MqInterf *mq, MqMessage *msg)

The send method implemented by the MqInterf sub-class.

Parameters:
mqa pointer to the base class. This should be upcast to the implementing class type.
msgthe message to send.
Returns:
0 on success, -1 on error. An error could indicate that the message queue is full.
typedef struct MqMessage MqMessage

The abstract class MqMessage is the only message that can be sent using the MqInterf.

This class should be sub-classed, and the run method must be implemented by the sub-class. The run method is activated by the receiver.

typedef void(* MqMessage_Runnable)(struct MqMessage *m)

The Message runnable function.

Parameters:
mthe message. Upcast this parameter to the implementing class.

Enumeration Type Documentation

Thread priority list.

You can set 1 of 5 priorities: ThreadPrioLowest, ThreadPrioLow, ThreadPrioNormal, ThreadPrioHigh and ThreadPrioHighest


Function Documentation

DefaultMq::DefaultMq ( AllocatorIntf allocator = 0)

Create an instance of the message queue.

Parameters:
allocatorthe allocator used for allocating nodes for the message queue. A node is of type DefaultMqNode, thus you can use the fixed size allocator for the message queue. A message queue of size 5 can be constructed as:
         U8 buf[sizeof(DefaultMqNode)*5];
         FixedSizeAllocator alloc(buf, sizeof(buf), sizeof(DefaultMqNode));
         DefaultMq mq(&alloc);
HttpCmdThreadPool::HttpCmdThreadPool ( HttpServer server,
ThreadPriority  priority,
int  stackSize 
)

Create an instance of HttpCmdThreadPool and bind the thread pool to an instance of the HttpServer class.

The constructor creates N threads, where N is set identical to the number of HttpCommand instances in the HttpServer object. See HttpServerConfig::setNoOfHttpCommands for more information.

Please note that failure to create the necessary resources is considered a fatal error.

Parameters:
serveris the HttpServer instance you bind this object to.
priorityis the priority for the created thread(s).
stackSizeis the stack size for the created thread(s).
MqInterf::MqInterf ( MqInterf_Send  send,
MqInterf_Receive  rec 
)

Sub-classes implementing the message queue calls this constructor.

Parameters:
senda pointer to the method implementing send.
reca pointer to the method implementing receive.
MqMessage::MqMessage ( MqMessage_Runnable  runnable)

The abstract message constructor.

Messages must inherit from this class and implement the "run" method.

Parameters:
runnablea pointer to the runnable method.
MqMessage * MqInterf::receivemsg ( )

block and wait for a message.

The receiver must call the run method in the MqMessage when receiving a message.

void MqInterf::sendmsg ( MqMessage m)

Send a message.

Parameters:
mthe message to send.
ThreadLock::ThreadLock ( ThreadMutex m)

Lock a region of code.

ThreadLock::ThreadLock ( ThreadMutex m)

Lock a region of code.

ThreadReleaseLock::ThreadReleaseLock ( struct HttpRequest req)

Temporarily unlock a locked mutex from within a resource.

ThreadReleaseLock::ThreadReleaseLock ( ThreadMutex m)

Temporarily unlock a locked mutex.

ThreadReleaseLock::ThreadReleaseLock ( ThreadMutex m)

Temporarily unlock a locked mutex.

ThreadReleaseLock::ThreadReleaseLock ( ThreadLock tl)

Temporarily unlock a locked mutex.

ThreadReleaseLock::ThreadReleaseLock ( ThreadLock tl)

Temporarily unlock a locked mutex.

HttpCmdThreadPool::~HttpCmdThreadPool ( )

Terminates all threads in the thread pool and deregisters the thread pool in the HttpServer instance.

Make sure you run this destructor before you terminate the HttpServer instance. Please note that calling this destructor may take considerable time as the destructor must wait for all threads to complete.

The dispatcher must be locked prior to calling the destructor. See the Dispatcher Mutext for more information.

ThreadLock::~ThreadLock ( )

Unlock the mutex.

ThreadReleaseLock::~ThreadReleaseLock ( )

Lock the temporarily unlock mutex.