Check for unix/windows headers
[metaproxy-moved-to-github.git] / src / thread_pool_observer.hpp
1 /* $Id: thread_pool_observer.hpp,v 1.5 2005-11-04 10:27:51 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #ifndef YP2_THREAD_POOL_OBSERVER_HPP
8 #define YP2_THREAD_POOL_OBSERVER_HPP
9
10 #include <boost/thread/thread.hpp>
11 #include <boost/thread/mutex.hpp>
12 #include <boost/thread/condition.hpp>
13
14 #include <ctype.h>
15
16 #include <deque>
17 #include <yaz++/socket-observer.h>
18 #include <yaz/yconfig.h>
19
20 namespace yp2 {
21     class IThreadPoolMsg {
22     public:
23         virtual IThreadPoolMsg *handle() = 0;
24         virtual void result() = 0;
25         virtual ~IThreadPoolMsg();
26     };
27
28     class ThreadPoolSocketObserver : public yazpp_1::ISocketObserver {
29     private:
30         class Worker {
31         public:
32             Worker(ThreadPoolSocketObserver *s) : m_s(s) {};
33             ThreadPoolSocketObserver *m_s;
34             void operator() (void) {
35                 m_s->run(0);
36             }
37         };
38     public:
39         ThreadPoolSocketObserver(yazpp_1::ISocketObservable *obs,
40                                  int no_threads);
41         virtual ~ThreadPoolSocketObserver();
42         void socketNotify(int event);
43         void put(IThreadPoolMsg *m);
44         IThreadPoolMsg *get();
45         void run(void *p);
46         int m_fd[2];
47     private:
48         yazpp_1::ISocketObservable *m_SocketObservable;
49         int m_no_threads;
50         boost::thread_group m_thrds;
51
52         std::deque<IThreadPoolMsg *> m_input;
53         std::deque<IThreadPoolMsg *> m_output;
54
55         boost::mutex m_mutex_input_data;
56         boost::condition m_cond_input_data;
57         boost::mutex m_mutex_output_data;
58         bool m_stop_flag;
59
60     
61     };
62 }
63 #endif
64 /*
65  * Local variables:
66  * c-basic-offset: 4
67  * indent-tabs-mode: nil
68  * c-file-style: "stroustrup"
69  * End:
70  * vim: shiftwidth=4 tabstop=8 expandtab
71  */
72