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