-/* $Id: thread_pool_observer.hpp,v 1.1 2005-10-13 20:06:45 adam Exp $
+/* $Id: thread_pool_observer.hpp,v 1.3 2005-10-14 10:27:18 adam Exp $
Copyright (c) 1998-2005, Index Data.
This file is part of the yaz-proxy.
#include <yaz++/socket-observer.h>
#include <yaz/yconfig.h>
-class IThreadPoolMsg {
-public:
- virtual IThreadPoolMsg *handle() = 0;
- virtual void result() = 0;
- virtual ~IThreadPoolMsg();
-};
+namespace yp2 {
+ class IThreadPoolMsg {
+ public:
+ virtual IThreadPoolMsg *handle() = 0;
+ virtual void result() = 0;
+ virtual ~IThreadPoolMsg();
+ };
-class ThreadPoolSocketObserver : public yazpp_1::ISocketObserver {
- public:
- ThreadPoolSocketObserver(yazpp_1::ISocketObservable *obs, int no_threads);
- virtual ~ThreadPoolSocketObserver();
- void socketNotify(int event);
- void put(IThreadPoolMsg *m);
- IThreadPoolMsg *get();
- void run(void *p);
- int m_fd[2];
-private:
- yazpp_1::ISocketObservable *m_SocketObservable;
- int m_no_threads;
- boost::thread_group m_thrds;
+ class ThreadPoolSocketObserver : public yazpp_1::ISocketObserver {
+ private:
+ class Worker {
+ public:
+ Worker(ThreadPoolSocketObserver *s) : m_s(s) {};
+ ThreadPoolSocketObserver *m_s;
+ void operator() (void) {
+ m_s->run(0);
+ }
+ };
+ public:
+ ThreadPoolSocketObserver(yazpp_1::ISocketObservable *obs,
+ int no_threads);
+ virtual ~ThreadPoolSocketObserver();
+ void socketNotify(int event);
+ void put(IThreadPoolMsg *m);
+ IThreadPoolMsg *get();
+ void run(void *p);
+ int m_fd[2];
+ private:
+ yazpp_1::ISocketObservable *m_SocketObservable;
+ int m_no_threads;
+ boost::thread_group m_thrds;
- std::deque<IThreadPoolMsg *> m_input;
- std::deque<IThreadPoolMsg *> m_output;
+ std::deque<IThreadPoolMsg *> m_input;
+ std::deque<IThreadPoolMsg *> m_output;
- boost::mutex m_mutex_input_data;
- boost::condition m_cond_input_data;
- boost::mutex m_mutex_output_data;
- bool m_stop_flag;
-};
+ boost::mutex m_mutex_input_data;
+ boost::condition m_cond_input_data;
+ boost::mutex m_mutex_output_data;
+ bool m_stop_flag;
+
+ };
+}
#endif
/*
* Local variables: