oculus1
diff libovr/Src/Kernel/OVR_Atomic.cpp @ 1:e2f9e4603129
added LibOVR and started a simple vr wrapper.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Sep 2013 16:14:59 +0300 |
parents | |
children | b069a5c27388 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libovr/Src/Kernel/OVR_Atomic.cpp Sat Sep 14 16:14:59 2013 +0300 1.3 @@ -0,0 +1,1 @@ 1.4 +/************************************************************************************ 1.5 1.6 Filename : OVR_Atomic.cpp 1.7 Content : Contains atomic operations and inline fastest locking 1.8 functionality. Will contain #ifdefs for OS efficiency. 1.9 Have non-thread-safe implementation if not available. 1.10 Created : September 19, 2012 1.11 Notes : 1.12 1.13 Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved. 1.14 1.15 Use of this software is subject to the terms of the Oculus license 1.16 agreement provided at the time of installation or download, or which 1.17 otherwise accompanies this software in either electronic or hard copy form. 1.18 1.19 ************************************************************************************/ 1.20 1.21 #include "OVR_Atomic.h" 1.22 1.23 #ifdef OVR_ENABLE_THREADS 1.24 1.25 // Include Windows 8-Metro compatible Synchronization API 1.26 #if defined(OVR_OS_WIN32) && defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8) 1.27 #include <synchapi.h> 1.28 #endif 1.29 1.30 1.31 namespace OVR { 1.32 1.33 // ***** Windows Lock implementation 1.34 1.35 #if defined(OVR_OS_WIN32) 1.36 1.37 // ***** Standard Win32 Lock implementation 1.38 1.39 // Constructors 1.40 Lock::Lock(unsigned spinCount) 1.41 { 1.42 #if defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8) 1.43 // On Windows 8 we use InitializeCriticalSectionEx due to Metro-Compatibility 1.44 InitializeCriticalSectionEx(&cs, spinCount, 1.45 OVR_DEBUG_SELECT(NULL, CRITICAL_SECTION_NO_DEBUG_INFO)); 1.46 #else 1.47 // Spin count init critical section function prototype for Window NT 1.48 typedef BOOL (WINAPI *Function_InitializeCriticalSectionAndSpinCount) 1.49 (LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount); 1.50 1.51 1.52 // Try to load function dynamically so that we don't require NT 1.53 // On Windows NT we will use InitializeCriticalSectionAndSpinCount 1.54 static bool initTried = 0; 1.55 static Function_InitializeCriticalSectionAndSpinCount pInitFn = 0; 1.56 1.57 if (!initTried) 1.58 { 1.59 HMODULE hmodule = ::LoadLibrary(OVR_STR("kernel32.dll")); 1.60 pInitFn = (Function_InitializeCriticalSectionAndSpinCount) 1.61 ::GetProcAddress(hmodule, "InitializeCriticalSectionAndSpinCount"); 1.62 initTried = true; 1.63 } 1.64 1.65 // Initialize the critical section 1.66 if (pInitFn) 1.67 pInitFn(&cs, spinCount); 1.68 else 1.69 ::InitializeCriticalSection(&cs); 1.70 #endif 1.71 1.72 } 1.73 1.74 1.75 Lock::~Lock() 1.76 { 1.77 DeleteCriticalSection(&cs); 1.78 } 1.79 1.80 1.81 #endif 1.82 1.83 } // OVR 1.84 1.85 #endif // OVR_ENABLE_THREADS 1.86 \ No newline at end of file