1 /* -------------------------------------------------------------------------
2 * tpool.h - htun thread pool defs
3 * Copyright (C) 2002 Moshe Jacobson <moshe@runslinux.net>,
4 * Ola Nordström <ola@triblock.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * -------------------------------------------------------------------------
21 /* $Id: tpool.h,v 2.1 2002/03/25 17:15:33 jehsom Exp $ */
30 * a generic thread pool creation routines
33 typedef struct tpool_work
{
34 void (*handler_routine
)();
36 struct tpool_work
*next
;
43 int do_not_block_when_full
;
46 tpool_work_t
*queue_head
;
47 tpool_work_t
*queue_tail
;
48 pthread_mutex_t queue_lock
;
49 pthread_cond_t queue_not_full
;
50 pthread_cond_t queue_not_empty
;
51 pthread_cond_t queue_empty
;
57 * returns a newly chreated thread pool
59 extern tpool_t
*tpool_init(int num_worker_threads
,
60 int max_queue_size
, int do_not_block_when_full
);
63 * returns -1 if work queue is busy
64 * otherwise places it on queue for processing, returning 0
66 * the routine is a func. ptr to the routine which will handle the
67 * work, arg is the arguments to that same routine
69 extern int tpool_add_work(tpool_t
*pool
, void (*routine
)(), void *arg
);
73 * if finish is set the any working threads will be allowd to finish
75 extern int tpool_destroy(tpool_t
*pool
, int finish
);
78 /*extern void tpool_thread(tpool_t *pool); */
81 #endif /* _TPOOL_H_ */