dplayx: Fix semaphore deadlock.
- Make sure to release the dplayx semaphore in for error cases as well. - Prevent race condition between creation of the semaphore and grabbing of the lock by creating the semaphore in the locked state instead of unlocked.
This commit is contained in:
parent
c04cbbfeae
commit
75fc82c965
|
@ -229,7 +229,7 @@ BOOL DPLAYX_ConstructData(void)
|
||||||
s_attrib.lpSecurityDescriptor = NULL;
|
s_attrib.lpSecurityDescriptor = NULL;
|
||||||
s_attrib.nLength = sizeof(s_attrib);
|
s_attrib.nLength = sizeof(s_attrib);
|
||||||
|
|
||||||
hDplayxSema = CreateSemaphoreA( &s_attrib, 1, 1, lpszDplayxSemaName );
|
hDplayxSema = CreateSemaphoreA( &s_attrib, 0, 1, lpszDplayxSemaName );
|
||||||
|
|
||||||
/* First instance creates the semaphore. Others just use it */
|
/* First instance creates the semaphore. Others just use it */
|
||||||
if( GetLastError() == ERROR_SUCCESS )
|
if( GetLastError() == ERROR_SUCCESS )
|
||||||
|
@ -242,6 +242,7 @@ BOOL DPLAYX_ConstructData(void)
|
||||||
else if ( GetLastError() == ERROR_ALREADY_EXISTS )
|
else if ( GetLastError() == ERROR_ALREADY_EXISTS )
|
||||||
{
|
{
|
||||||
TRACE( "Found semaphore handle %p\n", hDplayxSema );
|
TRACE( "Found semaphore handle %p\n", hDplayxSema );
|
||||||
|
DPLAYX_AquireSemaphore();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -251,8 +252,6 @@ BOOL DPLAYX_ConstructData(void)
|
||||||
|
|
||||||
SetLastError( ERROR_SUCCESS );
|
SetLastError( ERROR_SUCCESS );
|
||||||
|
|
||||||
DPLAYX_AquireSemaphore();
|
|
||||||
|
|
||||||
hDplayxSharedMem = CreateFileMappingA( INVALID_HANDLE_VALUE,
|
hDplayxSharedMem = CreateFileMappingA( INVALID_HANDLE_VALUE,
|
||||||
&s_attrib,
|
&s_attrib,
|
||||||
PAGE_READWRITE | SEC_COMMIT,
|
PAGE_READWRITE | SEC_COMMIT,
|
||||||
|
@ -271,6 +270,7 @@ BOOL DPLAYX_ConstructData(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ERR( ": unable to create shared memory (%ld)\n", GetLastError() );
|
ERR( ": unable to create shared memory (%ld)\n", GetLastError() );
|
||||||
|
DPLAYX_ReleaseSemaphore();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,6 +282,7 @@ BOOL DPLAYX_ConstructData(void)
|
||||||
{
|
{
|
||||||
ERR( ": unable to map static data into process memory space (%ld)\n",
|
ERR( ": unable to map static data into process memory space (%ld)\n",
|
||||||
GetLastError() );
|
GetLastError() );
|
||||||
|
DPLAYX_ReleaseSemaphore();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue