Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global statically initialized mutex #1327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/openvr_api_public.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ namespace vr

static void *g_pVRModule = NULL;
static IVRClientCore *g_pHmdSystem = NULL;
static std::recursive_mutex g_mutexSystem;

static std::recursive_mutex& GetMutexSystem()
{
static std::recursive_mutex mutexSystem;
return mutexSystem;
}

typedef void* (*VRClientCoreFactoryFn)(const char *pInterfaceName, int *pReturnCode);

Expand All @@ -55,7 +59,7 @@ void CleanupInternalInterfaces();

uint32_t VR_InitInternal2( EVRInitError *peError, vr::EVRApplicationType eApplicationType, const char *pStartupInfo )
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
std::lock_guard<std::recursive_mutex> lock( GetMutexSystem() );

EVRInitError err = VR_LoadHmdSystemInternal();
if ( err == vr::VRInitError_None )
Expand Down Expand Up @@ -87,7 +91,7 @@ uint32_t VR_InitInternal( EVRInitError *peError, vr::EVRApplicationType eApplica

void VR_ShutdownInternal()
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
std::lock_guard<std::recursive_mutex> lock( GetMutexSystem() );

if ( g_pHmdSystem )
{
Expand Down Expand Up @@ -172,7 +176,7 @@ EVRInitError VR_LoadHmdSystemInternal()

void *VR_GetGenericInterface(const char *pchInterfaceVersion, EVRInitError *peError)
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
std::lock_guard<std::recursive_mutex> lock( GetMutexSystem() );

if (!g_pHmdSystem)
{
Expand All @@ -186,7 +190,7 @@ void *VR_GetGenericInterface(const char *pchInterfaceVersion, EVRInitError *peEr

bool VR_IsInterfaceVersionValid(const char *pchInterfaceVersion)
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
std::lock_guard<std::recursive_mutex> lock( GetMutexSystem() );

if (!g_pHmdSystem)
{
Expand All @@ -198,7 +202,7 @@ bool VR_IsInterfaceVersionValid(const char *pchInterfaceVersion)

bool VR_IsHmdPresent()
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
std::lock_guard<std::recursive_mutex> lock( GetMutexSystem() );

if( g_pHmdSystem )
{
Expand All @@ -225,7 +229,7 @@ bool VR_IsHmdPresent()
/** Returns true if the OpenVR runtime is installed. */
bool VR_IsRuntimeInstalled()
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
std::lock_guard<std::recursive_mutex> lock( GetMutexSystem() );

if( g_pHmdSystem )
{
Expand Down Expand Up @@ -319,7 +323,7 @@ bool VR_GetRuntimePath( char *pchPathBuffer, uint32_t unBufferSize, uint32_t *pu
/** Returns the symbol version of an HMD error. */
const char *VR_GetVRInitErrorAsSymbol( EVRInitError error )
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
std::lock_guard<std::recursive_mutex> lock( GetMutexSystem() );

if( g_pHmdSystem )
return g_pHmdSystem->GetIDForVRInitError( error );
Expand All @@ -331,7 +335,7 @@ const char *VR_GetVRInitErrorAsSymbol( EVRInitError error )
/** Returns the english string version of an HMD error. */
const char *VR_GetVRInitErrorAsEnglishDescription( EVRInitError error )
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
std::lock_guard<std::recursive_mutex> lock( GetMutexSystem() );

if ( g_pHmdSystem )
return g_pHmdSystem->GetEnglishStringForHmdError( error );
Expand Down