- Timestamp:
- Oct 2, 2013, 8:20:03 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/Miscellaneous/StaticConstructor/StaticConstructor.cpp
r219 r220 6 6 #include <atlbase.h> 7 7 #include <atlcom.h> 8 9 class CModule : 10 public CAtlExeModuleT<CModule> 11 { 12 }; 8 13 9 14 class CFoo … … 20 25 m_nValue++; 21 26 } 27 CFoo(INT nValue) 28 { 29 m_nValue = nValue; 30 Sleep(100); 31 m_nValue++; 32 } 33 CFoo(INT nValue1, INT nValue2) 34 { 35 m_nValue = nValue1 + nValue2; 36 Sleep(100); 37 m_nValue++; 38 } 22 39 }; 23 40 24 CRITICAL_SECTION g_Section; 41 #define STATICLOCAL_PART1(type, name) \ 42 static BYTE g_pn##name##Data[sizeof (type)]; \ 43 static BOOL g_b##name##Initialized = FALSE; \ 44 type& g_##name = reinterpret_cast<type&>(g_pn##name##Data); \ 45 { \ 46 ATLASSERT(_pAtlModule); \ 47 CComCritSecLock<CComCriticalSection> Lock(_pAtlModule->m_csStaticDataInitAndTypeInfo); \ 48 if(!g_b##name##Initialized) \ 49 { \ 50 new (g_pn##name##Data) type( 51 52 #define STATICLOCAL_PART2(type, name) \ 53 ); \ 54 g_b##name##Initialized = TRUE; \ 55 } \ 56 } 57 58 #define STATICLOCAL0(type, name) \ 59 STATICLOCAL_PART1(type, name) STATICLOCAL_PART2(type, name) 60 #define STATICLOCAL1(type, name, parameter1) \ 61 STATICLOCAL_PART1(type, name) parameter1 STATICLOCAL_PART2(type, name) 62 #define STATICLOCAL2(type, name, parameter1, parameter2) \ 63 STATICLOCAL_PART1(type, name) parameter1, parameter2 STATICLOCAL_PART2(type, name) 25 64 26 65 DWORD WINAPI ThreadProc(INT_PTR*) 27 66 { 28 67 #if TRUE 29 static BYTE g_pnFooData[sizeof (CFoo)]; 30 static BOOL g_bFooInitialized = FALSE; 31 CFoo& g_Foo = reinterpret_cast<CFoo&>(g_pnFooData); 32 EnterCriticalSection(&g_Section); 33 if(!g_bFooInitialized) 34 { 35 new (g_pnFooData) CFoo(); 36 g_bFooInitialized = TRUE; 37 } 38 LeaveCriticalSection(&g_Section); 68 //STATICLOCAL0(CFoo, Foo); 69 //STATICLOCAL1(CFoo, Foo, 10); 70 STATICLOCAL2(CFoo, Foo, 20, 30); 39 71 #else 40 72 static CFoo g_Foo; … … 46 78 int _tmain(int argc, _TCHAR* argv[]) 47 79 { 48 InitializeCriticalSection(&g_Section);80 CModule Module; 49 81 HANDLE phObjects[32]; 50 82 for(SIZE_T nIndex = 0; nIndex < _countof(phObjects); nIndex++)
Note: See TracChangeset
for help on using the changeset viewer.