oculus1

view libovr/Src/Kernel/OVR_Atomic.cpp @ 21:ef4c9d8eeca7

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