ntdll: Implement TpCallbackReleaseMutexOnCompletion.

Various internal details about the order and error handling of completion
actions are documented in "Concurrent Programming on Windows" by Joe Duffy.
This commit is contained in:
Sebastian Lackner 2015-07-01 22:56:14 +02:00 committed by Alexandre Julliard
parent a9dd37be68
commit 02ee5bb52d
2 changed files with 20 additions and 0 deletions

View file

@ -975,6 +975,7 @@
@ stdcall TpAllocWork(ptr ptr ptr ptr)
@ stdcall TpCallbackLeaveCriticalSectionOnCompletion(ptr ptr)
@ stdcall TpCallbackMayRunLong(ptr)
@ stdcall TpCallbackReleaseMutexOnCompletion(ptr long)
@ stdcall TpPostWork(ptr)
@ stdcall TpReleaseCleanupGroup(ptr)
@ stdcall TpReleaseCleanupGroupMembers(ptr long ptr)

View file

@ -206,6 +206,7 @@ struct threadpool_instance
struct
{
CRITICAL_SECTION *critical_section;
HANDLE mutex;
} cleanup;
};
@ -1635,6 +1636,7 @@ static void CALLBACK threadpool_worker_proc( void *param )
instance.threadid = GetCurrentThreadId();
instance.may_run_long = object->may_run_long;
instance.cleanup.critical_section = NULL;
instance.cleanup.mutex = NULL;
switch (object->type)
{
@ -1675,6 +1677,10 @@ static void CALLBACK threadpool_worker_proc( void *param )
{
RtlLeaveCriticalSection( instance.cleanup.critical_section );
}
if (instance.cleanup.mutex)
{
NtReleaseMutant( instance.cleanup.mutex, NULL );
}
RtlEnterCriticalSection( &pool->cs );
pool->num_busy_workers--;
@ -1826,6 +1832,19 @@ NTSTATUS WINAPI TpCallbackMayRunLong( TP_CALLBACK_INSTANCE *instance )
return status;
}
/***********************************************************************
* TpCallbackReleaseMutexOnCompletion (NTDLL.@)
*/
VOID WINAPI TpCallbackReleaseMutexOnCompletion( TP_CALLBACK_INSTANCE *instance, HANDLE mutex )
{
struct threadpool_instance *this = impl_from_TP_CALLBACK_INSTANCE( instance );
TRACE( "%p %p\n", instance, mutex );
if (!this->cleanup.mutex)
this->cleanup.mutex = mutex;
}
/***********************************************************************
* TpPostWork (NTDLL.@)
*/