annotate DEPENDENCIES/generic/include/boost/signals2/detail/lwm_win32_cs.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // boost/signals2/detail/lwm_win32_cs.hpp
Chris@16 3 //
Chris@16 4 // Copyright (c) 2002, 2003 Peter Dimov
Chris@16 5 // Copyright (c) 2008 Frank Mori Hess
Chris@101 6 // Copyright (c) Microsoft Corporation 2014
Chris@16 7 //
Chris@16 8 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 9 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 10 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 11 //
Chris@16 12
Chris@16 13 #ifndef BOOST_SIGNALS2_LWM_WIN32_CS_HPP
Chris@16 14 #define BOOST_SIGNALS2_LWM_WIN32_CS_HPP
Chris@16 15
Chris@16 16 // MS compatible compilers support #pragma once
Chris@16 17
Chris@101 18 #if defined(_MSC_VER)
Chris@16 19 # pragma once
Chris@16 20 #endif
Chris@16 21
Chris@16 22 #include <boost/assert.hpp>
Chris@16 23
Chris@16 24 #ifdef BOOST_USE_WINDOWS_H
Chris@16 25 # include <windows.h>
Chris@16 26 #endif
Chris@16 27
Chris@101 28 #include <boost/predef/platform.h>
Chris@101 29
Chris@16 30 namespace boost
Chris@16 31 {
Chris@16 32
Chris@16 33 namespace signals2
Chris@16 34 {
Chris@16 35
Chris@16 36 #ifndef BOOST_USE_WINDOWS_H
Chris@16 37
Chris@16 38 struct critical_section
Chris@16 39 {
Chris@16 40 struct critical_section_debug * DebugInfo;
Chris@16 41 long LockCount;
Chris@16 42 long RecursionCount;
Chris@16 43 void * OwningThread;
Chris@16 44 void * LockSemaphore;
Chris@16 45 #if defined(_WIN64)
Chris@16 46 unsigned __int64 SpinCount;
Chris@16 47 #else
Chris@16 48 unsigned long SpinCount;
Chris@16 49 #endif
Chris@16 50 };
Chris@16 51
Chris@101 52 #if BOOST_PLAT_WINDOWS_RUNTIME
Chris@101 53 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSectionEx(critical_section *, unsigned long, unsigned long);
Chris@101 54 #else
Chris@16 55 extern "C" __declspec(dllimport) void __stdcall InitializeCriticalSection(critical_section *);
Chris@101 56 #endif
Chris@16 57 extern "C" __declspec(dllimport) void __stdcall EnterCriticalSection(critical_section *);
Chris@16 58 extern "C" __declspec(dllimport) bool __stdcall TryEnterCriticalSection(critical_section *);
Chris@16 59 extern "C" __declspec(dllimport) void __stdcall LeaveCriticalSection(critical_section *);
Chris@16 60 extern "C" __declspec(dllimport) void __stdcall DeleteCriticalSection(critical_section *);
Chris@16 61
Chris@16 62 #else
Chris@16 63
Chris@16 64 typedef ::CRITICAL_SECTION critical_section;
Chris@16 65
Chris@16 66 #endif // #ifndef BOOST_USE_WINDOWS_H
Chris@16 67
Chris@16 68 class mutex
Chris@16 69 {
Chris@16 70 private:
Chris@16 71
Chris@16 72 critical_section cs_;
Chris@16 73
Chris@16 74 mutex(mutex const &);
Chris@16 75 mutex & operator=(mutex const &);
Chris@16 76
Chris@16 77 public:
Chris@16 78
Chris@16 79 mutex()
Chris@16 80 {
Chris@101 81 #if BOOST_PLAT_WINDOWS_RUNTIME
Chris@101 82 InitializeCriticalSectionEx(&cs_, 4000, 0);
Chris@101 83 #else
Chris@16 84 InitializeCriticalSection(&cs_);
Chris@101 85 #endif
Chris@16 86 }
Chris@16 87
Chris@16 88 ~mutex()
Chris@16 89 {
Chris@16 90 DeleteCriticalSection(&cs_);
Chris@16 91 }
Chris@16 92
Chris@16 93 void lock()
Chris@16 94 {
Chris@16 95 EnterCriticalSection(&cs_);
Chris@16 96 }
Chris@16 97 // TryEnterCriticalSection only exists on Windows NT 4.0 and later
Chris@16 98 #if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0400))
Chris@16 99 bool try_lock()
Chris@16 100 {
Chris@16 101 return TryEnterCriticalSection(&cs_) != 0;
Chris@16 102 }
Chris@16 103 #else
Chris@16 104 bool try_lock()
Chris@16 105 {
Chris@16 106 BOOST_ASSERT(false);
Chris@16 107 return false;
Chris@16 108 }
Chris@16 109 #endif
Chris@16 110 void unlock()
Chris@16 111 {
Chris@16 112 LeaveCriticalSection(&cs_);
Chris@16 113 }
Chris@16 114 };
Chris@16 115
Chris@16 116 } // namespace signals2
Chris@16 117
Chris@16 118 } // namespace boost
Chris@16 119
Chris@16 120 #endif // #ifndef BOOST_SIGNALS2_LWM_WIN32_CS_HPP