Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-30 08:04:59

0001  //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTERPROCESS_SHM_NAMED_SEMAPHORE_HPP
0012 #define BOOST_INTERPROCESS_SHM_NAMED_SEMAPHORE_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 0018 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 #  pragma once
0021 #endif
0022 
0023 #include <boost/interprocess/detail/config_begin.hpp>
0024 #include <boost/interprocess/detail/workaround.hpp>
0025 #include <boost/interprocess/creation_tags.hpp>
0026 #include <boost/interprocess/exceptions.hpp>
0027 #include <boost/interprocess/permissions.hpp>
0028 #include <boost/interprocess/detail/interprocess_tester.hpp>
0029 #include <boost/interprocess/shared_memory_object.hpp>
0030 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
0031 #include <boost/interprocess/sync/interprocess_semaphore.hpp>
0032 #include <boost/interprocess/sync/shm/named_creation_functor.hpp>
0033 
0034 namespace boost {
0035 namespace interprocess {
0036 namespace ipcdetail {
0037 
0038 class shm_named_semaphore
0039 {
0040    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0041 
0042    //Non-copyable
0043    shm_named_semaphore();
0044    shm_named_semaphore(const shm_named_semaphore &);
0045    shm_named_semaphore &operator=(const shm_named_semaphore &);
0046    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0047 
0048    public:
0049    shm_named_semaphore(create_only_t, const char *name, unsigned int initialCount, const permissions &perm = permissions());
0050 
0051    shm_named_semaphore(open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm = permissions());
0052 
0053    shm_named_semaphore(open_only_t, const char *name);
0054 
0055    #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0056 
0057    shm_named_semaphore(create_only_t, const wchar_t *name, unsigned int initialCount, const permissions &perm = permissions());
0058 
0059    shm_named_semaphore(open_or_create_t, const wchar_t *name, unsigned int initialCount, const permissions &perm = permissions());
0060 
0061    shm_named_semaphore(open_only_t, const wchar_t *name);
0062 
0063    #endif   //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0064 
0065    ~shm_named_semaphore();
0066 
0067    void post();
0068    void wait();
0069    bool try_wait();
0070    template<class TimePoint> bool timed_wait(const TimePoint &abs_time);
0071 
0072    static bool remove(const char *name);
0073 
0074    #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0075 
0076    static bool remove(const wchar_t *name);
0077 
0078    #endif
0079 
0080    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0081    private:
0082    friend class interprocess_tester;
0083    void dont_close_on_destruction();
0084 
0085    interprocess_semaphore *semaphore() const
0086    {  return static_cast<interprocess_semaphore*>(m_shmem.get_user_address()); }
0087 
0088    typedef ipcdetail::managed_open_or_create_impl<shared_memory_object, 0, true, false> open_create_impl_t;
0089    open_create_impl_t m_shmem;
0090    typedef named_creation_functor<interprocess_semaphore, unsigned> construct_func_t;
0091    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0092 };
0093 
0094 inline shm_named_semaphore::~shm_named_semaphore()
0095 {}
0096 
0097 inline void shm_named_semaphore::dont_close_on_destruction()
0098 {  interprocess_tester::dont_close_on_destruction(m_shmem);  }
0099 
0100 inline shm_named_semaphore::shm_named_semaphore
0101    (create_only_t, const char *name, unsigned int initialCount, const permissions &perm)
0102    :  m_shmem  (create_only
0103                ,name
0104                ,sizeof(interprocess_semaphore) +
0105                   open_create_impl_t::ManagedOpenOrCreateUserOffset
0106                ,read_write
0107                ,0
0108                ,construct_func_t(DoCreate, initialCount)
0109                ,perm)
0110 {}
0111 
0112 inline shm_named_semaphore::shm_named_semaphore
0113    (open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm)
0114    :  m_shmem  (open_or_create
0115                ,name
0116                ,sizeof(interprocess_semaphore) +
0117                   open_create_impl_t::ManagedOpenOrCreateUserOffset
0118                ,read_write
0119                ,0
0120                ,construct_func_t(DoOpenOrCreate, initialCount)
0121                ,perm)
0122 {}
0123 
0124 inline shm_named_semaphore::shm_named_semaphore
0125    (open_only_t, const char *name)
0126    :  m_shmem  (open_only
0127                ,name
0128                ,read_write
0129                ,0
0130                ,construct_func_t(DoOpen, 0))
0131 {}
0132 
0133 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0134 
0135 inline shm_named_semaphore::shm_named_semaphore
0136    (create_only_t, const wchar_t *name, unsigned int initialCount, const permissions &perm)
0137    :  m_shmem  (create_only
0138                ,name
0139                ,sizeof(interprocess_semaphore) +
0140                   open_create_impl_t::ManagedOpenOrCreateUserOffset
0141                ,read_write
0142                ,0
0143                ,construct_func_t(DoCreate, initialCount)
0144                ,perm)
0145 {}
0146 
0147 inline shm_named_semaphore::shm_named_semaphore
0148    (open_or_create_t, const wchar_t *name, unsigned int initialCount, const permissions &perm)
0149    :  m_shmem  (open_or_create
0150                ,name
0151                ,sizeof(interprocess_semaphore) +
0152                   open_create_impl_t::ManagedOpenOrCreateUserOffset
0153                ,read_write
0154                ,0
0155                ,construct_func_t(DoOpenOrCreate, initialCount)
0156                ,perm)
0157 {}
0158 
0159 inline shm_named_semaphore::shm_named_semaphore
0160    (open_only_t, const wchar_t *name)
0161    :  m_shmem  (open_only
0162                ,name
0163                ,read_write
0164                ,0
0165                ,construct_func_t(DoOpen, 0))
0166 {}
0167 
0168 #endif   //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0169 
0170 inline void shm_named_semaphore::post()
0171 {  semaphore()->post();   }
0172 
0173 inline void shm_named_semaphore::wait()
0174 {  semaphore()->wait();   }
0175 
0176 inline bool shm_named_semaphore::try_wait()
0177 {  return semaphore()->try_wait();   }
0178 
0179 template<class TimePoint>
0180 inline bool shm_named_semaphore::timed_wait(const TimePoint &abs_time)
0181 {  return semaphore()->timed_wait(abs_time); }
0182 
0183 inline bool shm_named_semaphore::remove(const char *name)
0184 {  return shared_memory_object::remove(name); }
0185 
0186 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0187 
0188 inline bool shm_named_semaphore::remove(const wchar_t *name)
0189 {  return shared_memory_object::remove(name); }
0190 
0191 #endif
0192 
0193 }  //namespace ipcdetail {
0194 }  //namespace interprocess {
0195 }  //namespace boost {
0196 
0197 #include <boost/interprocess/detail/config_end.hpp>
0198 
0199 #endif   //BOOST_INTERPROCESS_SHM_NAMED_SEMAPHORE_HPP