Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-19 08:09:35

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_NAMED_CONDITION_HPP
0012 #define BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_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 
0026 #include <boost/interprocess/sync/posix/semaphore_wrapper.hpp>
0027 
0028 namespace boost {
0029 namespace interprocess {
0030 
0031 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0032 namespace ipcdetail{ class interprocess_tester; }
0033 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0034 
0035 namespace ipcdetail {
0036 
0037 class posix_named_semaphore
0038 {
0039    posix_named_semaphore();
0040    posix_named_semaphore(const posix_named_semaphore&);
0041    posix_named_semaphore &operator= (const posix_named_semaphore &);
0042 
0043    public:
0044    posix_named_semaphore
0045       (create_only_t, const char *name, unsigned int initialCount, const permissions &perm = permissions())
0046    {  semaphore_open(mp_sem, DoCreate, name, initialCount, perm);   }
0047 
0048    posix_named_semaphore(open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm = permissions())
0049    {  semaphore_open(mp_sem, DoOpenOrCreate, name, initialCount, perm);   }
0050 
0051    posix_named_semaphore(open_only_t, const char *name)
0052    {  semaphore_open(mp_sem, DoOpen, name);   }
0053 
0054    ~posix_named_semaphore()
0055    {
0056       if(mp_sem != BOOST_INTERPROCESS_POSIX_SEM_FAILED)
0057          semaphore_close(mp_sem);
0058    }
0059 
0060    void post()
0061    {  semaphore_post(mp_sem); }
0062 
0063    void wait()
0064    {  semaphore_wait(mp_sem); }
0065 
0066    bool try_wait()
0067    {  return semaphore_try_wait(mp_sem); }
0068 
0069    template<class TimePoint>
0070    bool timed_wait(const TimePoint &abs_time)
0071    {  return semaphore_timed_wait(mp_sem, abs_time); }
0072 
0073    static bool remove(const char *name)
0074    {  return semaphore_unlink(name);   }
0075 
0076    private:
0077    friend class ipcdetail::interprocess_tester;
0078    void dont_close_on_destruction()
0079    {  mp_sem = BOOST_INTERPROCESS_POSIX_SEM_FAILED; }
0080 
0081    sem_t      *mp_sem;
0082 };
0083 
0084 }  //namespace ipcdetail {
0085 }  //namespace interprocess {
0086 }  //namespace boost {
0087 
0088 #include <boost/interprocess/detail/config_end.hpp>
0089 
0090 #endif   //#ifndef BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_HPP