Simple tools for multi threading / objects in plain C Snapshot
Functions
tpool.c File Reference
#include "tpool.h"
#include <butils/errorp.h>
#include <pthread.h>

Go to the source code of this file.

Functions

void RUNNABLE_init (RUNNABLE *runnable, RUNNABLE_HANDLER handler, RUNNABLE_HANDLER free_request)
 constructs a RUNNABLE instance
void RUNNABLE_free (RUNNABLE *runnable)
 free a RUNNABLE instance
static void * worker_thread (void *arg)
THREADPOOLTHREADPOOL_init (RUNNABLE_HANDLER process_result, int queue_size, int num_threads, int stack_size_kb)
 constructs a thread pool and starts it.
void THREADPOOL_close (THREADPOOL *pool)
int THREADPOOL_send_block_on_queue_full (THREADPOOL *pool, RUNNABLE *request)
 posts a work request to the pool; blocks if request queue limit is reached
int THREADPOOL_send_fail_on_queue_full (THREADPOOL *pool, RUNNABLE *request)
 posts a work request to the pool; blocks if request queue limit is reached

Function Documentation

static void* worker_thread ( void *  arg) [static]

Definition at line 25 of file tpool.c.

{
  THREADPOOL *pool = (THREADPOOL *) arg;
  RUNNABLE *req;

  while ( (req = TQUEUE_pop( &pool->request_queue ) ) != 0 ) {
     
     req->handle_request( req );
     if (pool->process_result != 0) {
        pool->process_result( req ); 
     }
  }

  CYCLIC_BARRIER_await( &pool->all_finished );

  return 0;
}