Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:13

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2018-2018. 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 //
0012 // This code is partially based on the lightweight mutex implemented
0013 // by Boost.SmartPtr:
0014 //
0015 //  Copyright (c) 2002, 2003 Peter Dimov
0016 //  Copyright (c) Microsoft Corporation 2014
0017 //
0018 // Distributed under the Boost Software License, Version 1.0. (See
0019 // accompanying file LICENSE_1_0.txt or copy at
0020 // http://www.boost.org/LICENSE_1_0.txt)
0021 //
0022 //////////////////////////////////////////////////////////////////////////////
0023 
0024 #ifndef BOOST_CONFIG_HPP
0025 #  include <boost/config.hpp>
0026 #endif
0027 #
0028 #if defined(BOOST_HAS_PRAGMA_ONCE)
0029 #  pragma once
0030 #endif
0031 
0032 #ifndef BOOST_CONTAINER_DETAIL_THREAD_MUTEX_HPP
0033 #define BOOST_CONTAINER_DETAIL_THREAD_MUTEX_HPP
0034 
0035 #include <boost/container/detail/config_begin.hpp>
0036 #include <boost/container/detail/workaround.hpp>
0037 
0038 #if defined(BOOST_HAS_PTHREADS)
0039 
0040 #include <pthread.h>
0041 #include <boost/assert.hpp>
0042 
0043 namespace boost{
0044 namespace container {
0045 namespace dtl {
0046 
0047 class thread_mutex
0048 {
0049    public:
0050    thread_mutex()
0051    {
0052       BOOST_VERIFY(pthread_mutex_init(&m_mut, 0) == 0);
0053    }
0054 
0055    ~thread_mutex()
0056    {
0057      BOOST_VERIFY(pthread_mutex_destroy(&m_mut) == 0);
0058    }
0059 
0060    void lock()
0061    {
0062       BOOST_VERIFY(pthread_mutex_lock( &m_mut) == 0);
0063    }
0064 
0065    void unlock()
0066    {
0067       BOOST_VERIFY(pthread_mutex_unlock(&m_mut) == 0);
0068    }
0069 
0070    private:
0071    thread_mutex(thread_mutex const &);
0072    thread_mutex & operator=(thread_mutex const &);
0073    
0074    pthread_mutex_t m_mut;
0075 };
0076 
0077 } // namespace dtl {
0078 } // namespace container {
0079 } // namespace boost {
0080 
0081 #else //!BOOST_HAS_PTHREADS (Windows implementation)
0082 
0083 #ifdef BOOST_USE_WINDOWS_H
0084 
0085 #include <windows.h>
0086 
0087 namespace boost{
0088 namespace container {
0089 namespace dtl {
0090 
0091 typedef ::CRITICAL_SECTION win_critical_section;
0092 
0093 } // namespace dtl {
0094 } // namespace container {
0095 } // namespace boost {
0096 
0097 #else //! BOOST_USE_WINDOWS_H
0098 
0099 struct _RTL_CRITICAL_SECTION_DEBUG;
0100 struct _RTL_CRITICAL_SECTION;
0101    
0102 namespace boost{
0103 namespace container {
0104 namespace dtl {
0105 
0106 #ifdef BOOST_PLAT_WINDOWS_UWP
0107 extern "C" __declspec(dllimport) int __stdcall InitializeCriticalSectionEx(::_RTL_CRITICAL_SECTION *, unsigned long, unsigned long);
0108 #else
0109 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(::_RTL_CRITICAL_SECTION *);
0110 #endif
0111 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(::_RTL_CRITICAL_SECTION *);
0112 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(::_RTL_CRITICAL_SECTION *);
0113 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(::_RTL_CRITICAL_SECTION *);
0114 
0115 struct win_critical_section
0116 {
0117    struct _RTL_CRITICAL_SECTION_DEBUG * DebugInfo;
0118    long LockCount;
0119    long RecursionCount;
0120    void * OwningThread;
0121    void * LockSemaphore;
0122    #if defined(_WIN64)
0123    unsigned __int64 SpinCount;
0124    #else
0125    unsigned long SpinCount;
0126    #endif
0127 };
0128 
0129 } // namespace dtl {
0130 } // namespace container {
0131 } // namespace boost {
0132 
0133 #endif   //BOOST_USE_WINDOWS_H
0134 
0135 namespace boost{
0136 namespace container {
0137 namespace dtl {
0138 
0139 class thread_mutex
0140 {
0141    public:
0142    thread_mutex()
0143    {
0144       #ifdef BOOST_PLAT_WINDOWS_UWP
0145       (InitializeCriticalSectionEx)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect), 4000, 0);
0146       #else
0147       (InitializeCriticalSection)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect));
0148       #endif
0149    }
0150 
0151    void lock()
0152    {
0153       (EnterCriticalSection)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect));
0154    }
0155 
0156    void unlock()
0157    {
0158       (LeaveCriticalSection)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect));
0159    }
0160 
0161    ~thread_mutex()
0162    {
0163       (DeleteCriticalSection)(reinterpret_cast< ::_RTL_CRITICAL_SECTION* >(&m_crit_sect));
0164    }
0165   
0166    private:
0167    thread_mutex(thread_mutex const &);
0168    thread_mutex & operator=(thread_mutex const &);
0169    
0170    win_critical_section m_crit_sect;
0171 };
0172 
0173 } // namespace dtl {
0174 } // namespace container {
0175 } // namespace boost {
0176 
0177 #endif   //BOOST_HAS_PTHREADS
0178 
0179 #include <boost/container/detail/config_end.hpp>
0180 
0181 #endif // #ifndef BOOST_CONTAINER_DETAIL_THREAD_MUTEX_HPP