Commit in reactos/subsys/win32k on MAIN
include/msgqueue.h+2-51.39 -> 1.40
       /timer.h+3-31.6 -> 1.7
ntuser/caret.c+3-31.13 -> 1.14
      /msgqueue.c+39-451.101 -> 1.102
      /timer.c+37-261.34 -> 1.35
+84-82
5 modified files
Reverted my changes to timers

reactos/subsys/win32k/include
msgqueue.h 1.39 -> 1.40
diff -u -r1.39 -r1.40
--- msgqueue.h	30 Jul 2004 09:16:06 -0000	1.39
+++ msgqueue.h	4 Aug 2004 22:31:17 -0000	1.40
@@ -17,20 +17,17 @@
 
 struct _USER_MESSAGE_QUEUE;
 
-#define USMF_WAKE_SENDER 0x1
-
 typedef struct _USER_SENT_MESSAGE
 {
   LIST_ENTRY ListEntry;
   MSG Msg;
-  LRESULT Result;
-  ULONG Flags; /* the sender queue must be locked to access this field!!! */
+  PKEVENT CompletionEvent;
+  LRESULT* Result;
   struct _USER_MESSAGE_QUEUE* SenderQueue;
   SENDASYNCPROC CompletionCallback;
   ULONG_PTR CompletionCallbackContext;
   /* entry in the dispatching list of the sender's message queue */
   LIST_ENTRY DispatchingListEntry;
-  KEVENT CompletionEvent;
 } USER_SENT_MESSAGE, *PUSER_SENT_MESSAGE;
 
 typedef struct _USER_SENT_MESSAGE_NOTIFY

reactos/subsys/win32k/include
timer.h 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- timer.h	30 Jul 2004 09:16:06 -0000	1.6
+++ timer.h	4 Aug 2004 22:31:17 -0000	1.7
@@ -4,15 +4,15 @@
 typedef struct _MSG_TIMER_ENTRY{
    LIST_ENTRY     ListEntry;
    LARGE_INTEGER  Timeout;
-   struct _USER_MESSAGE_QUEUE* MessageQueue;
+   HANDLE          ThreadID;
    UINT           Period;
    MSG            Msg;
 } MSG_TIMER_ENTRY, *PMSG_TIMER_ENTRY;
 
 NTSTATUS FASTCALL InitTimerImpl(VOID);
-VOID FASTCALL RemoveTimersThread(PUSER_MESSAGE_QUEUE MessageQueue);
+VOID FASTCALL RemoveTimersThread(HANDLE ThreadID);
 VOID FASTCALL RemoveTimersWindow(HWND hWnd);
-PMSG_TIMER_ENTRY FASTCALL IntRemoveTimer(HWND hWnd, UINT_PTR IDEvent, BOOL SysTimer);
+PMSG_TIMER_ENTRY FASTCALL IntRemoveTimer(HWND hWnd, UINT_PTR IDEvent, HANDLE ThreadID, BOOL SysTimer);
 UINT_PTR FASTCALL IntSetTimer(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc, BOOL SystemTimer);
 
 #endif /* _WIN32K_TIMER_H */

reactos/subsys/win32k/ntuser
caret.c 1.13 -> 1.14
diff -u -r1.13 -r1.14
--- caret.c	30 Jul 2004 09:16:06 -0000	1.13
+++ caret.c	4 Aug 2004 22:31:17 -0000	1.14
@@ -1,4 +1,4 @@
-/* $Id: caret.c,v 1.13 2004/07/30 09:16:06 weiden Exp $
+/* $Id: caret.c,v 1.14 2004/08/04 22:31:17 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -262,7 +262,7 @@
     return FALSE;
   }
   
-  IntRemoveTimer(hWnd, IDCARETTIMER, TRUE);
+  IntRemoveTimer(hWnd, IDCARETTIMER, PsGetCurrentThreadId(), TRUE);
   
   ThreadQueue = (PUSER_MESSAGE_QUEUE)PsGetWin32Thread()->MessageQueue;
   
@@ -347,7 +347,7 @@
   
   if(ThreadQueue->CaretInfo->Visible)
   {
-    IntRemoveTimer(hWnd, IDCARETTIMER, TRUE);
+    IntRemoveTimer(hWnd, IDCARETTIMER, PsGetCurrentThreadId(), TRUE);
     
     IntHideCaret(ThreadQueue->CaretInfo);
     ThreadQueue->CaretInfo->Visible = 0;

reactos/subsys/win32k/ntuser
msgqueue.c 1.101 -> 1.102
diff -u -r1.101 -r1.102
--- msgqueue.c	30 Jul 2004 09:16:06 -0000	1.101
+++ msgqueue.c	4 Aug 2004 22:31:17 -0000	1.102
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: msgqueue.c,v 1.101 2004/07/30 09:16:06 weiden Exp $
+/* $Id: msgqueue.c,v 1.102 2004/08/04 22:31:17 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -729,7 +729,7 @@
   PUSER_SENT_MESSAGE Message;
   PLIST_ENTRY Entry;
   LRESULT Result;
-  BOOL Freed, Wake;
+  BOOL Freed;
   PUSER_SENT_MESSAGE_NOTIFY NotifyMessage;
 
   IntLockMessageQueue(MessageQueue);
@@ -775,18 +775,22 @@
      MsqSendMessage() function (if timed out) */
   
   /* Let the sender know the result. */
-  Message->Result = Result;
-
-  Wake = (Message->Flags & USMF_WAKE_SENDER) != 0;
+  if (Message->Result != NULL)
+    {
+      *Message->Result = Result;
+    }
 
   /* Notify the sender. */
-  if (Wake)
+  if (Message->CompletionEvent != NULL)
     {
-      KeSetEvent(&Message->CompletionEvent, IO_NO_INCREMENT, FALSE);
+      KeSetEvent(Message->CompletionEvent, IO_NO_INCREMENT, FALSE);
     }
+  
+  /* unlock the sender's message queue, the safe operation is done */
+  IntUnLockMessageQueue(Message->SenderQueue);
 
   /* Notify the sender if they specified a callback. */
-  if (!Freed && Wake)
+  if (!Freed && Message->CompletionCallback != NULL)
     {
       if(!(NotifyMessage = ExAllocatePoolWithTag(NonPagedPool,
 					         sizeof(USER_SENT_MESSAGE_NOTIFY), TAG_USRMSG)))
@@ -794,7 +798,6 @@
         DPRINT1("MsqDispatchOneSentMessage(): Not enough memory to create a callback notify message\n");
         goto Notified;
       }
-      /* FIXME
       NotifyMessage->CompletionCallback =
 	Message->CompletionCallback;
       NotifyMessage->CompletionCallbackContext =
@@ -803,23 +806,16 @@
       NotifyMessage->hWnd = Message->Msg.hwnd;
       NotifyMessage->Msg = Message->Msg.message;
       MsqSendNotifyMessage(Message->SenderQueue, NotifyMessage);
-      */
     }
 
 Notified:
-  /* unlock the sender's message queue, the safe operation is done */
-  IntUnLockMessageQueue(Message->SenderQueue);
-  if(!Wake)
-  {
-    IntDereferenceMessageQueue(Message->SenderQueue);
-  }
-  
   if(!Freed)
   {
     /* only dereference our message queue if the message has not been timed out */
     IntDereferenceMessageQueue(MessageQueue);
   }
   
+  /* only free the message if not freed already */
   ExFreePool(Message);
   return(TRUE);
 }
@@ -841,7 +837,9 @@
                UINT uTimeout, BOOL Block, ULONG_PTR *uResult)
 {
   PUSER_SENT_MESSAGE Message;
+  KEVENT CompletionEvent;
   NTSTATUS WaitStatus;
+  LRESULT Result;
   PUSER_MESSAGE_QUEUE ThreadQueue;
   LARGE_INTEGER Timeout;
   PLIST_ENTRY Entry;
@@ -852,24 +850,26 @@
     return STATUS_INSUFFICIENT_RESOURCES;
   }
   
-  KeInitializeEvent(&Message->CompletionEvent, NotificationEvent, FALSE);
+  KeInitializeEvent(&CompletionEvent, NotificationEvent, FALSE);
   
   ThreadQueue = PsGetWin32Thread()->MessageQueue;
   ASSERT(ThreadQueue != MessageQueue);
   
   Timeout.QuadPart = uTimeout * -10000;
   
+  /* FIXME - increase reference counter of sender's message queue here */
+  
+  Result = 0;
   Message->Msg.hwnd = Wnd;
   Message->Msg.message = Msg;
   Message->Msg.wParam = wParam;
   Message->Msg.lParam = lParam;
-  Message->Result = 0;
-  Message->Flags = USMF_WAKE_SENDER;
+  Message->CompletionEvent = &CompletionEvent;
+  Message->Result = &Result;
   Message->SenderQueue = ThreadQueue;
   Message->CompletionCallback = NULL;
   
   IntReferenceMessageQueue(MessageQueue);
-  IntReferenceMessageQueue(ThreadQueue);
   
   /* add it to the list of pending messages */
   IntLockMessageQueue(ThreadQueue);
@@ -888,11 +888,11 @@
   if(Block)
   {
     /* don't process messages sent to the thread */
-    WaitStatus = KeWaitForSingleObject(&Message->CompletionEvent, UserRequest, UserMode,
+    WaitStatus = KeWaitForSingleObject(&CompletionEvent, UserRequest, UserMode, 
                                        FALSE, (uTimeout ? &Timeout : NULL));
     if(WaitStatus == STATUS_TIMEOUT)
       {
-        /* look up if the message has not yet been dispatched, if so
+        /* look up if the message has not yet dispatched, if so
            make sure it can't pass a result and it must not set the completion event anymore */
 	IntLockMessageQueue(MessageQueue);
         Entry = MessageQueue->SentMessagesListHead.Flink;
@@ -901,11 +901,10 @@
             if ((PUSER_SENT_MESSAGE) CONTAINING_RECORD(Entry, USER_SENT_MESSAGE, ListEntry)
                 == Message)
               {
-                IntLockMessageQueue(ThreadQueue);
-                /* we can access Message here, it's secure because the sender message queue is locked
+                /* we can access Message here, it's secure because the message queue is locked
                    and the message is still hasn't been dispatched */
-		Message->Flags &= ~USMF_WAKE_SENDER;
-		IntUnLockMessageQueue(ThreadQueue);
+		Message->CompletionEvent = NULL;
+                Message->Result = NULL;
                 break;
               }
             Entry = Entry->Flink;
@@ -925,7 +924,8 @@
                    and the message has definitely not yet been destroyed, otherwise it would
                    have been removed from this list by the dispatching routine right after
 		   dispatching the message */
-                Message->Flags &= ~USMF_WAKE_SENDER;
+		Message->CompletionEvent = NULL;
+                Message->Result = NULL;
                 RemoveEntryList(&Message->DispatchingListEntry);
                 IntDereferenceMessageQueue(MessageQueue);
                 break;
@@ -942,7 +942,7 @@
   {
     PVOID WaitObjects[2];
     
-    WaitObjects[0] = &Message->CompletionEvent;
+    WaitObjects[0] = &CompletionEvent;
     WaitObjects[1] = &ThreadQueue->NewMessages;
     do
       {
@@ -959,11 +959,10 @@
                 if ((PUSER_SENT_MESSAGE) CONTAINING_RECORD(Entry, USER_SENT_MESSAGE, ListEntry)
                     == Message)
                   {
-                    IntLockMessageQueue(ThreadQueue);
-                    /* we can access Message here, it's secure because the sender message queue is locked
+                    /* we can access Message here, it's secure because the message queue is locked
                        and the message is still hasn't been dispatched */
-                    Message->Flags &= ~USMF_WAKE_SENDER;
-                    IntUnLockMessageQueue(ThreadQueue);
+		    Message->CompletionEvent = NULL;
+                    Message->Result = NULL;
                     break;
                   }
                 Entry = Entry->Flink;
@@ -983,7 +982,8 @@
                        and the message has definitely not yet been destroyed, otherwise it would
                        have been removed from this list by the dispatching routine right after
 		       dispatching the message */
-                    Message->Flags &= ~USMF_WAKE_SENDER;
+		    Message->CompletionEvent = NULL;
+                    Message->Result = NULL;
                     RemoveEntryList(&Message->DispatchingListEntry);
                     IntDereferenceMessageQueue(MessageQueue);
                     break;
@@ -1001,13 +1001,7 @@
   }
   
   if(WaitStatus != STATUS_TIMEOUT)
-  {
-    *uResult = (STATUS_WAIT_0 == WaitStatus ? Message->Result : -1);
-  }
-  else
-  {
-    IntDereferenceMessageQueue(ThreadQueue);
-  }
+    *uResult = (STATUS_WAIT_0 == WaitStatus ? Result : -1);
   
   return WaitStatus;
 }
@@ -1165,9 +1159,9 @@
       }
       
       /* wake the sender's thread */
-      if (CurrentSentMessage->Flags & USMF_WAKE_SENDER)
+      if (CurrentSentMessage->CompletionEvent != NULL)
       {
-        KeSetEvent(&CurrentSentMessage->CompletionEvent, IO_NO_INCREMENT, FALSE);
+        KeSetEvent(CurrentSentMessage->CompletionEvent, IO_NO_INCREMENT, FALSE);
       }
       
       /* dereference our message queue */
@@ -1188,9 +1182,9 @@
       DPRINT("Notify the sender, the thread has been terminated while dispatching a message!\n");
       
       /* wake the sender's thread */
-      if (CurrentSentMessage->Flags & USMF_WAKE_SENDER)
+      if (CurrentSentMessage->CompletionEvent != NULL)
       {
-        KeSetEvent(&CurrentSentMessage->CompletionEvent, IO_NO_INCREMENT, FALSE);
+        KeSetEvent(CurrentSentMessage->CompletionEvent, IO_NO_INCREMENT, FALSE);
       }
       
       /* dereference our message queue */

reactos/subsys/win32k/ntuser
timer.c 1.34 -> 1.35
diff -u -r1.34 -r1.35
--- timer.c	30 Jul 2004 09:16:06 -0000	1.34
+++ timer.c	4 Aug 2004 22:31:17 -0000	1.35
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: timer.c,v 1.34 2004/07/30 09:16:06 weiden Exp $
+/* $Id: timer.c,v 1.35 2004/08/04 22:31:17 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -85,11 +85,10 @@
 
 //must hold mutex while calling this
 PMSG_TIMER_ENTRY FASTCALL
-IntRemoveTimer(HWND hWnd, UINT_PTR IDEvent, BOOL SysTimer)
+IntRemoveTimer(HWND hWnd, UINT_PTR IDEvent, HANDLE ThreadID, BOOL SysTimer)
 {
   PMSG_TIMER_ENTRY MsgTimer;
   PLIST_ENTRY EnumEntry;
-  PUSER_MESSAGE_QUEUE MessageQueue = PsGetWin32Thread()->MessageQueue;
   
   //remove timer if already in the queue
   EnumEntry = TimerListHead.Flink;
@@ -100,7 +99,7 @@
       
     if (MsgTimer->Msg.hwnd == hWnd && 
         MsgTimer->Msg.wParam == (WPARAM)IDEvent &&
-        MsgTimer->MessageQueue == MessageQueue &&
+        MsgTimer->ThreadID == ThreadID &&
         (MsgTimer->Msg.message == WM_SYSTIMER) == SysTimer)
     {
       RemoveEntryList(&MsgTimer->ListEntry);
@@ -116,16 +115,11 @@
  * NOTE: It doesn't kill the timer. It just removes them from the list.
  */
 VOID FASTCALL
-RemoveTimersThread(PUSER_MESSAGE_QUEUE MessageQueue)
+RemoveTimersThread(HANDLE ThreadID)
 {
   PMSG_TIMER_ENTRY MsgTimer;
   PLIST_ENTRY EnumEntry;
   
-  if(MessageQueue == NULL)
-  {
-    return;
-  }
-  
   IntLockTimerList();
   
   EnumEntry = TimerListHead.Flink;
@@ -134,7 +128,7 @@
     MsgTimer = CONTAINING_RECORD(EnumEntry, MSG_TIMER_ENTRY, ListEntry);
     EnumEntry = EnumEntry->Flink;
     
-    if (MsgTimer->MessageQueue == MessageQueue)
+    if (MsgTimer->ThreadID == ThreadID)
     {
       if (MsgTimer->Msg.hwnd == NULL)
       {
@@ -142,9 +136,6 @@
       }
       
       RemoveEntryList(&MsgTimer->ListEntry);
-      
-      IntDereferenceMessageQueue(MsgTimer->MessageQueue);
-      
       ExFreePool(MsgTimer);
     }
   }
@@ -173,9 +164,6 @@
     if (MsgTimer->Msg.hwnd == Wnd)
     {
       RemoveEntryList(&MsgTimer->ListEntry);
-      
-      IntDereferenceMessageQueue(MsgTimer->MessageQueue);
-      
       ExFreePool(MsgTimer);
     }
   }
@@ -191,8 +179,10 @@
   PMSG_TIMER_ENTRY NewTimer;
   LARGE_INTEGER CurrentTime;
   PWINDOW_OBJECT WindowObject;
+  HANDLE ThreadID;
   UINT_PTR Ret = 0;
  
+  ThreadID = PsGetCurrentThreadId();
   KeQuerySystemTime(&CurrentTime);
   IntLockTimerList();
   
@@ -229,7 +219,7 @@
     IntReleaseWindowObject(WindowObject);
     
     /* remove timer if already in the queue */
-    MsgTimer = IntRemoveTimer(hWnd, nIDEvent, SystemTimer);
+    MsgTimer = IntRemoveTimer(hWnd, nIDEvent, ThreadID, SystemTimer); 
   }
   
   #if 1
@@ -276,9 +266,7 @@
     NewTimer->Msg.lParam = (LPARAM)lpTimerFunc;
     NewTimer->Period = uElapse;
     NewTimer->Timeout.QuadPart = CurrentTime.QuadPart + (uElapse * 10000);
-    NewTimer->MessageQueue = PsGetWin32Thread()->MessageQueue;
-    
-    IntReferenceMessageQueue(NewTimer->MessageQueue);
+    NewTimer->ThreadID = ThreadID;
   }
   
   Ret = nIDEvent; // FIXME - return lpTimerProc if it's not a system timer
@@ -334,7 +322,7 @@
     IntReleaseWindowObject(WindowObject);
   }
   
-  MsgTimer = IntRemoveTimer(hWnd, uIDEvent, SystemTimer);
+  MsgTimer = IntRemoveTimer(hWnd, uIDEvent, PsGetCurrentThreadId(), SystemTimer);
   
   IntUnLockTimerList();
   
@@ -345,8 +333,6 @@
     return FALSE;
   }
   
-  IntReferenceMessageQueue(MsgTimer->MessageQueue);
-  
   /* FIXME: use lookaside? */
   ExFreePool(MsgTimer);
   
@@ -360,6 +346,9 @@
   LARGE_INTEGER CurrentTime;
   PLIST_ENTRY EnumEntry;
   PMSG_TIMER_ENTRY MsgTimer;
+  PETHREAD Thread;
+  PETHREAD *ThreadsToDereference;
+  ULONG ThreadsToDereferenceCount, ThreadsToDereferencePos, i;
   
   for(;;)
   {
@@ -374,6 +363,8 @@
       KEBUGCHECK(0);
     }
     
+    ThreadsToDereferenceCount = ThreadsToDereferencePos = 0;
+    
     IntLockTimerList();
     
     KeQuerySystemTime(&CurrentTime);
@@ -383,10 +374,16 @@
          EnumEntry = EnumEntry->Flink)
     {
        MsgTimer = CONTAINING_RECORD(EnumEntry, MSG_TIMER_ENTRY, ListEntry);
-       if (CurrentTime.QuadPart < MsgTimer->Timeout.QuadPart)
+       if (CurrentTime.QuadPart >= MsgTimer->Timeout.QuadPart)
+          ++ThreadsToDereferenceCount;
+       else
           break;
     }
 
+
+    ThreadsToDereference = (PETHREAD *)ExAllocatePoolWithTag(
+       NonPagedPool, ThreadsToDereferenceCount * sizeof(PETHREAD), TAG_TIMERTD);
+
     EnumEntry = TimerListHead.Flink;
     while (EnumEntry != &TimerListHead)
     {
@@ -402,7 +399,16 @@
          * FIXME: 1) Find a faster way of getting the thread message queue? (lookup by id is slow)
          */
         
-        MsqPostMessage(MsgTimer->MessageQueue, &MsgTimer->Msg, FALSE);
+        if (!NT_SUCCESS(PsLookupThreadByThreadId(MsgTimer->ThreadID, &Thread)))
+        {
+          ExFreePool(MsgTimer);
+          continue;
+        }
+        
+        MsqPostMessage(((PW32THREAD)Thread->Win32Thread)->MessageQueue, &MsgTimer->Msg, FALSE);
+        
+        ThreadsToDereference[ThreadsToDereferencePos] = Thread;
+        ++ThreadsToDereferencePos;
         
         //set up next periodic timeout
         //FIXME: is this calculation really necesary (and correct)? -Gunnar
@@ -429,6 +435,11 @@
     }
     
     IntUnLockTimerList();
+
+    for (i = 0; i < ThreadsToDereferencePos; i++)
+       ObDereferenceObject(ThreadsToDereference[i]);
+
+     ExFreePool(ThreadsToDereference);
   }
 }
 
CVSspam 0.2.8