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