mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 14:03:14 +00:00
- Revert my previous changes in QueueUserWorkItem
svn path=/trunk/; revision=42122
This commit is contained in:
parent
15293b22aa
commit
badf1a329a
1 changed files with 51 additions and 2 deletions
|
@ -854,6 +854,34 @@ dowait:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _QUEUE_USER_WORKITEM_CONTEXT
|
||||||
|
{
|
||||||
|
LPTHREAD_START_ROUTINE Function;
|
||||||
|
PVOID Context;
|
||||||
|
} QUEUE_USER_WORKITEM_CONTEXT, *PQUEUE_USER_WORKITEM_CONTEXT;
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
NTAPI
|
||||||
|
InternalWorkItemTrampoline(PVOID Context)
|
||||||
|
{
|
||||||
|
QUEUE_USER_WORKITEM_CONTEXT Info;
|
||||||
|
|
||||||
|
ASSERT(Context);
|
||||||
|
|
||||||
|
/* Save the context to the stack */
|
||||||
|
Info = *(volatile QUEUE_USER_WORKITEM_CONTEXT *)Context;
|
||||||
|
|
||||||
|
/* Free the context before calling the callback. This avoids
|
||||||
|
a memory leak in case the thread dies... */
|
||||||
|
RtlFreeHeap(RtlGetProcessHeap(),
|
||||||
|
0,
|
||||||
|
Context);
|
||||||
|
|
||||||
|
/* Call the real callback */
|
||||||
|
Info.Function(Info.Context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
|
@ -865,13 +893,34 @@ QueueUserWorkItem(
|
||||||
ULONG Flags
|
ULONG Flags
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
PQUEUE_USER_WORKITEM_CONTEXT WorkItemContext;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
Status = RtlQueueWorkItem((WORKERCALLBACKFUNC)Function,
|
/* Save the context for the trampoline function */
|
||||||
Context,
|
WorkItemContext = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
|
0,
|
||||||
|
sizeof(*WorkItemContext));
|
||||||
|
if (WorkItemContext == NULL)
|
||||||
|
{
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkItemContext->Function = Function;
|
||||||
|
WorkItemContext->Context = Context;
|
||||||
|
|
||||||
|
/* NOTE: Don't use Function directly since the callback signature
|
||||||
|
differs. This might cause problems on certain platforms... */
|
||||||
|
Status = RtlQueueWorkItem(InternalWorkItemTrampoline,
|
||||||
|
WorkItemContext,
|
||||||
Flags);
|
Flags);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
/* Free the allocated context in case of failure */
|
||||||
|
RtlFreeHeap(RtlGetProcessHeap(),
|
||||||
|
0,
|
||||||
|
WorkItemContext);
|
||||||
|
|
||||||
SetLastErrorByStatus(Status);
|
SetLastErrorByStatus(Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue