oculus1

diff 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
line diff
     1.1 --- a/libovr/Src/Kernel/OVR_Atomic.cpp	Sat Sep 14 17:51:03 2013 +0300
     1.2 +++ b/libovr/Src/Kernel/OVR_Atomic.cpp	Sun Sep 15 04:10:05 2013 +0300
     1.3 @@ -1,1 +1,82 @@
     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
    1.87 +/************************************************************************************
    1.88 +
    1.89 +Filename    :   OVR_Atomic.cpp
    1.90 +Content     :   Contains atomic operations and inline fastest locking
    1.91 +                functionality. Will contain #ifdefs for OS efficiency.
    1.92 +                Have non-thread-safe implementation if not available.
    1.93 +Created     :   September 19, 2012
    1.94 +Notes       : 
    1.95 +
    1.96 +Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
    1.97 +
    1.98 +Use of this software is subject to the terms of the Oculus license
    1.99 +agreement provided at the time of installation or download, or which
   1.100 +otherwise accompanies this software in either electronic or hard copy form.
   1.101 +
   1.102 +************************************************************************************/
   1.103 +
   1.104 +#include "OVR_Atomic.h"
   1.105 +
   1.106 +#ifdef OVR_ENABLE_THREADS
   1.107 +
   1.108 +// Include Windows 8-Metro compatible Synchronization API
   1.109 +#if defined(OVR_OS_WIN32) && defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8)
   1.110 +#include <synchapi.h>
   1.111 +#endif
   1.112 +
   1.113 +
   1.114 +namespace OVR {
   1.115 +
   1.116 +// ***** Windows Lock implementation
   1.117 +
   1.118 +#if defined(OVR_OS_WIN32)
   1.119 +
   1.120 +// ***** Standard Win32 Lock implementation
   1.121 +
   1.122 +// Constructors
   1.123 +Lock::Lock(unsigned spinCount)
   1.124 +{
   1.125 +#if defined(NTDDI_WIN8) && (NTDDI_VERSION >= NTDDI_WIN8)
   1.126 +   // On Windows 8 we use InitializeCriticalSectionEx due to Metro-Compatibility
   1.127 +   InitializeCriticalSectionEx(&cs, spinCount,
   1.128 +                               OVR_DEBUG_SELECT(NULL, CRITICAL_SECTION_NO_DEBUG_INFO));
   1.129 +#else
   1.130 +    // Spin count init critical section function prototype for Window NT
   1.131 +    typedef BOOL (WINAPI *Function_InitializeCriticalSectionAndSpinCount) 
   1.132 +                 (LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount);
   1.133 +
   1.134 +
   1.135 +    // Try to load function dynamically so that we don't require NT
   1.136 +    // On Windows NT we will use InitializeCriticalSectionAndSpinCount
   1.137 +    static  bool initTried = 0;
   1.138 +    static  Function_InitializeCriticalSectionAndSpinCount pInitFn = 0;
   1.139 +
   1.140 +    if (!initTried)
   1.141 +    {
   1.142 +        HMODULE hmodule = ::LoadLibrary(OVR_STR("kernel32.dll"));
   1.143 +        pInitFn     = (Function_InitializeCriticalSectionAndSpinCount)
   1.144 +                      ::GetProcAddress(hmodule, "InitializeCriticalSectionAndSpinCount");
   1.145 +        initTried   = true;
   1.146 +    }
   1.147 +
   1.148 +    // Initialize the critical section
   1.149 +    if (pInitFn)
   1.150 +        pInitFn(&cs, spinCount);
   1.151 +    else
   1.152 +        ::InitializeCriticalSection(&cs);
   1.153 +#endif
   1.154 +   
   1.155 +}
   1.156 +
   1.157 +
   1.158 +Lock::~Lock()
   1.159 +{
   1.160 +    DeleteCriticalSection(&cs);
   1.161 +}
   1.162 +
   1.163 +
   1.164 +#endif
   1.165 +
   1.166 +} // OVR
   1.167 +
   1.168 +#endif // OVR_ENABLE_THREADS