File indexing completed on 2025-01-18 09:38:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_SHM_NAMED_CONDITION_ANY_HPP
0012 #define BOOST_INTERPROCESS_SHM_NAMED_CONDITION_ANY_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024
0025 #include <boost/interprocess/sync/cv_status.hpp>
0026 #include <boost/static_assert.hpp>
0027 #include <boost/interprocess/detail/type_traits.hpp>
0028 #include <boost/interprocess/creation_tags.hpp>
0029 #include <boost/interprocess/exceptions.hpp>
0030 #include <boost/interprocess/shared_memory_object.hpp>
0031 #include <boost/interprocess/sync/interprocess_condition.hpp>
0032 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
0033 #include <boost/interprocess/sync/shm/named_creation_functor.hpp>
0034 #include <boost/interprocess/sync/named_mutex.hpp>
0035 #include <boost/interprocess/permissions.hpp>
0036 #include <boost/interprocess/sync/interprocess_mutex.hpp>
0037 #include <boost/interprocess/sync/scoped_lock.hpp>
0038 #include <boost/interprocess/sync/detail/condition_any_algorithm.hpp>
0039
0040
0041
0042
0043 namespace boost {
0044 namespace interprocess {
0045 namespace ipcdetail {
0046
0047 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0048 class interprocess_tester;
0049 #endif
0050
0051
0052
0053
0054 class shm_named_condition_any
0055 {
0056 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0057
0058 shm_named_condition_any();
0059 shm_named_condition_any(const shm_named_condition_any &);
0060 shm_named_condition_any &operator=(const shm_named_condition_any &);
0061 #endif
0062 public:
0063
0064
0065 template <class CharT>
0066 shm_named_condition_any(create_only_t, const CharT *name, const permissions &perm = permissions())
0067 : m_shmem (create_only_t()
0068 ,name
0069 ,sizeof(internal_condition) +
0070 open_create_impl_t::ManagedOpenOrCreateUserOffset
0071 ,read_write
0072 ,0
0073 ,construct_func_t(DoCreate)
0074 ,perm)
0075 {}
0076
0077
0078
0079
0080
0081
0082
0083 template <class CharT>
0084 shm_named_condition_any(open_or_create_t, const CharT *name, const permissions &perm = permissions())
0085 : m_shmem (open_or_create_t()
0086 ,name
0087 ,sizeof(internal_condition) +
0088 open_create_impl_t::ManagedOpenOrCreateUserOffset
0089 ,read_write
0090 ,0
0091 ,construct_func_t(DoOpenOrCreate)
0092 ,perm)
0093 {}
0094
0095
0096
0097
0098 template <class CharT>
0099 shm_named_condition_any(open_only_t, const CharT *name)
0100 : m_shmem (open_only_t()
0101 ,name
0102 ,read_write
0103 ,0
0104 ,construct_func_t(DoOpen))
0105 {}
0106
0107
0108
0109
0110
0111
0112
0113 ~shm_named_condition_any()
0114 {}
0115
0116
0117
0118 void notify_one()
0119 { this->internal_cond().notify_one(); }
0120
0121
0122
0123 void notify_all()
0124 { this->internal_cond().notify_all(); }
0125
0126
0127
0128
0129 template <typename L>
0130 void wait(L& lock)
0131 { this->internal_cond().wait(lock); }
0132
0133
0134
0135 template <typename L, typename Pr>
0136 void wait(L& lock, Pr pred)
0137 { this->internal_cond().wait(lock, pred); }
0138
0139
0140
0141
0142
0143
0144 template <typename L, typename TimePoint>
0145 bool timed_wait(L& lock, const TimePoint &abs_time)
0146 { return this->internal_cond().timed_wait(lock, abs_time); }
0147
0148
0149
0150
0151 template <typename L, typename TimePoint, typename Pr>
0152 bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred)
0153 { return this->internal_cond().timed_wait(lock, abs_time, pred); }
0154
0155
0156
0157 template <typename L, class TimePoint>
0158 cv_status wait_until(L& lock, const TimePoint &abs_time)
0159 { return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
0160
0161
0162
0163 template <typename L, class TimePoint, typename Pr>
0164 bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
0165 { return this->timed_wait(lock, abs_time, pred); }
0166
0167
0168
0169 template <typename L, class Duration>
0170 cv_status wait_for(L& lock, const Duration &dur)
0171 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur)); }
0172
0173
0174
0175 template <typename L, class Duration, typename Pr>
0176 bool wait_for(L& lock, const Duration &dur, Pr pred)
0177 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur), pred); }
0178
0179
0180
0181 template <class CharT>
0182 static bool remove(const CharT *name)
0183 { return shared_memory_object::remove(name); }
0184
0185 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0186 private:
0187
0188 class internal_condition_members
0189 {
0190 public:
0191 typedef interprocess_mutex mutex_type;
0192 typedef interprocess_condition condvar_type;
0193
0194 condvar_type& get_condvar() { return m_cond; }
0195 mutex_type& get_mutex() { return m_mtx; }
0196
0197 private:
0198 mutex_type m_mtx;
0199 condvar_type m_cond;
0200 };
0201
0202 typedef ipcdetail::condition_any_wrapper<internal_condition_members> internal_condition;
0203
0204 internal_condition &internal_cond()
0205 { return *static_cast<internal_condition*>(m_shmem.get_user_address()); }
0206
0207 friend class boost::interprocess::ipcdetail::interprocess_tester;
0208 void dont_close_on_destruction()
0209 { interprocess_tester::dont_close_on_destruction(m_shmem); }
0210
0211 typedef ipcdetail::managed_open_or_create_impl<shared_memory_object, 0, true, false> open_create_impl_t;
0212 open_create_impl_t m_shmem;
0213
0214 template <class T, class Arg> friend class boost::interprocess::ipcdetail::named_creation_functor;
0215 typedef boost::interprocess::ipcdetail::named_creation_functor<internal_condition> construct_func_t;
0216 #endif
0217 };
0218
0219 }
0220 }
0221 }
0222
0223 #include <boost/interprocess/detail/config_end.hpp>
0224
0225 #endif