Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:42

0001 //
0002 // detail/posix_mutex.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_POSIX_MUTEX_HPP
0012 #define BOOST_ASIO_DETAIL_POSIX_MUTEX_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #if defined(BOOST_ASIO_HAS_PTHREADS)
0021 
0022 #include <pthread.h>
0023 #include <boost/asio/detail/noncopyable.hpp>
0024 #include <boost/asio/detail/scoped_lock.hpp>
0025 
0026 #include <boost/asio/detail/push_options.hpp>
0027 
0028 namespace boost {
0029 namespace asio {
0030 namespace detail {
0031 
0032 class posix_event;
0033 
0034 class posix_mutex
0035   : private noncopyable
0036 {
0037 public:
0038   typedef boost::asio::detail::scoped_lock<posix_mutex> scoped_lock;
0039 
0040   // Constructor.
0041   BOOST_ASIO_DECL posix_mutex();
0042 
0043   // Destructor.
0044   ~posix_mutex()
0045   {
0046     ::pthread_mutex_destroy(&mutex_); // Ignore EBUSY.
0047   }
0048 
0049   // Lock the mutex.
0050   void lock()
0051   {
0052     (void)::pthread_mutex_lock(&mutex_); // Ignore EINVAL.
0053   }
0054 
0055   // Unlock the mutex.
0056   void unlock()
0057   {
0058     (void)::pthread_mutex_unlock(&mutex_); // Ignore EINVAL.
0059   }
0060 
0061 private:
0062   friend class posix_event;
0063   ::pthread_mutex_t mutex_;
0064 };
0065 
0066 } // namespace detail
0067 } // namespace asio
0068 } // namespace boost
0069 
0070 #include <boost/asio/detail/pop_options.hpp>
0071 
0072 #if defined(BOOST_ASIO_HEADER_ONLY)
0073 # include <boost/asio/detail/impl/posix_mutex.ipp>
0074 #endif // defined(BOOST_ASIO_HEADER_ONLY)
0075 
0076 #endif // defined(BOOST_ASIO_HAS_PTHREADS)
0077 
0078 #endif // BOOST_ASIO_DETAIL_POSIX_MUTEX_HPP