1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_HPP
12 #define BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
25 #include <boost/interprocess/sync/posix/semaphore_wrapper.hpp>
28 namespace interprocess {
30 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
31 namespace ipcdetail{ class interprocess_tester; }
32 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
36 class posix_named_semaphore
38 posix_named_semaphore();
39 posix_named_semaphore(const posix_named_semaphore&);
40 posix_named_semaphore &operator= (const posix_named_semaphore &);
44 (create_only_t, const char *name, unsigned int initialCount, const permissions &perm = permissions())
45 { semaphore_open(mp_sem, DoCreate, name, initialCount, perm); }
47 posix_named_semaphore(open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm = permissions())
48 { semaphore_open(mp_sem, DoOpenOrCreate, name, initialCount, perm); }
50 posix_named_semaphore(open_only_t, const char *name)
51 { semaphore_open(mp_sem, DoOpen, name); }
53 ~posix_named_semaphore()
55 if(mp_sem != BOOST_INTERPROCESS_POSIX_SEM_FAILED)
56 semaphore_close(mp_sem);
60 { semaphore_post(mp_sem); }
63 { semaphore_wait(mp_sem); }
66 { return semaphore_try_wait(mp_sem); }
68 bool timed_wait(const boost::posix_time::ptime &abs_time)
69 { return semaphore_timed_wait(mp_sem, abs_time); }
71 static bool remove(const char *name)
72 { return semaphore_unlink(name); }
75 friend class ipcdetail::interprocess_tester;
76 void dont_close_on_destruction()
77 { mp_sem = BOOST_INTERPROCESS_POSIX_SEM_FAILED; }
82 } //namespace ipcdetail {
83 } //namespace interprocess {
86 #include <boost/interprocess/detail/config_end.hpp>
88 #endif //#ifndef BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_HPP