#ifndef __THRMGR_H__
#define __THRMGR_H__
#include <pthread.h>
#include <sys/time.h>
typedef struct work_item_tag {
struct work_item_tag *next;
void *data;
struct timeval time_queued;
} work_item_t;
typedef struct work_queue_tag {
work_item_t *head;
work_item_t *tail;
int item_count;
} work_queue_t;
typedef enum {
POOL_INVALID,
POOL_VALID,
POOL_EXIT,
} pool_state_t;
typedef struct threadpool_tag {
pthread_mutex_t pool_mutex;
pthread_cond_t pool_cond;
pthread_attr_t pool_attr;
pool_state_t state;
int thr_max;
int thr_alive;
int thr_idle;
int idle_timeout;
void (*handler)(void *);
work_queue_t *queue;
} threadpool_t;
threadpool_t *thrmgr_new(int max_threads, int idle_timeout, void (*handler)(void *));
void thrmgr_destroy(threadpool_t *threadpool);
int thrmgr_dispatch(threadpool_t *threadpool, void *user_data);
#endif