Skip to content
Snippets Groups Projects
Commit 4fd8241d authored by Mark Winter's avatar Mark Winter
Browse files

Removed windows-specific ScopedProcessMutex

TODO: Consider long-term methods for managing cross-process GPU resource usage.
parent dbdb429a
No related branches found
No related tags found
No related merge requests found
......@@ -95,7 +95,6 @@ copy $(OutDir)CudaMex.dll "$(ProjectDir)Mex.mexw64"</Command>
<ClInclude Include="Mex\MexCommand.h" />
<ClInclude Include="Mex\MexWrapDef.h" />
<ClInclude Include="Mex\MexKernel.h" />
<ClInclude Include="Mex\ScopedProcessMutex.h" />
<ClInclude Include="WrapCmds\CommandList.h" />
</ItemGroup>
<ItemGroup>
......@@ -122,7 +121,6 @@ copy $(OutDir)CudaMex.dll "$(ProjectDir)Mex.mexw64"</Command>
<ClCompile Include="Mex\MexSum.cpp" />
<ClCompile Include="Mex\MexVarFilter.cpp" />
<ClCompile Include="Mex\MexWienerFilter.cpp" />
<ClCompile Include="Mex\ScopedProcessMutex.cpp" />
<None Include="Mex\_TemplateMex.cpp" />
</ItemGroup>
<ItemGroup>
......
......@@ -21,9 +21,6 @@
<ClInclude Include="Mex\MexCommand.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Mex\ScopedProcessMutex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Mex\MexKernel.h">
<Filter>Header Files</Filter>
</ClInclude>
......@@ -44,9 +41,6 @@
<ClCompile Include="Mex\MexDeviceStats.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Mex\ScopedProcessMutex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Mex\MexDeviceCount.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......
#pragma once
#include "../Cuda/Vec.h"
#include "ScopedProcessMutex.h"
#include "../Cuda/ImageDimensions.cuh"
#include <mex.h>
......@@ -51,7 +50,6 @@ public:
try
{
ScopedProcessMutex("CudaMutex");
mexCmd->execute(nlhs,plhs,cmdNRHS,cmdPRHS);
} catch(const std::runtime_error& err)
{
......
#include "ScopedProcessMutex.h"
HANDLE ScopedProcessMutex::mutexHandle = NULL;
ScopedProcessMutex::ScopedProcessMutex(const std::string& name)
{
if ( !mutexHandle )
{
mutexHandle = CreateMutex(NULL, false, name.c_str());
if ( !mutexHandle && GetLastError() == ERROR_ACCESS_DENIED )
mutexHandle = OpenMutex(SYNCHRONIZE, false, name.c_str());
if ( !mutexHandle )
throw std::runtime_error("Error creating mutex handle!");
}
DWORD waitResult = WaitForSingleObject(mutexHandle, INFINITE);
if ( waitResult == WAIT_FAILED )
{
mutexHandle = NULL;
throw std::runtime_error("Error unable to acquire mutex!");
}
else if ( waitResult == WAIT_ABANDONED )
{
mutexHandle = NULL;
throw std::runtime_error("Previous thread terminated without releasing mutex!");
}
}
ScopedProcessMutex::~ScopedProcessMutex()
{
if ( mutexHandle )
ReleaseMutex(mutexHandle);
}
#pragma once
#include <string>
#include <windows.h>
class ScopedProcessMutex
{
public:
ScopedProcessMutex(const std::string& name);
~ScopedProcessMutex();
private:
ScopedProcessMutex(){}
ScopedProcessMutex(const ScopedProcessMutex& other){}
static HANDLE mutexHandle;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment