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_POSIX_SEMAPHORE_HPP
0012 #define BOOST_INTERPROCESS_POSIX_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 
0025 #include <boost/interprocess/sync/posix/semaphore_wrapper.hpp>
0026 
0027 namespace boost {
0028 namespace interprocess {
0029 namespace ipcdetail {
0030 
0031 class posix_semaphore
0032 {
0033    posix_semaphore();
0034    posix_semaphore(const posix_semaphore&);
0035    posix_semaphore &operator= (const posix_semaphore &);
0036 
0037    public:
0038    posix_semaphore(unsigned int initialCount)
0039    {  semaphore_init(&m_sem, initialCount);  }
0040 
0041    ~posix_semaphore()
0042    {  semaphore_destroy(&m_sem);  }
0043 
0044    void post()
0045    {  semaphore_post(&m_sem); }
0046 
0047    void wait()
0048    {  semaphore_wait(&m_sem); }
0049 
0050    bool try_wait()
0051    {  return semaphore_try_wait(&m_sem); }
0052 
0053    template<class TimePoint>
0054    bool timed_wait(const TimePoint &abs_time)
0055    {  return semaphore_timed_wait(&m_sem, abs_time); }
0056 
0057    private:
0058    sem_t       m_sem;
0059 };
0060 
0061 }  //namespace ipcdetail {
0062 }  //namespace interprocess {
0063 }  //namespace boost {
0064 
0065 #include <boost/interprocess/detail/config_end.hpp>
0066 
0067 #endif   //#ifndef BOOST_INTERPROCESS_POSIX_SEMAPHORE_HPP