Allow any number of worker threads for sel_thread. Added optional parameter
[pazpar2-moved-to-github.git] / src / sel_thread.h
1 /* $Id: sel_thread.h,v 1.2 2007-04-23 08:06:21 adam Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #ifndef SEL_THREAD_H
23 #define SEL_THREAD_H
24 #include <yaz/yconfig.h>
25
26 YAZ_BEGIN_CDECL
27
28 /** \brief select thread handler type */
29 typedef struct sel_thread *sel_thread_t;
30
31 /** \brief creates select thread 
32     \param work_handler handler that does work in worker thread
33     \param work_destroy optional destroy handler for work (0 = no handler)
34     \param read_fd pointer to readable socket upon completion
35     \param no_of_threads number of worker threads
36     \returns select thread handler
37
38     Creates a worker thread. The worker thread will signal "completed"
39     work by sending one byte to the read_fd file descriptor.
40     You are supposed to select or poll on that for reading and
41     call sel_thread_result accordingly.
42 */
43 sel_thread_t sel_thread_create(void (*work_handler)(void *work_data),
44                                void (*work_destroy)(void *work_data),
45                                int *read_fd, int no_of_threads);
46
47 /** \brief destorys select thread 
48     \param p select thread handler
49 */
50 void sel_thread_destroy(sel_thread_t p);
51
52 /** \brief adds work to be carried out in thread
53     \param p select thread handler
54     \param data pointer to data that work_handler knows about
55 */
56 void sel_thread_add(sel_thread_t p, void *data);
57
58 /** \brief gets result of work 
59     \param p select thread handler
60     \returns data for work (which work_handler has been working on)
61 */
62 void *sel_thread_result(sel_thread_t p);
63
64 YAZ_END_CDECL
65
66
67 #endif
68
69
70 /*
71  * Local variables:
72  * c-basic-offset: 4
73  * indent-tabs-mode: nil
74  * End:
75  * vim: shiftwidth=4 tabstop=8 expandtab
76  */