1 /*
2 * Copyright 2010 Vicente J. Botet Escriba
3 * Copyright 2015 Andrey Semashev
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * See http://www.boost.org/LICENSE_1_0.txt
7 */
8
9 #ifndef BOOST_WINAPI_INIT_ONCE_HPP_INCLUDED_
10 #define BOOST_WINAPI_INIT_ONCE_HPP_INCLUDED_
11
12 #include <boost/winapi/config.hpp>
13
14 #ifdef BOOST_HAS_PRAGMA_ONCE
15 #pragma once
16 #endif
17
18 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
19
20 #include <boost/winapi/basic_types.hpp>
21 #include <boost/winapi/detail/header.hpp>
22
23 #if !defined(BOOST_USE_WINDOWS_H)
24 extern "C" {
25 #if defined(BOOST_WINAPI_IS_CYGWIN) || defined(BOOST_WINAPI_IS_MINGW_W64)
26 struct _RTL_RUN_ONCE;
27 #else
28 union _RTL_RUN_ONCE;
29 #endif
30
31 typedef boost::winapi::BOOL_
32 (BOOST_WINAPI_WINAPI_CC *PINIT_ONCE_FN) (
33 ::_RTL_RUN_ONCE* InitOnce,
34 boost::winapi::PVOID_ Parameter,
35 boost::winapi::PVOID_ *Context);
36
37 BOOST_WINAPI_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
38 InitOnceInitialize(::_RTL_RUN_ONCE* InitOnce);
39
40 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
41 InitOnceExecuteOnce(
42 ::_RTL_RUN_ONCE* InitOnce,
43 ::PINIT_ONCE_FN InitFn,
44 boost::winapi::PVOID_ Parameter,
45 boost::winapi::LPVOID_ *Context);
46
47 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
48 InitOnceBeginInitialize(
49 ::_RTL_RUN_ONCE* lpInitOnce,
50 boost::winapi::DWORD_ dwFlags,
51 boost::winapi::PBOOL_ fPending,
52 boost::winapi::LPVOID_ *lpContext);
53
54 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
55 InitOnceComplete(
56 ::_RTL_RUN_ONCE* lpInitOnce,
57 boost::winapi::DWORD_ dwFlags,
58 boost::winapi::LPVOID_ lpContext);
59 }
60 #endif
61
62 namespace boost {
63 namespace winapi {
64
65 typedef union BOOST_MAY_ALIAS _RTL_RUN_ONCE {
66 PVOID_ Ptr;
67 } INIT_ONCE_, *PINIT_ONCE_, *LPINIT_ONCE_;
68
69 extern "C" {
70 typedef BOOL_ (BOOST_WINAPI_WINAPI_CC *PINIT_ONCE_FN_) (PINIT_ONCE_ lpInitOnce, PVOID_ Parameter, PVOID_ *Context);
71 }
72
InitOnceInitialize(PINIT_ONCE_ lpInitOnce)73 BOOST_FORCEINLINE VOID_ InitOnceInitialize(PINIT_ONCE_ lpInitOnce)
74 {
75 ::InitOnceInitialize(reinterpret_cast< ::_RTL_RUN_ONCE* >(lpInitOnce));
76 }
77
InitOnceExecuteOnce(PINIT_ONCE_ lpInitOnce,PINIT_ONCE_FN_ InitFn,PVOID_ Parameter,LPVOID_ * Context)78 BOOST_FORCEINLINE BOOL_ InitOnceExecuteOnce(PINIT_ONCE_ lpInitOnce, PINIT_ONCE_FN_ InitFn, PVOID_ Parameter, LPVOID_ *Context)
79 {
80 return ::InitOnceExecuteOnce(reinterpret_cast< ::_RTL_RUN_ONCE* >(lpInitOnce), reinterpret_cast< ::PINIT_ONCE_FN >(InitFn), Parameter, Context);
81 }
82
InitOnceBeginInitialize(PINIT_ONCE_ lpInitOnce,DWORD_ dwFlags,PBOOL_ fPending,LPVOID_ * lpContext)83 BOOST_FORCEINLINE BOOL_ InitOnceBeginInitialize(PINIT_ONCE_ lpInitOnce, DWORD_ dwFlags, PBOOL_ fPending, LPVOID_ *lpContext)
84 {
85 return ::InitOnceBeginInitialize(reinterpret_cast< ::_RTL_RUN_ONCE* >(lpInitOnce), dwFlags, fPending, lpContext);
86 }
87
InitOnceComplete(PINIT_ONCE_ lpInitOnce,DWORD_ dwFlags,LPVOID_ lpContext)88 BOOST_FORCEINLINE BOOL_ InitOnceComplete(PINIT_ONCE_ lpInitOnce, DWORD_ dwFlags, LPVOID_ lpContext)
89 {
90 return ::InitOnceComplete(reinterpret_cast< ::_RTL_RUN_ONCE* >(lpInitOnce), dwFlags, lpContext);
91 }
92
93 #if defined( BOOST_USE_WINDOWS_H )
94
95 #define BOOST_WINAPI_INIT_ONCE_STATIC_INIT INIT_ONCE_STATIC_INIT
96 BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_ASYNC_ = INIT_ONCE_ASYNC;
97 BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_CHECK_ONLY_ = INIT_ONCE_CHECK_ONLY;
98 BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_INIT_FAILED_ = INIT_ONCE_INIT_FAILED;
99 BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_CTX_RESERVED_BITS_ = INIT_ONCE_CTX_RESERVED_BITS;
100
101 #else // defined( BOOST_USE_WINDOWS_H )
102
103 #define BOOST_WINAPI_INIT_ONCE_STATIC_INIT {0}
104 BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_ASYNC_ = 0x00000002UL;
105 BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_CHECK_ONLY_ = 0x00000001UL;
106 BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_INIT_FAILED_ = 0x00000004UL;
107 BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_CTX_RESERVED_BITS_ = 2;
108
109 #endif // defined( BOOST_USE_WINDOWS_H )
110
111 BOOST_CONSTEXPR_OR_CONST DWORD_ init_once_async = INIT_ONCE_ASYNC_;
112 BOOST_CONSTEXPR_OR_CONST DWORD_ init_once_check_only = INIT_ONCE_CHECK_ONLY_;
113 BOOST_CONSTEXPR_OR_CONST DWORD_ init_once_init_failed = INIT_ONCE_INIT_FAILED_;
114 BOOST_CONSTEXPR_OR_CONST DWORD_ init_once_ctx_reserved_bits = INIT_ONCE_CTX_RESERVED_BITS_;
115
116 }
117 }
118
119 #include <boost/winapi/detail/footer.hpp>
120
121 #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
122
123 #endif // BOOST_WINAPI_INIT_ONCE_HPP_INCLUDED_
124