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_MUTEX_HPP
12 #define BOOST_INTERPROCESS_POSIX_NAMED_MUTEX_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>
24 #include <boost/interprocess/creation_tags.hpp>
25 #include <boost/interprocess/exceptions.hpp>
26 #include <boost/interprocess/detail/interprocess_tester.hpp>
27 #include <boost/interprocess/permissions.hpp>
29 #include <boost/interprocess/sync/posix/named_semaphore.hpp>
32 namespace interprocess {
35 class named_condition;
37 class posix_named_mutex
39 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
42 posix_named_mutex(const posix_named_mutex &);
43 posix_named_mutex &operator=(const posix_named_mutex &);
44 friend class named_condition;
45 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
48 posix_named_mutex(create_only_t create_only, const char *name, const permissions &perm = permissions());
50 posix_named_mutex(open_or_create_t open_or_create, const char *name, const permissions &perm = permissions());
52 posix_named_mutex(open_only_t open_only, const char *name);
59 bool timed_lock(const boost::posix_time::ptime &abs_time);
60 static bool remove(const char *name);
62 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
64 friend class interprocess_tester;
65 void dont_close_on_destruction();
67 posix_named_semaphore m_sem;
68 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
71 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
73 inline posix_named_mutex::posix_named_mutex(create_only_t, const char *name, const permissions &perm)
74 : m_sem(create_only, name, 1, perm)
77 inline posix_named_mutex::posix_named_mutex(open_or_create_t, const char *name, const permissions &perm)
78 : m_sem(open_or_create, name, 1, perm)
81 inline posix_named_mutex::posix_named_mutex(open_only_t, const char *name)
82 : m_sem(open_only, name)
85 inline void posix_named_mutex::dont_close_on_destruction()
86 { interprocess_tester::dont_close_on_destruction(m_sem); }
88 inline posix_named_mutex::~posix_named_mutex()
91 inline void posix_named_mutex::lock()
94 inline void posix_named_mutex::unlock()
97 inline bool posix_named_mutex::try_lock()
98 { return m_sem.try_wait(); }
100 inline bool posix_named_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
101 { return m_sem.timed_wait(abs_time); }
103 inline bool posix_named_mutex::remove(const char *name)
104 { return posix_named_semaphore::remove(name); }
106 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
108 } //namespace ipcdetail {
109 } //namespace interprocess {
110 } //namespace boost {
112 #include <boost/interprocess/detail/config_end.hpp>
114 #endif //BOOST_INTERPROCESS_POSIX_NAMED_MUTEX_HPP