Fixed crashing in stopping parser.

This commit is contained in:
Hidenori Takeshima 2002-04-08 20:12:50 +00:00 committed by Alexandre Julliard
parent 2223450ad2
commit bf6c92aa3a
2 changed files with 17 additions and 4 deletions

View File

@ -568,9 +568,11 @@ HRESULT CParserImpl_BeginThread( CParserImpl* This )
DWORD dwRes; DWORD dwRes;
HANDLE hEvents[2]; HANDLE hEvents[2];
if ( This->m_hEventInit != (HANDLE)NULL && if ( This->m_bIsRunning )
This->m_hThread != (HANDLE)NULL ) {
TRACE("(%p) - already running\n",This);
return NOERROR; return NOERROR;
}
This->m_hEventInit = CreateEventA(NULL,TRUE,FALSE,NULL); This->m_hEventInit = CreateEventA(NULL,TRUE,FALSE,NULL);
if ( This->m_hEventInit == (HANDLE)NULL ) if ( This->m_hEventInit == (HANDLE)NULL )
@ -601,6 +603,8 @@ HRESULT CParserImpl_BeginThread( CParserImpl* This )
if ( dwRes != WAIT_OBJECT_0 ) if ( dwRes != WAIT_OBJECT_0 )
return E_FAIL; return E_FAIL;
This->m_bIsRunning = TRUE;
return NOERROR; return NOERROR;
} }
@ -613,14 +617,16 @@ BOOL CParserImpl_EndThread( CParserImpl* This, BOOL bAsync )
dwThreadId = This->m_dwThreadId; dwThreadId = This->m_dwThreadId;
if ( This->m_hEventInit != (HANDLE)NULL ) if ( This->m_hEventInit != (HANDLE)NULL )
{ {
if ( dwThreadId != 0 ) /* FIXME? */ if ( dwThreadId != 0 )
PostThreadMessageA( PostThreadMessageA(
dwThreadId, QUARTZ_MSG_EXITTHREAD, 0, 0 ); dwThreadId, QUARTZ_MSG_EXITTHREAD, 0, 0 );
if ( bAsync ) if ( bAsync &&
WaitForSingleObject( This->m_hEventInit, 0 ) == WAIT_TIMEOUT )
return FALSE; return FALSE;
WaitForSingleObject( This->m_hEventInit, INFINITE ); WaitForSingleObject( This->m_hEventInit, INFINITE );
CloseHandle( This->m_hEventInit ); CloseHandle( This->m_hEventInit );
This->m_bIsRunning = FALSE;
This->m_hEventInit = (HANDLE)NULL; This->m_hEventInit = (HANDLE)NULL;
} }
@ -724,9 +730,14 @@ static HRESULT CParserImpl_OnInactive( CBaseFilterImpl* pImpl )
hr = CParserImpl_MemCommit(This); hr = CParserImpl_MemCommit(This);
if ( FAILED(hr) ) if ( FAILED(hr) )
return hr; return hr;
if ( This->basefilter.fstate == State_Stopped )
CParserImpl_EndThread(This,FALSE);
hr = CParserImpl_BeginThread(This); hr = CParserImpl_BeginThread(This);
if ( FAILED(hr) ) if ( FAILED(hr) )
{ {
FIXME("CParserImpl_BeginThread returns %08lx\n",hr);
CParserImpl_EndThread(This,FALSE); CParserImpl_EndThread(This,FALSE);
return hr; return hr;
} }
@ -1100,6 +1111,7 @@ HRESULT QUARTZ_CreateParser(
This->m_pAllocator = NULL; This->m_pAllocator = NULL;
ZeroMemory( &This->m_propAlloc, sizeof(ALLOCATOR_PROPERTIES) ); ZeroMemory( &This->m_propAlloc, sizeof(ALLOCATOR_PROPERTIES) );
This->m_hEventInit = (HANDLE)NULL; This->m_hEventInit = (HANDLE)NULL;
This->m_bIsRunning = FALSE;
This->m_hThread = (HANDLE)NULL; This->m_hThread = (HANDLE)NULL;
This->m_dwThreadId = 0; This->m_dwThreadId = 0;
This->m_bSendEOS = FALSE; This->m_bSendEOS = FALSE;

View File

@ -48,6 +48,7 @@ struct CParserImpl
IMemAllocator* m_pAllocator; IMemAllocator* m_pAllocator;
ALLOCATOR_PROPERTIES m_propAlloc; ALLOCATOR_PROPERTIES m_propAlloc;
HANDLE m_hEventInit; HANDLE m_hEventInit;
BOOL m_bIsRunning;
DWORD m_dwThreadId; DWORD m_dwThreadId;
HANDLE m_hThread; HANDLE m_hThread;
BOOL m_bSendEOS; BOOL m_bSendEOS;