00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_DETAIL_POSIX_EVENT_HPP
00012 #define ASIO_DETAIL_POSIX_EVENT_HPP
00013
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017
00018 #include "asio/detail/push_options.hpp"
00019
00020 #include "asio/detail/push_options.hpp"
00021 #include <boost/config.hpp>
00022 #include "asio/detail/pop_options.hpp"
00023
00024 #if defined(BOOST_HAS_PTHREADS)
00025
00026 #include "asio/detail/push_options.hpp"
00027 #include <boost/throw_exception.hpp>
00028 #include <pthread.h>
00029 #include "asio/detail/pop_options.hpp"
00030
00031 #include "asio/system_error.hpp"
00032 #include "asio/detail/noncopyable.hpp"
00033
00034 namespace asio {
00035 namespace detail {
00036
00037 class posix_event
00038 : private noncopyable
00039 {
00040 public:
00041
00042 posix_event()
00043 : signalled_(false)
00044 {
00045 int error = ::pthread_mutex_init(&mutex_, 0);
00046 if (error != 0)
00047 {
00048 asio::system_error e(
00049 asio::error_code(error, asio::native_ecat),
00050 "event");
00051 boost::throw_exception(e);
00052 }
00053
00054 error = ::pthread_cond_init(&cond_, 0);
00055 if (error != 0)
00056 {
00057 ::pthread_mutex_destroy(&mutex_);
00058 asio::system_error e(
00059 asio::error_code(error, asio::native_ecat),
00060 "event");
00061 boost::throw_exception(e);
00062 }
00063 }
00064
00065
00066 ~posix_event()
00067 {
00068 ::pthread_cond_destroy(&cond_);
00069 ::pthread_mutex_destroy(&mutex_);
00070 }
00071
00072
00073 void signal()
00074 {
00075 ::pthread_mutex_lock(&mutex_);
00076 signalled_ = true;
00077 ::pthread_cond_signal(&cond_);
00078 ::pthread_mutex_unlock(&mutex_);
00079 }
00080
00081
00082 void clear()
00083 {
00084 ::pthread_mutex_lock(&mutex_);
00085 signalled_ = false;
00086 ::pthread_mutex_unlock(&mutex_);
00087 }
00088
00089
00090 void wait()
00091 {
00092 ::pthread_mutex_lock(&mutex_);
00093 while (!signalled_)
00094 ::pthread_cond_wait(&cond_, &mutex_);
00095 ::pthread_mutex_unlock(&mutex_);
00096 }
00097
00098 private:
00099 ::pthread_mutex_t mutex_;
00100 ::pthread_cond_t cond_;
00101 bool signalled_;
00102 };
00103
00104 }
00105 }
00106
00107 #endif // defined(BOOST_HAS_PTHREADS)
00108
00109 #include "asio/detail/pop_options.hpp"
00110
00111 #endif // ASIO_DETAIL_POSIX_EVENT_HPP