Main Page | Modules | Data Structures | File List | Data Fields

Worker Thread System
[State Daemon]


Typedefs

typedef smd_worker_group_t smd_worker_group_t
typedef smd_worker_t smd_worker_t
typedef sul_error_t *(* smd_worker_fn_t )(smd_worker_t *worker, void *baton, apr_pool_t *pool)

Functions

sul_error_t * smd_worker_group_create (smd_worker_group_t **self, apr_pool_t *pool)
sul_error_t * smd_worker_group_destroy (smd_worker_group_t *group)
sul_error_t * smd_worker_group_launch (smd_worker_group_t *group, smd_worker_t **ptr, smd_worker_fn_t fn, void *baton, apr_size_t queue_sz, apr_pool_t *pool)
sul_error_t * smd_worker_group_stop (smd_worker_group_t *group, smd_worker_t *worker)
sul_boolean_t smd_worker_is_alive (smd_worker_t *worker)
apr_queue_t * smd_worker_queue (smd_worker_t *worker)
sul_error_t * smd_worker_hybernate (smd_worker_t *worker, apr_interval_time_t interval)
smd_worker_group_t * smd_worker_get_group (smd_worker_t *worker)
apr_thread_mutex_t * smd_worker_mutex_get (smd_worker_t *worker)

Typedef Documentation

typedef sul_error_t*(* smd_worker_fn_t)(smd_worker_t *worker, void *baton, apr_pool_t *pool)
 

Worker function prototype that is invoked for worker functions.

typedef struct smd_worker_group_t smd_worker_group_t
 

Worker group instance for spawning multithreaded worker functions for doing cool things. Workers can run for as long as necessary.

typedef struct smd_worker_t smd_worker_t
 

Workers do work. Each of them has an associated working function.


Function Documentation

smd_worker_group_t* smd_worker_get_group (  smd_worker_t *  worker  ) 
 

Gets the Worker Group for a specific Worker. Usefull for when you'd like to spawn more workers under the group.

Parameters:
worker A worker.
Returns:
A worker group.

sul_error_t* smd_worker_group_create (  smd_worker_group_t **  self,
apr_pool_t *  pool
) 
 

Creates a new Worker Group.

Parameters:
self Pointer to receive the new Worker Group.
pool Pool to allocate the Worker Group from.
Returns:
An sul_error_t instance if an error occured and NULL otherwise.

sul_error_t* smd_worker_group_destroy (  smd_worker_group_t *  group  ) 
 

Kills all Workers in a Worker Group and returns once all of their threads have ceased execution.

Parameters:
group A worker group.
Returns:
An sul_error_t instance if an error occured and NULL otherwise.

sul_error_t* smd_worker_group_launch (  smd_worker_group_t *  group,
smd_worker_t **  ptr,
smd_worker_fn_t  fn,
void *  baton,
apr_size_t  queue_sz,
apr_pool_t *  pool
) 
 

Launches a new Worker.

Parameters:
group A worker group to start the Worker in.
ptr Pointer to receive the new Worker.
fn Function to invoke in the Worker's thread.
baton Baton to pass to the Worker.
queue_sz Size of the queue created to handle things for this Worker.
pool Pool to allocate overhead from.
Returns:
An sul_error_t instance if an error occured and NULL otherwise.

sul_error_t* smd_worker_group_stop (  smd_worker_group_t *  group,
smd_worker_t *  worker
) 
 

Stops a running Worker instance.

Parameters:
group Worker group that the Worker is in.
worker Worker to stop.
Returns:
An sul_error_t instance if an error occured and NULL otherwise.

sul_error_t* smd_worker_hybernate (  smd_worker_t *  worker,
apr_interval_time_t  interval
) 
 

Puts the current thread to sleep for interval microseconds, at the very minimum and wakes up with the thread is interrupted or awakened. Awakenings usually indicate that the thread should die. Note that this is one of two methods that a worker may block for activity.

Note:
This should only be called from the worker's thread.
Parameters:
worker A valid worker.
interval Number of microseconds to sleep for before returning.
Returns:
An sul_error_t instance if an error occured and NULL otherwise.

sul_boolean_t smd_worker_is_alive (  smd_worker_t *  worker  ) 
 

Checks to see if the given Worker is still alive or if it's been killed.

Parameters:
worker A valid worker.
Returns:
True if the Worker given is still alive and ticking.

apr_thread_mutex_t* smd_worker_mutex_get (  smd_worker_t *  worker  ) 
 

Gets the mutex that is locked and held when we come OUT of hybernation and are running normally.

Parameters:
worker A worker.
Returns:
Thread wake mutex for the worker.

apr_queue_t* smd_worker_queue (  smd_worker_t *  worker  ) 
 

Returns the APR queue associated with a worker. Worker's can use these to get jobs and items in a thread safe manner from other threads. When a worker is to die, this queue will also be terminated. This and the hybernate facility are the two methods that worker threads may block for activity.

Parameters:
worker An already running worker.
Returns:
A queue.


Generated on Wed Apr 28 09:38:38 2004 for State by doxygen 1.3.5