00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #pragma once
00022
00023 #include <boost/thread/mutex.hpp>
00024 #include <boost/thread/condition_variable.hpp>
00025 #include <boost/shared_ptr.hpp>
00026
00027 namespace client {
00028
00029
00030 class Wakeup {
00031 public:
00032 typedef boost::shared_ptr<Wakeup> shared_ptr;
00033
00034 Wakeup() :
00035 sleeping(true)
00036 { }
00037
00038
00039 void start()
00040 {
00041 boost::mutex::scoped_lock scopedWakeup(sleeper_mutex);
00042 sleeping= false;
00043 sleep_threshhold.notify_all();
00044 }
00045
00046
00047 void reset()
00048 {
00049 boost::mutex::scoped_lock scopedWakeup(sleeper_mutex);
00050 sleeping= true;
00051 }
00052
00053 void wait()
00054 {
00055 sleeper_mutex.lock();
00056 while (sleeping)
00057 {
00058 sleep_threshhold.wait(sleeper_mutex);
00059 }
00060 sleeper_mutex.unlock();
00061 }
00062
00063 private:
00064 bool sleeping;
00065 boost::mutex sleeper_mutex;
00066 boost::condition_variable_any sleep_threshhold;
00067 };
00068
00069 }