init_once.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #ifndef BOOST_WINAPI_INIT_ONCE_HPP_INCLUDED_
  9. #define BOOST_WINAPI_INIT_ONCE_HPP_INCLUDED_
  10. #include <boost/winapi/config.hpp>
  11. #ifdef BOOST_HAS_PRAGMA_ONCE
  12. #pragma once
  13. #endif
  14. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  15. #include <boost/winapi/basic_types.hpp>
  16. #if !defined(BOOST_USE_WINDOWS_H)
  17. extern "C" {
  18. #if defined(BOOST_WINAPI_IS_CYGWIN) || defined(BOOST_WINAPI_IS_MINGW_W64)
  19. struct _RTL_RUN_ONCE;
  20. #else
  21. union _RTL_RUN_ONCE;
  22. #endif
  23. typedef boost::winapi::BOOL_
  24. (BOOST_WINAPI_WINAPI_CC *PINIT_ONCE_FN) (
  25. ::_RTL_RUN_ONCE* InitOnce,
  26. boost::winapi::PVOID_ Parameter,
  27. boost::winapi::PVOID_ *Context);
  28. BOOST_SYMBOL_IMPORT boost::winapi::VOID_ BOOST_WINAPI_WINAPI_CC
  29. InitOnceInitialize(::_RTL_RUN_ONCE* InitOnce);
  30. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  31. InitOnceExecuteOnce(
  32. ::_RTL_RUN_ONCE* InitOnce,
  33. ::PINIT_ONCE_FN InitFn,
  34. boost::winapi::PVOID_ Parameter,
  35. boost::winapi::LPVOID_ *Context);
  36. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  37. InitOnceBeginInitialize(
  38. ::_RTL_RUN_ONCE* lpInitOnce,
  39. boost::winapi::DWORD_ dwFlags,
  40. boost::winapi::PBOOL_ fPending,
  41. boost::winapi::LPVOID_ *lpContext);
  42. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC
  43. InitOnceComplete(
  44. ::_RTL_RUN_ONCE* lpInitOnce,
  45. boost::winapi::DWORD_ dwFlags,
  46. boost::winapi::LPVOID_ lpContext);
  47. }
  48. #endif
  49. namespace boost {
  50. namespace winapi {
  51. typedef union BOOST_MAY_ALIAS _RTL_RUN_ONCE {
  52. PVOID_ Ptr;
  53. } INIT_ONCE_, *PINIT_ONCE_, *LPINIT_ONCE_;
  54. extern "C" {
  55. typedef BOOL_ (BOOST_WINAPI_WINAPI_CC *PINIT_ONCE_FN_) (PINIT_ONCE_ lpInitOnce, PVOID_ Parameter, PVOID_ *Context);
  56. }
  57. BOOST_FORCEINLINE VOID_ InitOnceInitialize(PINIT_ONCE_ lpInitOnce)
  58. {
  59. ::InitOnceInitialize(reinterpret_cast< ::_RTL_RUN_ONCE* >(lpInitOnce));
  60. }
  61. BOOST_FORCEINLINE BOOL_ InitOnceExecuteOnce(PINIT_ONCE_ lpInitOnce, PINIT_ONCE_FN_ InitFn, PVOID_ Parameter, LPVOID_ *Context)
  62. {
  63. return ::InitOnceExecuteOnce(reinterpret_cast< ::_RTL_RUN_ONCE* >(lpInitOnce), reinterpret_cast< ::PINIT_ONCE_FN >(InitFn), Parameter, Context);
  64. }
  65. BOOST_FORCEINLINE BOOL_ InitOnceBeginInitialize(PINIT_ONCE_ lpInitOnce, DWORD_ dwFlags, PBOOL_ fPending, LPVOID_ *lpContext)
  66. {
  67. return ::InitOnceBeginInitialize(reinterpret_cast< ::_RTL_RUN_ONCE* >(lpInitOnce), dwFlags, fPending, lpContext);
  68. }
  69. BOOST_FORCEINLINE BOOL_ InitOnceComplete(PINIT_ONCE_ lpInitOnce, DWORD_ dwFlags, LPVOID_ lpContext)
  70. {
  71. return ::InitOnceComplete(reinterpret_cast< ::_RTL_RUN_ONCE* >(lpInitOnce), dwFlags, lpContext);
  72. }
  73. #if defined( BOOST_USE_WINDOWS_H )
  74. #define BOOST_WINAPI_INIT_ONCE_STATIC_INIT INIT_ONCE_STATIC_INIT
  75. BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_ASYNC_ = INIT_ONCE_ASYNC;
  76. BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_CHECK_ONLY_ = INIT_ONCE_CHECK_ONLY;
  77. BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_INIT_FAILED_ = INIT_ONCE_INIT_FAILED;
  78. BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_CTX_RESERVED_BITS_ = INIT_ONCE_CTX_RESERVED_BITS;
  79. #else // defined( BOOST_USE_WINDOWS_H )
  80. #define BOOST_WINAPI_INIT_ONCE_STATIC_INIT {0}
  81. BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_ASYNC_ = 0x00000002UL;
  82. BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_CHECK_ONLY_ = 0x00000001UL;
  83. BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_INIT_FAILED_ = 0x00000004UL;
  84. BOOST_CONSTEXPR_OR_CONST DWORD_ INIT_ONCE_CTX_RESERVED_BITS_ = 2;
  85. #endif // defined( BOOST_USE_WINDOWS_H )
  86. BOOST_CONSTEXPR_OR_CONST DWORD_ init_once_async = INIT_ONCE_ASYNC_;
  87. BOOST_CONSTEXPR_OR_CONST DWORD_ init_once_check_only = INIT_ONCE_CHECK_ONLY_;
  88. BOOST_CONSTEXPR_OR_CONST DWORD_ init_once_init_failed = INIT_ONCE_INIT_FAILED_;
  89. BOOST_CONSTEXPR_OR_CONST DWORD_ init_once_ctx_reserved_bits = INIT_ONCE_CTX_RESERVED_BITS_;
  90. }
  91. }
  92. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  93. #endif // BOOST_WINAPI_INIT_ONCE_HPP_INCLUDED_