Started work on select thread system.
[pazpar2-moved-to-github.git] / src / sel_thread.h
1 /* $Id: sel_thread.h,v 1.1 2007-04-20 10:06:52 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 read_fd pointer to readable socket upon completion
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                                int *read_fd);
43
44 /** \brief destorys select thread 
45     \param p select thread handler
46 */
47 void sel_thread_destroy(sel_thread_t p);
48
49 /** \brief adds work to be carried out in thread
50     \param p select thread handler
51     \param data pointer to data that work_handler knows about
52 */
53 void sel_thread_add(sel_thread_t p, void *data);
54
55 /** \brief gets result of work 
56     \param p select thread handler
57     \returns data for work (which work_handler has been working on)
58 */
59 void *sel_thread_result(sel_thread_t p);
60
61 YAZ_END_CDECL
62
63
64 #endif
65
66
67 /*
68  * Local variables:
69  * c-basic-offset: 4
70  * indent-tabs-mode: nil
71  * End:
72  * vim: shiftwidth=4 tabstop=8 expandtab
73  */