PageRenderTime 23ms CodeModel.GetById 18ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/asio/detail/posix_event.hpp

http://hadesmem.googlecode.com/
C++ Header | 100 lines | 66 code | 19 blank | 15 comment | 3 complexity | 1b98be9a545aaf532b31ac2aed169460 MD5 | raw file
  1//
  2// detail/posix_event.hpp
  3// ~~~~~~~~~~~~~~~~~~~~~~
  4//
  5// Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6//
  7// Distributed under the Boost Software License, Version 1.0. (See accompanying
  8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9//
 10
 11#ifndef BOOST_ASIO_DETAIL_POSIX_EVENT_HPP
 12#define BOOST_ASIO_DETAIL_POSIX_EVENT_HPP
 13
 14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
 15# pragma once
 16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
 17
 18#include <boost/asio/detail/config.hpp>
 19
 20#if defined(BOOST_HAS_PTHREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
 21
 22#include <boost/assert.hpp>
 23#include <pthread.h>
 24#include <boost/asio/detail/noncopyable.hpp>
 25
 26#include <boost/asio/detail/push_options.hpp>
 27
 28namespace boost {
 29namespace asio {
 30namespace detail {
 31
 32class posix_event
 33  : private noncopyable
 34{
 35public:
 36  // Constructor.
 37  BOOST_ASIO_DECL posix_event();
 38
 39  // Destructor.
 40  ~posix_event()
 41  {
 42    ::pthread_cond_destroy(&cond_);
 43  }
 44
 45  // Signal the event.
 46  template <typename Lock>
 47  void signal(Lock& lock)
 48  {
 49    BOOST_ASSERT(lock.locked());
 50    (void)lock;
 51    signalled_ = true;
 52    ::pthread_cond_signal(&cond_); // Ignore EINVAL.
 53  }
 54
 55  // Signal the event and unlock the mutex.
 56  template <typename Lock>
 57  void signal_and_unlock(Lock& lock)
 58  {
 59    BOOST_ASSERT(lock.locked());
 60    signalled_ = true;
 61    lock.unlock();
 62    ::pthread_cond_signal(&cond_); // Ignore EINVAL.
 63  }
 64
 65  // Reset the event.
 66  template <typename Lock>
 67  void clear(Lock& lock)
 68  {
 69    BOOST_ASSERT(lock.locked());
 70    (void)lock;
 71    signalled_ = false;
 72  }
 73
 74  // Wait for the event to become signalled.
 75  template <typename Lock>
 76  void wait(Lock& lock)
 77  {
 78    BOOST_ASSERT(lock.locked());
 79    while (!signalled_)
 80      ::pthread_cond_wait(&cond_, &lock.mutex().mutex_); // Ignore EINVAL.
 81  }
 82
 83private:
 84  ::pthread_cond_t cond_;
 85  bool signalled_;
 86};
 87
 88} // namespace detail
 89} // namespace asio
 90} // namespace boost
 91
 92#include <boost/asio/detail/pop_options.hpp>
 93
 94#if defined(BOOST_ASIO_HEADER_ONLY)
 95# include <boost/asio/detail/impl/posix_event.ipp>
 96#endif // defined(BOOST_ASIO_HEADER_ONLY)
 97
 98#endif // defined(BOOST_HAS_PTHREADS) && !defined(BOOST_ASIO_DISABLE_THREADS)
 99
100#endif // BOOST_ASIO_DETAIL_POSIX_EVENT_HPP