rpcrt4: Wait for server threads to finish in RpcMgmtWaitServerListen.

This fixes races when stopping manual listen RPC servers. It should fix
races in Office applications as well as our services.exe (visible as CS
error on prefix shutdown).

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2017-05-31 17:30:52 +02:00 committed by Alexandre Julliard
parent e98c7a59c2
commit 09e98be243
1 changed files with 24 additions and 1 deletions

View File

@ -1542,7 +1542,8 @@ RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT
*/
RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
{
HANDLE event;
RpcServerProtseq *protseq;
HANDLE event, wait_thread;
TRACE("()\n");
@ -1558,6 +1559,28 @@ RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
TRACE( "done waiting\n" );
EnterCriticalSection(&listen_cs);
/* wait for server threads to finish */
while(1)
{
if (listen_count)
break;
wait_thread = NULL;
EnterCriticalSection(&server_cs);
LIST_FOR_EACH_ENTRY(protseq, &protseqs, RpcServerProtseq, entry)
{
if ((wait_thread = protseq->server_thread))
break;
}
LeaveCriticalSection(&server_cs);
if (!wait_thread)
break;
TRACE("waiting for thread %u\n", GetThreadId(wait_thread));
LeaveCriticalSection(&listen_cs);
WaitForSingleObject(wait_thread, INFINITE);
EnterCriticalSection(&listen_cs);
}
if (listen_done_event == event)
{
listen_done_event = NULL;