2004-07-08 00:40:31 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* PURPOSE: Timer Queue implementation
|
2005-09-08 00:09:32 +00:00
|
|
|
* FILE: lib/rtl/timerqueue.c
|
2007-10-19 23:21:45 +00:00
|
|
|
* PROGRAMMER:
|
2004-07-08 00:40:31 +00:00
|
|
|
*/
|
|
|
|
|
2005-09-08 00:09:32 +00:00
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <rtl.h>
|
2004-07-08 00:40:31 +00:00
|
|
|
|
2005-06-19 22:50:59 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
2004-07-08 00:40:31 +00:00
|
|
|
|
2008-09-08 11:10:02 +00:00
|
|
|
#undef LIST_FOR_EACH
|
|
|
|
#undef LIST_FOR_EACH_SAFE
|
|
|
|
#include <wine/list.h>
|
|
|
|
|
2005-09-08 00:09:32 +00:00
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
[RTL/NTDLL/KERNEL32]: Rtl provides worker queue and timer queue functionality, which queues a worker thread associated with a caller-supplied callback. In Windows, Rtl by default calls RtlCreateUserThread, but as soon as kernel32 loads, it's DllMain calls an exported function RtlSetThreadPoolStartFunc which changes that default to a special Base function that calls CreateRemoteThread instead. The net result is that Win32 processes using the Rtl functionality get their threads properly registered with CSRSS. In ReactOS, this did not happen, so when those threads called into CSRSS, CSRSS had no CSR_THREAD structure/state for them, which is why CsrCreateThread (and the API loop) are so badly hacked. This commit implements RtlSetThreadPoolStartFunc, implements the kernel32 base functions which wrap CreateRemoteThread, and implements the rtl functions which wrap RtlCreateUserThread. Services, Setup, and any ReactOS application using RPC now have the worker threads correctly registered.
svn path=/trunk/; revision=55706
2012-02-19 10:06:31 +00:00
|
|
|
extern PRTL_START_POOL_THREAD RtlpStartThreadFunc;
|
|
|
|
extern PRTL_EXIT_POOL_THREAD RtlpExitThreadFunc;
|
2006-07-03 20:24:46 +00:00
|
|
|
HANDLE TimerThreadHandle = NULL;
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
RtlpInitializeTimerThread(VOID)
|
|
|
|
{
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2008-09-08 11:10:02 +00:00
|
|
|
static inline PLARGE_INTEGER get_nt_timeout( PLARGE_INTEGER pTime, ULONG timeout )
|
2004-07-08 00:40:31 +00:00
|
|
|
{
|
2008-09-08 11:10:02 +00:00
|
|
|
if (timeout == INFINITE) return NULL;
|
|
|
|
pTime->QuadPart = (ULONGLONG)timeout * -10000;
|
|
|
|
return pTime;
|
2004-07-08 00:40:31 +00:00
|
|
|
}
|
|
|
|
|
2008-09-08 11:10:02 +00:00
|
|
|
struct timer_queue;
|
|
|
|
struct queue_timer
|
|
|
|
{
|
|
|
|
struct timer_queue *q;
|
|
|
|
struct list entry;
|
|
|
|
ULONG runcount; /* number of callbacks pending execution */
|
|
|
|
WAITORTIMERCALLBACKFUNC callback;
|
|
|
|
PVOID param;
|
|
|
|
DWORD period;
|
|
|
|
ULONG flags;
|
|
|
|
ULONGLONG expire;
|
2015-11-24 20:35:58 +00:00
|
|
|
BOOL destroy; /* timer should be deleted; once set, never unset */
|
|
|
|
HANDLE event; /* removal event */
|
2008-09-08 11:10:02 +00:00
|
|
|
};
|
2004-07-08 00:40:31 +00:00
|
|
|
|
2008-09-08 11:10:02 +00:00
|
|
|
struct timer_queue
|
|
|
|
{
|
2015-11-24 20:35:58 +00:00
|
|
|
DWORD magic;
|
2008-09-08 11:10:02 +00:00
|
|
|
RTL_CRITICAL_SECTION cs;
|
2015-11-24 20:35:58 +00:00
|
|
|
struct list timers; /* sorted by expiration time */
|
|
|
|
BOOL quit; /* queue should be deleted; once set, never unset */
|
2008-09-08 11:10:02 +00:00
|
|
|
HANDLE event;
|
|
|
|
HANDLE thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define EXPIRE_NEVER (~(ULONGLONG) 0)
|
2015-11-24 20:35:58 +00:00
|
|
|
#define TIMER_QUEUE_MAGIC 0x516d6954 /* TimQ */
|
2008-09-08 11:10:02 +00:00
|
|
|
|
2019-09-21 12:46:01 +02:00
|
|
|
NTSTATUS
|
|
|
|
WINAPI
|
|
|
|
RtlSetTimer(
|
|
|
|
HANDLE TimerQueue,
|
|
|
|
PHANDLE NewTimer,
|
|
|
|
WAITORTIMERCALLBACKFUNC Callback,
|
|
|
|
PVOID Parameter,
|
|
|
|
DWORD DueTime,
|
|
|
|
DWORD Period,
|
|
|
|
ULONG Flags)
|
|
|
|
{
|
|
|
|
return RtlCreateTimer(TimerQueue,
|
|
|
|
NewTimer,
|
|
|
|
Callback,
|
|
|
|
Parameter,
|
|
|
|
DueTime,
|
|
|
|
Period,
|
|
|
|
Flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RtlCancelTimer(HANDLE TimerQueue, HANDLE Timer)
|
|
|
|
{
|
|
|
|
return RtlDeleteTimer(TimerQueue, Timer, NULL);
|
|
|
|
}
|
|
|
|
|
2004-07-08 00:40:31 +00:00
|
|
|
/*
|
2008-09-08 11:10:02 +00:00
|
|
|
* @implemented
|
2004-07-08 00:40:31 +00:00
|
|
|
*/
|
|
|
|
NTSTATUS
|
2005-10-19 17:03:38 +00:00
|
|
|
NTAPI
|
2008-09-08 11:10:02 +00:00
|
|
|
RtlDeleteTimerQueue(HANDLE TimerQueue)
|
2004-07-08 00:40:31 +00:00
|
|
|
{
|
2008-09-08 11:10:02 +00:00
|
|
|
return RtlDeleteTimerQueueEx(TimerQueue, INVALID_HANDLE_VALUE);
|
2004-07-08 00:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|