ReactOS 0.4.16-dev-927-g467dec4
shared_initialization.cpp
Go to the documentation of this file.
1//
2// shared_initialization.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Shared initialization logic used by both the AppCRT and the DesktopCRT.
7//
8#include <corecrt_internal.h>
9
11 __acrt_initializer const* const first,
12 __acrt_initializer const* const last
13 )
14{
15 if (first == last)
16 return true;
17
18 // Execute the initializers in [first, last), in order:
19 __acrt_initializer const* it = first;
20 for (; it != last; ++it)
21 {
22 if (it->_initialize == nullptr)
23 continue;
24
25 if (!(it->_initialize)())
26 break;
27 }
28
29 // If we reached the end, all initializers completed successfully:
30 if (it == last)
31 return true;
32
33 // Otherwise, the initializer pointed to by it failed. We need to roll back
34 // the initialization by executing the uninitializers corresponding to each
35 // of the initializers that completed successfully:
36 for (; it != first; --it)
37 {
38 // During initialization roll back, we do not execute uninitializers
39 // that have no corresponding initializer:
40 if ((it - 1)->_initialize == nullptr || (it - 1)->_uninitialize == nullptr)
41 continue;
42
43 (it - 1)->_uninitialize(false);
44 }
45
46 return false;
47}
48
50 __acrt_initializer const* const first,
51 __acrt_initializer const* const last
52 )
53{
54 if (first == last)
55 return true;
56
57 // Execute the uninitializers in [first, last), in reverse order:
58 for (__acrt_initializer const* it = last; it != first; --it)
59 {
60 if ((it - 1)->_uninitialize == nullptr)
61 continue;
62
63 (it - 1)->_uninitialize(false);
64 }
65
66 return true;
67}
#define __cdecl
Definition: accygwin.h:79
const GLint * first
Definition: glext.h:5794
static UINT UINT last
Definition: font.c:45
bool __cdecl __acrt_execute_uninitializers(__acrt_initializer const *const first, __acrt_initializer const *const last)
bool __cdecl __acrt_execute_initializers(__acrt_initializer const *const first, __acrt_initializer const *const last)
__acrt_initialize_pft _initialize