nuclear@1: /************************************************************************************ nuclear@1: nuclear@1: Filename : OVR_System.cpp nuclear@1: Content : General kernel initialization/cleanup, including that nuclear@1: of the memory allocator. nuclear@1: Created : September 19, 2012 nuclear@1: Notes : nuclear@1: nuclear@1: Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved. nuclear@1: nuclear@1: Use of this software is subject to the terms of the Oculus license nuclear@1: agreement provided at the time of installation or download, or which nuclear@1: otherwise accompanies this software in either electronic or hard copy form. nuclear@1: nuclear@1: ************************************************************************************/ nuclear@1: nuclear@1: #include "OVR_System.h" nuclear@1: #include "OVR_Threads.h" nuclear@1: #include "OVR_Timer.h" nuclear@1: nuclear@1: namespace OVR { nuclear@1: nuclear@1: // ***** OVR::System Implementation nuclear@1: nuclear@1: // Initializes System core, installing allocator. nuclear@1: void System::Init(Log* log, Allocator *palloc) nuclear@1: { nuclear@1: if (!Allocator::GetInstance()) nuclear@1: { nuclear@1: Log::SetGlobalLog(log); nuclear@1: Timer::initializeTimerSystem(); nuclear@1: Allocator::setInstance(palloc); nuclear@1: } nuclear@1: else nuclear@1: { nuclear@1: OVR_DEBUG_LOG(("System::Init failed - duplicate call.")); nuclear@1: } nuclear@1: } nuclear@1: nuclear@1: void System::Destroy() nuclear@1: { nuclear@1: if (Allocator::GetInstance()) nuclear@1: { nuclear@1: // Wait for all threads to finish; this must be done so that memory nuclear@1: // allocator and all destructors finalize correctly. nuclear@1: #ifdef OVR_ENABLE_THREADS nuclear@1: Thread::FinishAllThreads(); nuclear@1: #endif nuclear@1: nuclear@1: // Shutdown heap and destroy SysAlloc singleton, if any. nuclear@1: Allocator::GetInstance()->onSystemShutdown(); nuclear@1: Allocator::setInstance(0); nuclear@1: nuclear@1: Timer::shutdownTimerSystem(); nuclear@1: Log::SetGlobalLog(Log::GetDefaultLog()); nuclear@1: } nuclear@1: else nuclear@1: { nuclear@1: OVR_DEBUG_LOG(("System::Destroy failed - System not initialized.")); nuclear@1: } nuclear@1: } nuclear@1: nuclear@1: // Returns 'true' if system was properly initialized. nuclear@1: bool System::IsInitialized() nuclear@1: { nuclear@1: return Allocator::GetInstance() != 0; nuclear@1: } nuclear@1: nuclear@1: } // OVR nuclear@1: