~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to NuxCore/NGlobalInitializer.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 19:25:37 UTC
  • Revision ID: neil.patel@canonical.com-20100901192537-mfz7rm6q262pewg6
Import and build NuxCore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "NKernel.h"
 
2
 
 
3
NAMESPACE_BEGIN
 
4
 
 
5
static NGlobalSingletonInitializer*      GGlobalInitializer   = 0;
 
6
 
 
7
static void SystemStart()
 
8
{
 
9
    static t_u8 StaticBuffer[sizeof(NGlobalSingletonInitializer)];
 
10
    // Placement new in our reserved buffer.
 
11
    GGlobalInitializer =  new(StaticBuffer) NGlobalSingletonInitializer();
 
12
 
 
13
    GLogDevice.AddOutputDevice( &INL_GLOBAL_OBJECT_INSTANCE(NOutputLogFile) );
 
14
    GLogDevice.AddOutputDevice( &INL_GLOBAL_OBJECT_INSTANCE(NOutputVisualDebugConsole) );
 
15
}
 
16
 
 
17
static void SystemShutdown()
 
18
{
 
19
    // Manually destroy initializer
 
20
    if(GGlobalInitializer)
 
21
        GGlobalInitializer->~NGlobalSingletonInitializer();
 
22
    GGlobalInitializer = 0;
 
23
 
 
24
}
 
25
 
 
26
bool NGlobalSingletonInitializer::m_bGlobalObjectsReady = false;
 
27
NGlobalSingletonInitializer::NGlobalSingletonInitializer()
 
28
{
 
29
    m_bGlobalObjectsReady = true;
 
30
}
 
31
 
 
32
NGlobalSingletonInitializer::~NGlobalSingletonInitializer()
 
33
{
 
34
    m_bGlobalObjectsReady = false;
 
35
}
 
36
 
 
37
bool NGlobalSingletonInitializer::Ready()
 
38
{
 
39
    return m_bGlobalObjectsReady;
 
40
}
 
41
 
 
42
int NGlobalInitializer::m_Count = 0;
 
43
NGlobalInitializer::NGlobalInitializer()
 
44
{
 
45
    if(m_Count++ == 0)
 
46
    {
 
47
        SystemStart();
 
48
    }
 
49
}
 
50
 
 
51
NGlobalInitializer::~NGlobalInitializer()
 
52
{
 
53
    if(--m_Count == 0)
 
54
    {
 
55
        SystemShutdown();
 
56
    }
 
57
}
 
58
 
 
59
NAMESPACE_END