oculus1

annotate libovr/Src/Kernel/OVR_Atomic.cpp @ 3:b069a5c27388

added a couple more stuff, fixed all the LibOVR line endings
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 15 Sep 2013 04:10:05 +0300
parents e2f9e4603129
children
rev   line source
nuclear@3 1 /************************************************************************************
nuclear@3 2
nuclear@3 3 Filename : OVR_Atomic.cpp
nuclear@3 4 Content : Contains atomic operations and inline fastest locking
nuclear@3 5 functionality. Will contain #ifdefs for OS efficiency.
nuclear@3 6 Have non-thread-safe implementation if not available.
nuclear@3 7 Created : September 19, 2012
nuclear@3 8 Notes :
nuclear@3 9
nuclear@3 10 Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
nuclear@3 11
nuclear@3 12 Use of this software is subject to the terms of the Oculus license
nuclear@3 13 agreement provided at the time of installation or download, or which
nuclear@3 14 otherwise accompanies this software in either electronic or hard copy form.
nuclear@3 15
nuclear@3 16 ************************************************************************************/
nuclear@3 17
nuclear@3 18 #include "OVR_Atomic.h"
nuclear@3 19
nuclear@3 20 #ifdef OVR_ENABLE_THREADS
nuclear@3 21
nuclear@3 22 // Include Windows 8-Metro compatible Synchronization API
nuclear@3 23 #if defined(OVR_OS_WIN32) && defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8)
nuclear@3 24 #include <synchapi.h>
nuclear@3 25 #endif
nuclear@3 26
nuclear@3 27
nuclear@3 28 namespace OVR {
nuclear@3 29
nuclear@3 30 // ***** Windows Lock implementation
nuclear@3 31
nuclear@3 32 #if defined(OVR_OS_WIN32)
nuclear@3 33
nuclear@3 34 // ***** Standard Win32 Lock implementation
nuclear@3 35
nuclear@3 36 // Constructors
nuclear@3 37 Lock::Lock(unsigned spinCount)
nuclear@3 38 {
nuclear@3 39 #if defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8)
nuclear@3 40 // On Windows 8 we use InitializeCriticalSectionEx due to Metro-Compatibility
nuclear@3 41 InitializeCriticalSectionEx(&cs, spinCount,
nuclear@3 42 OVR_DEBUG_SELECT(NULL, CRITICAL_SECTION_NO_DEBUG_INFO));
nuclear@3 43 #else
nuclear@3 44 // Spin count init critical section function prototype for Window NT
nuclear@3 45 typedef BOOL (WINAPI *Function_InitializeCriticalSectionAndSpinCount)
nuclear@3 46 (LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount);
nuclear@3 47
nuclear@3 48
nuclear@3 49 // Try to load function dynamically so that we don't require NT
nuclear@3 50 // On Windows NT we will use InitializeCriticalSectionAndSpinCount
nuclear@3 51 static bool initTried = 0;
nuclear@3 52 static Function_InitializeCriticalSectionAndSpinCount pInitFn = 0;
nuclear@3 53
nuclear@3 54 if (!initTried)
nuclear@3 55 {
nuclear@3 56 HMODULE hmodule = ::LoadLibrary(OVR_STR("kernel32.dll"));
nuclear@3 57 pInitFn = (Function_InitializeCriticalSectionAndSpinCount)
nuclear@3 58 ::GetProcAddress(hmodule, "InitializeCriticalSectionAndSpinCount");
nuclear@3 59 initTried = true;
nuclear@3 60 }
nuclear@3 61
nuclear@3 62 // Initialize the critical section
nuclear@3 63 if (pInitFn)
nuclear@3 64 pInitFn(&cs, spinCount);
nuclear@3 65 else
nuclear@3 66 ::InitializeCriticalSection(&cs);
nuclear@3 67 #endif
nuclear@3 68
nuclear@3 69 }
nuclear@3 70
nuclear@3 71
nuclear@3 72 Lock::~Lock()
nuclear@3 73 {
nuclear@3 74 DeleteCriticalSection(&cs);
nuclear@3 75 }
nuclear@3 76
nuclear@3 77
nuclear@3 78 #endif
nuclear@3 79
nuclear@3 80 } // OVR
nuclear@3 81
nuclear@3 82 #endif // OVR_ENABLE_THREADS