Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
ModuleInit.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
5
7
8 /*
9 ********************************************************************************
10 ******************************** ModuleDependency ******************************
11 ********************************************************************************
12 */
13 inline ModuleDependency::ModuleDependency (void (*start) (), void (*end) ())
14 : fEnd_{end}
15 {
16 (*start) ();
17 }
18 inline ModuleDependency::~ModuleDependency ()
19 {
20 (*fEnd_) ();
21 }
22
23 /*
24 ********************************************************************************
25 ************************ ModuleInitializer<MODULE_DATA> ************************
26 ********************************************************************************
27 */
28 template <typename MODULE_DATA>
29 inline void ModuleInitializer<MODULE_DATA>::Start ()
30 {
31 if (sInitCnt_++ == 0) {
32 // no need to store pointer, cuz its the same as &sActualModuleInitializer_Storage_
33 (void)new (&sActualModuleInitializer_Storage_) MODULE_DATA ();
34 }
35 }
36 template <typename MODULE_DATA>
37 void ModuleInitializer<MODULE_DATA>::End ()
38 {
39 if (--sInitCnt_ == 0) {
40 destroy_at (reinterpret_cast<MODULE_DATA*> (&sActualModuleInitializer_Storage_));
41 }
42 }
43 template <typename MODULE_DATA>
44 inline ModuleInitializer<MODULE_DATA>::ModuleInitializer ()
45 {
46 Start ();
47 }
48 template <typename MODULE_DATA>
49 inline ModuleInitializer<MODULE_DATA>::~ModuleInitializer ()
50 {
51 End ();
52 }
53 template <typename MODULE_DATA>
54 inline MODULE_DATA& ModuleInitializer<MODULE_DATA>::Actual ()
55 {
56 Assert (sInitCnt_ > 0); // we've been initialized, and not yet destroyed...
57 return *reinterpret_cast<MODULE_DATA*> (&sActualModuleInitializer_Storage_);
58 }
59 template <typename MODULE_DATA>
60 inline ModuleDependency ModuleInitializer<MODULE_DATA>::GetDependency ()
61 {
62 return ModuleDependency (Start, End);
63 }
64 template <typename MODULE_DATA>
65 alignas (alignof (MODULE_DATA)) byte ModuleInitializer<MODULE_DATA>::sActualModuleInitializer_Storage_[sizeof (MODULE_DATA)]; // avoid actual memory allocation call - since only one of these
66
67}
CONTAINER::value_type * End(CONTAINER &c)
For a contiguous container (such as a vector or basic_string) - find the pointer to the end of the co...
CONTAINER::value_type * Start(CONTAINER &c)
For a contiguous container (such as a vector or basic_string) - find the pointer to the start of the ...