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