OVR_Atomic.cpp
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   OVR_Atomic.cpp
00004 Content     :   Contains atomic operations and inline fastest locking
00005                 functionality. Will contain #ifdefs for OS efficiency.
00006                 Have non-thread-safe implementation if not available.
00007 Created     :   September 19, 2012
00008 Notes       : 
00009 
00010 Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
00011 
00012 Use of this software is subject to the terms of the Oculus license
00013 agreement provided at the time of installation or download, or which
00014 otherwise accompanies this software in either electronic or hard copy form.
00015 
00016 ************************************************************************************/
00017 
00018 #include "OVR_Atomic.h"
00019 
00020 #ifdef OVR_ENABLE_THREADS
00021 
00022 // Include Windows 8-Metro compatible Synchronization API
00023 #if defined(OVR_OS_WIN32) && defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8)
00024 #include <synchapi.h>
00025 #endif
00026 
00027 
00028 namespace OVR {
00029 
00030 // ***** Windows Lock implementation
00031 
00032 #if defined(OVR_OS_WIN32)
00033 
00034 // ***** Standard Win32 Lock implementation
00035 
00036 // Constructors
00037 Lock::Lock(unsigned spinCount)
00038 {
00039 #if defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8)
00040    // On Windows 8 we use InitializeCriticalSectionEx due to Metro-Compatibility
00041    InitializeCriticalSectionEx(&cs, spinCount,
00042                                OVR_DEBUG_SELECT(NULL, CRITICAL_SECTION_NO_DEBUG_INFO));
00043 #else
00044     // Spin count init critical section function prototype for Window NT
00045     typedef BOOL (WINAPI *Function_InitializeCriticalSectionAndSpinCount) 
00046                  (LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount);
00047 
00048 
00049     // Try to load function dynamically so that we don't require NT
00050     // On Windows NT we will use InitializeCriticalSectionAndSpinCount
00051     static  bool initTried = 0;
00052     static  Function_InitializeCriticalSectionAndSpinCount pInitFn = 0;
00053 
00054     if (!initTried)
00055     {
00056         HMODULE hmodule = ::LoadLibrary(OVR_STR("kernel32.dll"));
00057         pInitFn     = (Function_InitializeCriticalSectionAndSpinCount)
00058                       ::GetProcAddress(hmodule, "InitializeCriticalSectionAndSpinCount");
00059         initTried   = true;
00060     }
00061 
00062     // Initialize the critical section
00063     if (pInitFn)
00064         pInitFn(&cs, spinCount);
00065     else
00066         ::InitializeCriticalSection(&cs);
00067 #endif
00068    
00069 }
00070 
00071 
00072 Lock::~Lock()
00073 {
00074     DeleteCriticalSection(&cs);
00075 }
00076 
00077 
00078 #endif
00079 
00080 } // OVR
00081 
00082 #endif // OVR_ENABLE_THREADS


oculus_sdk
Author(s):
autogenerated on Fri Aug 28 2015 11:53:10