init_once.hpp 4.0 KB

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