00001 #ifndef _DHT_KADC_SHARED_QUEUE_H_
00002 #define _DHT_KADC_SHARED_QUEUE_H_
00003
00004 #include <ace/Condition_T.h>
00005 #include <ace/Thread_Mutex.h>
00006 #include <queue>
00007
00008 #include "../client.h"
00009 #include "reactor_event_handler.h"
00010
00011 namespace dht {
00012 namespace kadc {
00013 using namespace std;
00014
00015 template <class T>
00016 class shared_queue {
00017 queue<T> _q;
00018 ACE_Thread_Mutex _m;
00019 reactor_event_handler *_target;
00020
00021 public:
00022 shared_queue() {
00023
00024 }
00025 ~shared_queue() {
00026
00027 }
00028
00029 inline reactor_event_handler *target() { return _target; }
00030 inline void target(reactor_event_handler *t) { _target = t; }
00031
00032 inline int acquire() {
00033 return _m.acquire();
00034 }
00035 inline int release() {
00036 return _m.release();
00037 }
00038
00039 inline void signal() {
00040 _target->signal();
00041 }
00042
00043 inline int size() const { return _q.size(); }
00044 inline const T &front() const { return _q.front(); }
00045 inline void push(const T &e) { _q.push(e); }
00046 inline void pop() { _q.pop(); }
00047 };
00048 }
00049 }
00050
00051 #endif //_DHT_KADC_SHARED_QUEUE_H_