Add more proper options for t-server
[yazproxy-moved-to-github.git] / src / msg-thread.h
1 /* $Id: msg-thread.h,v 1.7 2005-09-26 09:22:59 adam Exp $
2    Copyright (c) 1998-2005, Index Data.
3
4 This file is part of the yaz-proxy.
5
6 YAZ proxy 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 YAZ proxy 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 YAZ proxy; 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 #include <pthread.h>
23 #include <unistd.h>
24 #include <ctype.h>
25
26 #if HAVE_DLFCN_H
27 #include <dlfcn.h>
28 #endif
29
30 #include <yaz++/socket-observer.h>
31 #include <yaz/yconfig.h>
32
33 class IMsg_Thread {
34 public:
35     virtual IMsg_Thread *handle() = 0;
36     virtual void result() = 0;
37     virtual ~IMsg_Thread();
38 };
39
40 class Msg_Thread_Queue_List {
41     friend class Msg_Thread_Queue;
42  private:
43     IMsg_Thread *m_item;
44     Msg_Thread_Queue_List *m_next;
45 };
46
47 class Msg_Thread_Queue {
48  public:
49     Msg_Thread_Queue();
50     void enqueue(IMsg_Thread *in);
51     IMsg_Thread *dequeue();
52     int size();
53  private:
54     Msg_Thread_Queue_List *m_list;
55 };
56
57 class Msg_Thread : public yazpp_1::ISocketObserver {
58  public:
59     Msg_Thread(yazpp_1::ISocketObservable *obs, int no_threads);
60     virtual ~Msg_Thread();
61     void socketNotify(int event);
62     void put(IMsg_Thread *m);
63     IMsg_Thread *get();
64     void run(void *p);
65     int m_fd[2];
66 private:
67     yazpp_1::ISocketObservable *m_SocketObservable;
68     int m_no_threads;
69     pthread_t *m_thread_id;
70     Msg_Thread_Queue m_input;
71     Msg_Thread_Queue m_output;
72     pthread_mutex_t m_mutex_input_data;
73     pthread_cond_t m_cond_input_data;
74     pthread_mutex_t m_mutex_output_data;
75     bool m_stop_flag;
76 };
77
78 /*
79  * Local variables:
80  * c-basic-offset: 4
81  * indent-tabs-mode: nil
82  * End:
83  * vim: shiftwidth=4 tabstop=8 expandtab
84  */
85