Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
Thread handling

Detailed Description

See also
Barracuda Introduction

Classes

struct  HttpCmdThreadPool
 An instance of this class provides a thread pool to an instance of the HttpServer class. More...
 
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...
 

Typedefs

typedef struct HttpCmdThreadPool HttpCmdThreadPool
 An instance of this class provides a thread pool to an instance of the HttpServer class. More...
 
typedef void(* Thread_Run) (struct Thread *th)
 Entry point invoked in the new thread after Thread::start. More...
 

Enumerations

enum  ThreadPriority
 Portable priority choices, mapped to the target operating system. More...
 

Functions

BA_API void HttpCmdThreadPool_constructor (HttpCmdThreadPool *o, HttpServer *server, ThreadPriority priority, int stackSize)
 Create workers and bind the pool to a server. More...
 
BA_API void HttpCmdThreadPool_destructor (HttpCmdThreadPool *o)
 Wait for worker completion and detach the pool. More...
 
 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. More...
 
 HttpCmdThreadPool::~HttpCmdThreadPool ()
 Terminates all threads in the thread pool and deregisters the thread pool in the HttpServer instance. More...
 
 ThreadLock::ThreadLock (ThreadMutex &m)
 Acquire the mutex until scope exit. More...
 
 ThreadLock::ThreadLock (ThreadMutex *m)
 Acquire the mutex until scope exit. More...
 
 ThreadLock::~ThreadLock ()
 Unlock the mutex. More...
 
 ThreadReleaseLock::ThreadReleaseLock (struct HttpRequest *req)
 Temporarily release the owned mutex; reacquire at scope exit. More...
 
 ThreadReleaseLock::ThreadReleaseLock (ThreadMutex &m)
 Temporarily release the owned mutex; reacquire at scope exit. More...
 
 ThreadReleaseLock::ThreadReleaseLock (ThreadMutex *m)
 Temporarily release the owned mutex; reacquire at scope exit. More...
 
 ThreadReleaseLock::ThreadReleaseLock (ThreadLock &tl)
 Temporarily release the owned mutex; reacquire at scope exit. More...
 
 ThreadReleaseLock::ThreadReleaseLock (ThreadLock *tl)
 Temporarily release the owned mutex; reacquire at scope exit. More...
 
 ThreadReleaseLock::~ThreadReleaseLock ()
 Reacquire the same mutex before leaving scope. More...
 

Typedef Documentation

◆ HttpCmdThreadPool

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 Http Command Thread Pool documentation for more information.

◆ Thread_Run

typedef void(* Thread_Run) (struct Thread *th)

Entry point invoked in the new thread after Thread::start.

Parameters
[in,out]thBorrowed originating Thread object, valid until execution has finished. Returning finishes the entry point; it does not free th. The dispatcher mutex is not automatically held on entry.

Enumeration Type Documentation

◆ ThreadPriority

Portable priority choices, mapped to the target operating system.

Actual scheduling policy and supported priority differences are port-specific. You can set 1 of 5 priorities: ThreadPrioLowest, ThreadPrioLow, ThreadPrioNormal, ThreadPrioHigh and ThreadPrioHighest

Function Documentation

◆ HttpCmdThreadPool()

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.

The constructor returns no status. Platform thread creation failures use the Thread implementation's error handling. The worker array must be allocated successfully for the pool to serve requests.

Parameters
serverRequired initialized server, retained by the pool. Keep it alive until after the pool is destroyed.
priorityThreadPriority used for every worker.
stackSizeStack size in bytes for each worker, subject to the target Thread implementation requirements.

◆ HttpCmdThreadPool_constructor()

BA_API void HttpCmdThreadPool_constructor ( HttpCmdThreadPool *  o,
HttpServer *  server,
ThreadPriority  priority,
int  stackSize 
)

Create workers and bind the pool to a server.

Parameters
[out]oCaller-owned pool object.
[in,out]serverRequired initialized server that outlives the pool.
[in]priorityThreadPriority for each worker.
[in]stackSizePer-worker stack size in bytes. No recoverable construction status is returned.
See also
HttpCmdThreadPool::HttpCmdThreadPool

◆ HttpCmdThreadPool_destructor()

BA_API void HttpCmdThreadPool_destructor ( HttpCmdThreadPool *  o)

Wait for worker completion and detach the pool.

Parameters
[in,out]oInitialized pool, destroyed before its server. The caller must hold the dispatcher mutex; it is released and reacquired while waiting. Do not call from one of this pool's workers.

◆ ThreadLock() [1/2]

ThreadLock::ThreadLock ( ThreadMutex &  m)

Acquire the mutex until scope exit.

Parameters
[in,out]mBorrowed initialized mutex, valid for the lock lifetime.

◆ ThreadLock() [2/2]

ThreadLock::ThreadLock ( ThreadMutex *  m)

Acquire the mutex until scope exit.

Parameters
[in,out]mRequired non-NULL borrowed initialized mutex.

◆ ThreadReleaseLock() [1/5]

ThreadReleaseLock::ThreadReleaseLock ( struct HttpRequest *  req)

Temporarily release the owned mutex; reacquire at scope exit.

Parameters
[in,out]reqRequired live request whose dispatcher mutex the current thread owns.

◆ ThreadReleaseLock() [2/5]

ThreadReleaseLock::ThreadReleaseLock ( ThreadLock &  tl)

Temporarily release the owned mutex; reacquire at scope exit.

Parameters
[in,out]tlBorrowed active lock object, valid until this release guard ends.

◆ ThreadReleaseLock() [3/5]

ThreadReleaseLock::ThreadReleaseLock ( ThreadLock *  tl)

Temporarily release the owned mutex; reacquire at scope exit.

Parameters
[in,out]tlRequired non-NULL active lock object, valid until this guard ends.

◆ ThreadReleaseLock() [4/5]

ThreadReleaseLock::ThreadReleaseLock ( ThreadMutex &  m)

Temporarily release the owned mutex; reacquire at scope exit.

Parameters
[in,out]mBorrowed initialized mutex currently owned by this thread.

◆ ThreadReleaseLock() [5/5]

ThreadReleaseLock::ThreadReleaseLock ( ThreadMutex *  m)

Temporarily release the owned mutex; reacquire at scope exit.

Parameters
[in,out]mRequired non-NULL initialized mutex owned by this thread.

◆ ~HttpCmdThreadPool()

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 Mutex for more information.

◆ ~ThreadLock()

ThreadLock::~ThreadLock ( )

Unlock the mutex.

◆ ~ThreadReleaseLock()

ThreadReleaseLock::~ThreadReleaseLock ( )

Reacquire the same mutex before leaving scope.

Do not copy this guard.