]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/interprocess/include/boost/interprocess/sync/shm/named_semaphore.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / interprocess / include / boost / interprocess / sync / shm / named_semaphore.hpp
CommitLineData
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_SHM_NAMED_SEMAPHORE_HPP
12#define BOOST_INTERPROCESS_SHM_NAMED_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#include <boost/interprocess/creation_tags.hpp>
25#include <boost/interprocess/exceptions.hpp>
26#include <boost/interprocess/permissions.hpp>
27#include <boost/interprocess/detail/interprocess_tester.hpp>
28#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
29#include <boost/interprocess/shared_memory_object.hpp>
30#include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
31#include <boost/interprocess/sync/interprocess_semaphore.hpp>
32#include <boost/interprocess/sync/shm/named_creation_functor.hpp>
33
34namespace boost {
35namespace interprocess {
36namespace ipcdetail {
37
38class shm_named_semaphore
39{
40 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
41
42 //Non-copyable
43 shm_named_semaphore();
44 shm_named_semaphore(const shm_named_semaphore &);
45 shm_named_semaphore &operator=(const shm_named_semaphore &);
46 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
47
48 public:
49 shm_named_semaphore(create_only_t, const char *name, unsigned int initialCount, const permissions &perm = permissions());
50
51 shm_named_semaphore(open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm = permissions());
52
53 shm_named_semaphore(open_only_t, const char *name);
54
55 ~shm_named_semaphore();
56
57 void post();
58 void wait();
59 bool try_wait();
60 bool timed_wait(const boost::posix_time::ptime &abs_time);
61
62 static bool remove(const char *name);
63
64 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
65 private:
66 friend class interprocess_tester;
67 void dont_close_on_destruction();
68
69 interprocess_semaphore *semaphore() const
70 { return static_cast<interprocess_semaphore*>(m_shmem.get_user_address()); }
71
72 typedef ipcdetail::managed_open_or_create_impl<shared_memory_object, 0, true, false> open_create_impl_t;
73 open_create_impl_t m_shmem;
74 typedef named_creation_functor<interprocess_semaphore, int> construct_func_t;
75 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
76};
77
78inline shm_named_semaphore::~shm_named_semaphore()
79{}
80
81inline void shm_named_semaphore::dont_close_on_destruction()
82{ interprocess_tester::dont_close_on_destruction(m_shmem); }
83
84inline shm_named_semaphore::shm_named_semaphore
85 (create_only_t, const char *name, unsigned int initialCount, const permissions &perm)
86 : m_shmem (create_only
87 ,name
88 ,sizeof(interprocess_semaphore) +
89 open_create_impl_t::ManagedOpenOrCreateUserOffset
90 ,read_write
91 ,0
92 ,construct_func_t(DoCreate, initialCount)
93 ,perm)
94{}
95
96inline shm_named_semaphore::shm_named_semaphore
97 (open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm)
98 : m_shmem (open_or_create
99 ,name
100 ,sizeof(interprocess_semaphore) +
101 open_create_impl_t::ManagedOpenOrCreateUserOffset
102 ,read_write
103 ,0
104 ,construct_func_t(DoOpenOrCreate, initialCount)
105 ,perm)
106{}
107
108inline shm_named_semaphore::shm_named_semaphore
109 (open_only_t, const char *name)
110 : m_shmem (open_only
111 ,name
112 ,read_write
113 ,0
114 ,construct_func_t(DoOpen, 0))
115{}
116
117inline void shm_named_semaphore::post()
118{ semaphore()->post(); }
119
120inline void shm_named_semaphore::wait()
121{ semaphore()->wait(); }
122
123inline bool shm_named_semaphore::try_wait()
124{ return semaphore()->try_wait(); }
125
126inline bool shm_named_semaphore::timed_wait(const boost::posix_time::ptime &abs_time)
127{ return semaphore()->timed_wait(abs_time); }
128
129inline bool shm_named_semaphore::remove(const char *name)
130{ return shared_memory_object::remove(name); }
131
132} //namespace ipcdetail {
133} //namespace interprocess {
134} //namespace boost {
135
136#include <boost/interprocess/detail/config_end.hpp>
137
138#endif //BOOST_INTERPROCESS_SHM_NAMED_SEMAPHORE_HPP