1 ////////////////////////////////////////////////////////////////////////////// 2 // 3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost 4 // Software License, Version 1.0. (See accompanying file 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 // See http://www.boost.org/libs/interprocess for documentation. 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 #ifndef BOOST_INTERPROCESS_POSIX_SEMAPHORE_HPP 12 #define BOOST_INTERPROCESS_POSIX_SEMAPHORE_HPP 13 14 #ifndef BOOST_CONFIG_HPP 15 # include <boost/config.hpp> 16 #endif 17 # 18 #if defined(BOOST_HAS_PRAGMA_ONCE) 19 # pragma once 20 #endif 21 22 #include <boost/interprocess/detail/config_begin.hpp> 23 #include <boost/interprocess/detail/workaround.hpp> 24 25 #include <boost/interprocess/detail/posix_time_types_wrk.hpp> 26 #include <boost/interprocess/sync/posix/semaphore_wrapper.hpp> 27 28 namespace boost { 29 namespace interprocess { 30 namespace ipcdetail { 31 32 class posix_semaphore 33 { 34 posix_semaphore(); 35 posix_semaphore(const posix_semaphore&); 36 posix_semaphore &operator= (const posix_semaphore &); 37 38 public: posix_semaphore(unsigned int initialCount)39 posix_semaphore(unsigned int initialCount) 40 { semaphore_init(&m_sem, initialCount); } 41 ~posix_semaphore()42 ~posix_semaphore() 43 { semaphore_destroy(&m_sem); } 44 post()45 void post() 46 { semaphore_post(&m_sem); } 47 wait()48 void wait() 49 { semaphore_wait(&m_sem); } 50 try_wait()51 bool try_wait() 52 { return semaphore_try_wait(&m_sem); } 53 timed_wait(const boost::posix_time::ptime & abs_time)54 bool timed_wait(const boost::posix_time::ptime &abs_time) 55 { return semaphore_timed_wait(&m_sem, abs_time); } 56 57 private: 58 sem_t m_sem; 59 }; 60 61 } //namespace ipcdetail { 62 } //namespace interprocess { 63 } //namespace boost { 64 65 #include <boost/interprocess/detail/config_end.hpp> 66 67 #endif //#ifndef BOOST_INTERPROCESS_POSIX_SEMAPHORE_HPP 68