Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:31

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