////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/interprocess for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTERPROCESS_SHM_NAMED_SEMAPHORE_HPP #define BOOST_INTERPROCESS_SHM_NAMED_SEMAPHORE_HPP #if defined(_MSC_VER) # pragma once #endif #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace interprocess { namespace ipcdetail { class shm_named_semaphore { #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) //Non-copyable shm_named_semaphore(); shm_named_semaphore(const shm_named_semaphore &); shm_named_semaphore &operator=(const shm_named_semaphore &); #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED public: shm_named_semaphore(create_only_t, const char *name, unsigned int initialCount, const permissions &perm = permissions()); shm_named_semaphore(open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm = permissions()); shm_named_semaphore(open_only_t, const char *name); ~shm_named_semaphore(); void post(); void wait(); bool try_wait(); bool timed_wait(const boost::posix_time::ptime &abs_time); static bool remove(const char *name); #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) private: friend class interprocess_tester; void dont_close_on_destruction(); interprocess_semaphore *semaphore() const { return static_cast(m_shmem.get_user_address()); } typedef ipcdetail::managed_open_or_create_impl open_create_impl_t; open_create_impl_t m_shmem; typedef named_creation_functor construct_func_t; #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED }; inline shm_named_semaphore::~shm_named_semaphore() {} inline void shm_named_semaphore::dont_close_on_destruction() { interprocess_tester::dont_close_on_destruction(m_shmem); } inline shm_named_semaphore::shm_named_semaphore (create_only_t, const char *name, unsigned int initialCount, const permissions &perm) : m_shmem (create_only ,name ,sizeof(interprocess_semaphore) + open_create_impl_t::ManagedOpenOrCreateUserOffset ,read_write ,0 ,construct_func_t(DoCreate, initialCount) ,perm) {} inline shm_named_semaphore::shm_named_semaphore (open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm) : m_shmem (open_or_create ,name ,sizeof(interprocess_semaphore) + open_create_impl_t::ManagedOpenOrCreateUserOffset ,read_write ,0 ,construct_func_t(DoOpenOrCreate, initialCount) ,perm) {} inline shm_named_semaphore::shm_named_semaphore (open_only_t, const char *name) : m_shmem (open_only ,name ,read_write ,0 ,construct_func_t(DoOpen, 0)) {} inline void shm_named_semaphore::post() { semaphore()->post(); } inline void shm_named_semaphore::wait() { semaphore()->wait(); } inline bool shm_named_semaphore::try_wait() { return semaphore()->try_wait(); } inline bool shm_named_semaphore::timed_wait(const boost::posix_time::ptime &abs_time) { return semaphore()->timed_wait(abs_time); } inline bool shm_named_semaphore::remove(const char *name) { return shared_memory_object::remove(name); } } //namespace ipcdetail { } //namespace interprocess { } //namespace boost { #include #endif //BOOST_INTERPROCESS_SHM_NAMED_SEMAPHORE_HPP