summaryrefslogtreecommitdiff
path: root/src/thrd/pool.h
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2013-04-06 13:14:43 +0200
committerPaul Buetow <paul@buetow.org>2013-04-06 13:14:43 +0200
commitf038883a6e004eb4312ba1e761da06b596e14d3f (patch)
tree358f989cac07885cfa913c66a0d563d18c021b26 /src/thrd/pool.h
parent98eac951f8087b213f5850bd126dcb279db360a8 (diff)
tagging ychat-0.7.7.0ychat-0.7.7.0
Diffstat (limited to 'src/thrd/pool.h')
-rwxr-xr-xsrc/thrd/pool.h65
1 files changed, 39 insertions, 26 deletions
diff --git a/src/thrd/pool.h b/src/thrd/pool.h
index ab03b57..71ecaa9 100755
--- a/src/thrd/pool.h
+++ b/src/thrd/pool.h
@@ -3,52 +3,65 @@
#ifndef POOL_H
#define POOL_H
-#include <queue>
-
using namespace std;
-class pool
+class pool
{
private:
- friend class thro;
+ static int i_thrd_used;
- struct task
+ typedef struct tpool_work
{
- void(*p_func)(void*);
+ void (*routine)(void*); ///
void *p_void;
+ struct tpool_work *next;
+ }
+ tpool_work_t;
+
+ typedef struct tpool
+ {
+ // pool characteristics:
+ int num_threads;
+ int max_queue_size;
- task(void(*p_func)(void*), void *p_void)
- {
- this->p_func = p_func;
- this->p_void = p_void;
- }
- };
+ // pool state
+ pthread_t *threads;
+ int cur_queue_size;
- pthread_mutex_t mut_threads;
- pthread_mutex_t mut_queue_tasks;
- pthread_mutex_t mut_num_avail_threads;
- pthread_cond_t cond_new_task;
+ tpool_work_t *queue_head;
+ tpool_work_t *queue_tail;
- int i_num_avail_threads;
- int i_num_total_threads;
+ pthread_mutex_t queue_lock;
+ pthread_cond_t queue_not_empty;
+ pthread_cond_t queue_not_full;
+ pthread_cond_t queue_empty;
+ }
+ *tpool_t;
- queue<task*> queue_tasks;
+ int i_thrd_pool_size;
+ int i_thrd_pool_queue;
- int increase_pool(int i_num);
- void add_task( void(*p_func)(void*), void* p_void );
- static void* wait_for_task(void *p_void);
- static void run_func(void *p_void);
+ tpool_t thread_pool;
+
+ void tpool_init( tpool_t *tpoolp, int num_worker_threads, int max_queue_size);
+ int tpool_add_work( tpool_t tpool, void(*routine)(void*), void* p_void );
+ static void* tpool_thread( void *p_void);
+ static void run_func( void *p_void );
public:
pool();
- ~pool();
- void run(void* p_void);
- bool allow_user_login();
+ // inline (speed)!
+ void run( void *p_void )
+ {
+ tpool_add_work( thread_pool, run_func, p_void );
+ }
#ifdef NCURSES
void print_pool_size();
+ static void print_threads(int i_thrd_used);
#endif
+
};
#endif