]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_NAMED_MUTEX_HPP | |
12 | #define BOOST_INTERPROCESS_POSIX_NAMED_MUTEX_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 | #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> | |
28 | ||
29 | #include <boost/interprocess/sync/posix/named_semaphore.hpp> | |
30 | ||
31 | namespace boost { | |
32 | namespace interprocess { | |
33 | namespace ipcdetail { | |
34 | ||
35 | class named_condition; | |
36 | ||
37 | class posix_named_mutex | |
38 | { | |
39 | #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) | |
40 | ||
41 | posix_named_mutex(); | |
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 | |
46 | ||
47 | public: | |
48 | posix_named_mutex(create_only_t create_only, const char *name, const permissions &perm = permissions()); | |
49 | ||
50 | posix_named_mutex(open_or_create_t open_or_create, const char *name, const permissions &perm = permissions()); | |
51 | ||
52 | posix_named_mutex(open_only_t open_only, const char *name); | |
53 | ||
54 | ~posix_named_mutex(); | |
55 | ||
56 | void unlock(); | |
57 | void lock(); | |
58 | bool try_lock(); | |
59 | bool timed_lock(const boost::posix_time::ptime &abs_time); | |
60 | static bool remove(const char *name); | |
61 | ||
62 | #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) | |
63 | private: | |
64 | friend class interprocess_tester; | |
65 | void dont_close_on_destruction(); | |
66 | ||
67 | posix_named_semaphore m_sem; | |
68 | #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED | |
69 | }; | |
70 | ||
71 | #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) | |
72 | ||
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) | |
75 | {} | |
76 | ||
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) | |
79 | {} | |
80 | ||
81 | inline posix_named_mutex::posix_named_mutex(open_only_t, const char *name) | |
82 | : m_sem(open_only, name) | |
83 | {} | |
84 | ||
85 | inline void posix_named_mutex::dont_close_on_destruction() | |
86 | { interprocess_tester::dont_close_on_destruction(m_sem); } | |
87 | ||
88 | inline posix_named_mutex::~posix_named_mutex() | |
89 | {} | |
90 | ||
91 | inline void posix_named_mutex::lock() | |
92 | { m_sem.wait(); } | |
93 | ||
94 | inline void posix_named_mutex::unlock() | |
95 | { m_sem.post(); } | |
96 | ||
97 | inline bool posix_named_mutex::try_lock() | |
98 | { return m_sem.try_wait(); } | |
99 | ||
100 | inline bool posix_named_mutex::timed_lock(const boost::posix_time::ptime &abs_time) | |
101 | { return m_sem.timed_wait(abs_time); } | |
102 | ||
103 | inline bool posix_named_mutex::remove(const char *name) | |
104 | { return posix_named_semaphore::remove(name); } | |
105 | ||
106 | #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED | |
107 | ||
108 | } //namespace ipcdetail { | |
109 | } //namespace interprocess { | |
110 | } //namespace boost { | |
111 | ||
112 | #include <boost/interprocess/detail/config_end.hpp> | |
113 | ||
114 | #endif //BOOST_INTERPROCESS_POSIX_NAMED_MUTEX_HPP |