1 /* * Message queues related functions
3 * Copyright 1993, 1994 Alexandre Julliard
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
19 #include "debugtools.h"
23 DECLARE_DEBUG_CHANNEL(msg
);
24 DECLARE_DEBUG_CHANNEL(sendmsg
);
26 #define MAX_QUEUE_SIZE 120 /* Max. size of a message queue */
28 static HQUEUE16 hFirstQueue
= 0;
29 static HQUEUE16 hExitingQueue
= 0;
30 static HQUEUE16 hmemSysMsgQueue
= 0;
31 static MESSAGEQUEUE
*sysMsgQueue
= NULL
;
32 static PERQUEUEDATA
*pQDataWin16
= NULL
; /* Global perQData for Win16 tasks */
34 static MESSAGEQUEUE
*pMouseQueue
= NULL
; /* Queue for last mouse message */
35 static MESSAGEQUEUE
*pKbdQueue
= NULL
; /* Queue for last kbd message */
37 HQUEUE16 hCursorQueue
= 0;
38 HQUEUE16 hActiveQueue
= 0;
41 /***********************************************************************
42 * PERQDATA_CreateInstance
44 * Creates an instance of a reference counted PERQUEUEDATA element
45 * for the message queue. perQData is stored globally for 16 bit tasks.
47 * Note: We don't implement perQdata exactly the same way Windows does.
48 * Each perQData element is reference counted since it may be potentially
49 * shared by multiple message Queues (via AttachThreadInput).
50 * We only store the current values for Active, Capture and focus windows
53 PERQUEUEDATA
* PERQDATA_CreateInstance( )
61 /* Share a single instance of perQData for all 16 bit tasks */
62 if ( ( bIsWin16
= THREAD_IsWin16( NtCurrentTeb() ) ) )
64 /* If previously allocated, just bump up ref count */
67 PERQDATA_Addref( pQDataWin16
);
72 /* Allocate PERQUEUEDATA from the system heap */
73 if (!( pQData
= (PERQUEUEDATA
*) HeapAlloc( SystemHeap
, 0,
74 sizeof(PERQUEUEDATA
) ) ))
78 pQData
->hWndCapture
= pQData
->hWndFocus
= pQData
->hWndActive
= 0;
79 pQData
->ulRefCount
= 1;
80 pQData
->nCaptureHT
= HTCLIENT
;
82 /* Note: We have an independent critical section for the per queue data
83 * since this may be shared by different threads. see AttachThreadInput()
85 InitializeCriticalSection( &pQData
->cSection
);
86 /* FIXME: not all per queue data critical sections should be global */
87 MakeCriticalSectionGlobal( &pQData
->cSection
);
89 /* Save perQData globally for 16 bit tasks */
97 /***********************************************************************
100 * Increment reference count for the PERQUEUEDATA instance
101 * Returns reference count for debugging purposes
103 ULONG
PERQDATA_Addref( PERQUEUEDATA
*pQData
)
105 assert(pQData
!= 0 );
106 TRACE_(msg
)("(): current refcount %lu ...\n", pQData
->ulRefCount
);
108 EnterCriticalSection( &pQData
->cSection
);
109 ++pQData
->ulRefCount
;
110 LeaveCriticalSection( &pQData
->cSection
);
112 return pQData
->ulRefCount
;
116 /***********************************************************************
119 * Release a reference to a PERQUEUEDATA instance.
120 * Destroy the instance if no more references exist
121 * Returns reference count for debugging purposes
123 ULONG
PERQDATA_Release( PERQUEUEDATA
*pQData
)
125 assert(pQData
!= 0 );
126 TRACE_(msg
)("(): current refcount %lu ...\n",
127 (LONG
)pQData
->ulRefCount
);
129 EnterCriticalSection( &pQData
->cSection
);
130 if ( --pQData
->ulRefCount
== 0 )
132 LeaveCriticalSection( &pQData
->cSection
);
133 DeleteCriticalSection( &pQData
->cSection
);
135 TRACE_(msg
)("(): deleting PERQUEUEDATA instance ...\n" );
137 /* Deleting our global 16 bit perQData? */
138 if ( pQData
== pQDataWin16
)
141 /* Free the PERQUEUEDATA instance */
142 HeapFree( SystemHeap
, 0, pQData
);
146 LeaveCriticalSection( &pQData
->cSection
);
148 return pQData
->ulRefCount
;
152 /***********************************************************************
153 * PERQDATA_GetFocusWnd
155 * Get the focus hwnd member in a threadsafe manner
157 HWND
PERQDATA_GetFocusWnd( PERQUEUEDATA
*pQData
)
160 assert(pQData
!= 0 );
162 EnterCriticalSection( &pQData
->cSection
);
163 hWndFocus
= pQData
->hWndFocus
;
164 LeaveCriticalSection( &pQData
->cSection
);
170 /***********************************************************************
171 * PERQDATA_SetFocusWnd
173 * Set the focus hwnd member in a threadsafe manner
175 HWND
PERQDATA_SetFocusWnd( PERQUEUEDATA
*pQData
, HWND hWndFocus
)
178 assert(pQData
!= 0 );
180 EnterCriticalSection( &pQData
->cSection
);
181 hWndFocusPrv
= pQData
->hWndFocus
;
182 pQData
->hWndFocus
= hWndFocus
;
183 LeaveCriticalSection( &pQData
->cSection
);
189 /***********************************************************************
190 * PERQDATA_GetActiveWnd
192 * Get the active hwnd member in a threadsafe manner
194 HWND
PERQDATA_GetActiveWnd( PERQUEUEDATA
*pQData
)
197 assert(pQData
!= 0 );
199 EnterCriticalSection( &pQData
->cSection
);
200 hWndActive
= pQData
->hWndActive
;
201 LeaveCriticalSection( &pQData
->cSection
);
207 /***********************************************************************
208 * PERQDATA_SetActiveWnd
210 * Set the active focus hwnd member in a threadsafe manner
212 HWND
PERQDATA_SetActiveWnd( PERQUEUEDATA
*pQData
, HWND hWndActive
)
215 assert(pQData
!= 0 );
217 EnterCriticalSection( &pQData
->cSection
);
218 hWndActivePrv
= pQData
->hWndActive
;
219 pQData
->hWndActive
= hWndActive
;
220 LeaveCriticalSection( &pQData
->cSection
);
222 return hWndActivePrv
;
226 /***********************************************************************
227 * PERQDATA_GetCaptureWnd
229 * Get the capture hwnd member in a threadsafe manner
231 HWND
PERQDATA_GetCaptureWnd( PERQUEUEDATA
*pQData
)
234 assert(pQData
!= 0 );
236 EnterCriticalSection( &pQData
->cSection
);
237 hWndCapture
= pQData
->hWndCapture
;
238 LeaveCriticalSection( &pQData
->cSection
);
244 /***********************************************************************
245 * PERQDATA_SetCaptureWnd
247 * Set the capture hwnd member in a threadsafe manner
249 HWND
PERQDATA_SetCaptureWnd( PERQUEUEDATA
*pQData
, HWND hWndCapture
)
252 assert(pQData
!= 0 );
254 EnterCriticalSection( &pQData
->cSection
);
255 hWndCapturePrv
= pQData
->hWndCapture
;
256 pQData
->hWndCapture
= hWndCapture
;
257 LeaveCriticalSection( &pQData
->cSection
);
259 return hWndCapturePrv
;
263 /***********************************************************************
264 * PERQDATA_GetCaptureInfo
266 * Get the capture info member in a threadsafe manner
268 INT16
PERQDATA_GetCaptureInfo( PERQUEUEDATA
*pQData
)
271 assert(pQData
!= 0 );
273 EnterCriticalSection( &pQData
->cSection
);
274 nCaptureHT
= pQData
->nCaptureHT
;
275 LeaveCriticalSection( &pQData
->cSection
);
281 /***********************************************************************
282 * PERQDATA_SetCaptureInfo
284 * Set the capture info member in a threadsafe manner
286 INT16
PERQDATA_SetCaptureInfo( PERQUEUEDATA
*pQData
, INT16 nCaptureHT
)
289 assert(pQData
!= 0 );
291 EnterCriticalSection( &pQData
->cSection
);
292 nCaptureHTPrv
= pQData
->nCaptureHT
;
293 pQData
->nCaptureHT
= nCaptureHT
;
294 LeaveCriticalSection( &pQData
->cSection
);
296 return nCaptureHTPrv
;
300 /***********************************************************************
303 * Function for getting a 32 bit pointer on queue structure. For thread
304 * safeness programmers should use this function instead of GlobalLock to
305 * retrieve a pointer on the structure. QUEUE_Unlock should also be called
306 * when access to the queue structure is not required anymore.
308 MESSAGEQUEUE
*QUEUE_Lock( HQUEUE16 hQueue
)
312 HeapLock( SystemHeap
); /* FIXME: a bit overkill */
313 queue
= GlobalLock16( hQueue
);
314 if ( !queue
|| (queue
->magic
!= QUEUE_MAGIC
) )
316 HeapUnlock( SystemHeap
);
321 HeapUnlock( SystemHeap
);
326 /***********************************************************************
329 * Use with QUEUE_Lock to get a thread safe access to message queue
332 void QUEUE_Unlock( MESSAGEQUEUE
*queue
)
336 HeapLock( SystemHeap
); /* FIXME: a bit overkill */
338 if ( --queue
->lockCount
== 0 )
340 DeleteCriticalSection ( &queue
->cSection
);
341 if (queue
->server_queue
)
342 CloseHandle( queue
->server_queue
);
343 GlobalFree16( queue
->self
);
346 HeapUnlock( SystemHeap
);
351 /***********************************************************************
354 void QUEUE_DumpQueue( HQUEUE16 hQueue
)
358 if (!(pq
= (MESSAGEQUEUE
*) QUEUE_Lock( hQueue
)) )
360 WARN_(msg
)("%04x is not a queue handle\n", hQueue
);
364 DPRINTF( "next: %12.4x Intertask SendMessage:\n"
365 "thread: %10p ----------------------\n"
366 "firstMsg: %8p smWaiting: %10p\n"
367 "lastMsg: %8p smPending: %10p\n"
368 "msgCount: %8.4x smProcessing: %10p\n"
375 pq
->next
, pq
->teb
, pq
->firstMsg
, pq
->smWaiting
, pq
->lastMsg
,
376 pq
->smPending
, pq
->msgCount
, pq
->smProcessing
,
377 (unsigned)pq
->lockCount
, pq
->wPaintCount
, pq
->wTimerCount
,
378 pq
->wakeBits
, pq
->wakeMask
, pq
->hCurHook
);
384 /***********************************************************************
387 void QUEUE_WalkQueues(void)
390 HQUEUE16 hQueue
= hFirstQueue
;
392 DPRINTF( "Queue Msgs Thread Task Module\n" );
395 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
398 WARN_(msg
)("Bad queue handle %04x\n", hQueue
);
401 if (!GetModuleName16( queue
->teb
->htask16
, module
, sizeof(module
)))
402 strcpy( module
, "???" );
403 DPRINTF( "%04x %4d %p %04x %s\n", hQueue
,queue
->msgCount
,
404 queue
->teb
, queue
->teb
->htask16
, module
);
405 hQueue
= queue
->next
;
406 QUEUE_Unlock( queue
);
412 /***********************************************************************
413 * QUEUE_IsExitingQueue
415 BOOL
QUEUE_IsExitingQueue( HQUEUE16 hQueue
)
417 return (hExitingQueue
&& (hQueue
== hExitingQueue
));
421 /***********************************************************************
422 * QUEUE_SetExitingQueue
424 void QUEUE_SetExitingQueue( HQUEUE16 hQueue
)
426 hExitingQueue
= hQueue
;
430 /***********************************************************************
431 * QUEUE_CreateMsgQueue
433 * Creates a message queue. Doesn't link it into queue list!
435 static HQUEUE16
QUEUE_CreateMsgQueue( BOOL16 bCreatePerQData
)
439 MESSAGEQUEUE
* msgQueue
;
441 TRACE_(msg
)("(): Creating message queue...\n");
443 if (!(hQueue
= GlobalAlloc16( GMEM_FIXED
| GMEM_ZEROINIT
,
444 sizeof(MESSAGEQUEUE
) )))
447 msgQueue
= (MESSAGEQUEUE
*) GlobalLock16( hQueue
);
453 struct get_msg_queue_request
*req
= server_alloc_req( sizeof(*req
), 0 );
454 server_call( REQ_GET_MSG_QUEUE
);
455 handle
= req
->handle
;
460 ERR_(msg
)("Cannot get thread queue");
461 GlobalFree16( hQueue
);
464 msgQueue
->server_queue
= handle
;
465 msgQueue
->server_queue
= ConvertToGlobalHandle( msgQueue
->server_queue
);
467 msgQueue
->self
= hQueue
;
468 msgQueue
->wakeBits
= msgQueue
->changeBits
= 0;
470 InitializeCriticalSection( &msgQueue
->cSection
);
471 MakeCriticalSectionGlobal( &msgQueue
->cSection
);
473 msgQueue
->lockCount
= 1;
474 msgQueue
->magic
= QUEUE_MAGIC
;
476 /* Create and initialize our per queue data */
477 msgQueue
->pQData
= bCreatePerQData
? PERQDATA_CreateInstance() : NULL
;
483 /***********************************************************************
486 * Try to reply to all pending sent messages on exit.
488 static void QUEUE_FlushMessages( MESSAGEQUEUE
*queue
)
491 MESSAGEQUEUE
*senderQ
= 0;
495 EnterCriticalSection( &queue
->cSection
);
497 /* empty the list of pending SendMessage waiting to be received */
498 while (queue
->smPending
)
500 smsg
= QUEUE_RemoveSMSG( queue
, SM_PENDING_LIST
, 0);
502 senderQ
= (MESSAGEQUEUE
*)QUEUE_Lock( smsg
->hSrcQueue
);
506 /* return 0, to unblock other thread */
508 smsg
->flags
|= SMSG_HAVE_RESULT
;
509 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
511 QUEUE_Unlock( senderQ
);
514 QUEUE_ClearWakeBit( queue
, QS_SENDMESSAGE
);
516 LeaveCriticalSection( &queue
->cSection
);
521 /***********************************************************************
522 * QUEUE_DeleteMsgQueue
524 * Unlinks and deletes a message queue.
526 * Note: We need to mask asynchronous events to make sure PostMessage works
527 * even in the signal handler.
529 BOOL
QUEUE_DeleteMsgQueue( HQUEUE16 hQueue
)
531 MESSAGEQUEUE
* msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock(hQueue
);
534 TRACE_(msg
)("(): Deleting message queue %04x\n", hQueue
);
536 if (!hQueue
|| !msgQueue
)
538 ERR_(msg
)("invalid argument.\n");
544 if( hCursorQueue
== hQueue
) hCursorQueue
= 0;
545 if( hActiveQueue
== hQueue
) hActiveQueue
= 0;
547 /* flush sent messages */
548 QUEUE_FlushMessages( msgQueue
);
550 HeapLock( SystemHeap
); /* FIXME: a bit overkill */
552 /* Release per queue data if present */
553 if ( msgQueue
->pQData
)
555 PERQDATA_Release( msgQueue
->pQData
);
556 msgQueue
->pQData
= 0;
559 /* remove the message queue from the global link list */
560 pPrev
= &hFirstQueue
;
561 while (*pPrev
&& (*pPrev
!= hQueue
))
563 MESSAGEQUEUE
*msgQ
= (MESSAGEQUEUE
*)GlobalLock16(*pPrev
);
566 if ( !msgQ
|| (msgQ
->magic
!= QUEUE_MAGIC
) )
568 /* HQUEUE link list is corrupted, try to exit gracefully */
569 ERR_(msg
)("HQUEUE link list corrupted!\n");
575 if (pPrev
&& *pPrev
) *pPrev
= msgQueue
->next
;
578 HeapUnlock( SystemHeap
);
580 /* free up resource used by MESSAGEQUEUE structure */
581 msgQueue
->lockCount
--;
582 QUEUE_Unlock( msgQueue
);
588 /***********************************************************************
589 * QUEUE_CreateSysMsgQueue
591 * Create the system message queue, and set the double-click speed.
592 * Must be called only once.
594 BOOL
QUEUE_CreateSysMsgQueue( int size
)
596 /* Note: We dont need perQ data for the system message queue */
597 if (!(hmemSysMsgQueue
= QUEUE_CreateMsgQueue( FALSE
)))
600 sysMsgQueue
= (MESSAGEQUEUE
*) GlobalLock16( hmemSysMsgQueue
);
605 /***********************************************************************
608 MESSAGEQUEUE
*QUEUE_GetSysQueue(void)
614 /***********************************************************************
617 * See "Windows Internals", p.449
619 void QUEUE_SetWakeBit( MESSAGEQUEUE
*queue
, WORD bit
)
621 TRACE_(msg
)("queue = %04x (wm=%04x), bit = %04x\n",
622 queue
->self
, queue
->wakeMask
, bit
);
624 if (bit
& QS_MOUSE
) pMouseQueue
= queue
;
625 if (bit
& QS_KEY
) pKbdQueue
= queue
;
626 queue
->changeBits
|= bit
;
627 queue
->wakeBits
|= bit
;
628 if (queue
->wakeMask
& bit
)
632 /* Wake up thread waiting for message */
633 if ( THREAD_IsWin16( queue
->teb
) )
635 int iWndsLock
= WIN_SuspendWndsLock();
636 PostEvent16( queue
->teb
->htask16
);
637 WIN_RestoreWndsLock( iWndsLock
);
643 struct wake_queue_request
*req
= server_alloc_req( sizeof(*req
), 0 );
644 req
->handle
= queue
->server_queue
;
646 server_call( REQ_WAKE_QUEUE
);
654 /***********************************************************************
657 void QUEUE_ClearWakeBit( MESSAGEQUEUE
*queue
, WORD bit
)
659 queue
->changeBits
&= ~bit
;
660 queue
->wakeBits
&= ~bit
;
664 /***********************************************************************
667 * See "Windows Internals", p.447
670 * 0 if exit with timeout
673 int QUEUE_WaitBits( WORD bits
, DWORD timeout
)
679 TRACE_(msg
)("q %04x waiting for %04x\n", GetFastQueue16(), bits
);
681 if ( THREAD_IsWin16( NtCurrentTeb() ) && (timeout
!= INFINITE
) )
682 curTime
= GetTickCount();
684 hQueue
= GetFastQueue16();
685 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
))) return 0;
689 if (queue
->changeBits
& bits
)
691 /* One of the bits is set; we can return */
693 QUEUE_Unlock( queue
);
696 if (queue
->wakeBits
& QS_SENDMESSAGE
)
698 /* Process the sent message immediately */
701 QUEUE_ReceiveMessage( queue
);
702 continue; /* nested sm crux */
705 queue
->wakeMask
= bits
| QS_SENDMESSAGE
;
706 if(queue
->changeBits
& bits
)
711 TRACE_(msg
)("%04x) wakeMask is %04x, waiting\n", queue
->self
, queue
->wakeMask
);
713 if ( !THREAD_IsWin16( NtCurrentTeb() ) )
718 if ( (bHasWin16Lock
= _ConfirmWin16Lock()) )
720 TRACE_(msg
)("bHasWin16Lock=TRUE\n");
721 ReleaseThunkLock( &dwlc
);
724 WaitForSingleObject( queue
->server_queue
, timeout
);
728 RestoreThunkLock( dwlc
);
733 if ( timeout
== INFINITE
)
734 WaitEvent16( 0 ); /* win 16 thread, use WaitEvent */
737 /* check for timeout, then give control to other tasks */
738 if (GetTickCount() - curTime
> timeout
)
741 QUEUE_Unlock( queue
);
742 return 0; /* exit with timeout */
751 /***********************************************************************
754 * This routine is called when a SMSG need to be added to one of the three
755 * SM list. (SM_PROCESSING_LIST, SM_PENDING_LIST, SM_WAITING_LIST)
757 BOOL
QUEUE_AddSMSG( MESSAGEQUEUE
*queue
, int list
, SMSG
*smsg
)
759 TRACE_(sendmsg
)("queue=%x, list=%d, smsg=%p msg=%s\n", queue
->self
, list
,
760 smsg
, SPY_GetMsgName(smsg
->msg
));
764 case SM_PROCESSING_LIST
:
765 /* don't need to be thread safe, only accessed by the
766 thread associated with the sender queue */
767 smsg
->nextProcessing
= queue
->smProcessing
;
768 queue
->smProcessing
= smsg
;
771 case SM_WAITING_LIST
:
772 /* don't need to be thread safe, only accessed by the
773 thread associated with the receiver queue */
774 smsg
->nextWaiting
= queue
->smWaiting
;
775 queue
->smWaiting
= smsg
;
778 case SM_PENDING_LIST
:
780 /* make it thread safe, could be accessed by the sender and
784 EnterCriticalSection( &queue
->cSection
);
785 smsg
->nextPending
= NULL
;
786 prev
= &queue
->smPending
;
788 prev
= &(*prev
)->nextPending
;
790 LeaveCriticalSection( &queue
->cSection
);
792 QUEUE_SetWakeBit( queue
, QS_SENDMESSAGE
);
797 ERR_(sendmsg
)("Invalid list: %d", list
);
805 /***********************************************************************
808 * This routine is called when a SMSG needs to be removed from one of the three
809 * SM lists (SM_PROCESSING_LIST, SM_PENDING_LIST, SM_WAITING_LIST).
810 * If smsg == 0, remove the first smsg from the specified list
812 SMSG
*QUEUE_RemoveSMSG( MESSAGEQUEUE
*queue
, int list
, SMSG
*smsg
)
817 case SM_PROCESSING_LIST
:
818 /* don't need to be thread safe, only accessed by the
819 thread associated with the sender queue */
821 /* if smsg is equal to null, it means the first in the list */
823 smsg
= queue
->smProcessing
;
825 TRACE_(sendmsg
)("queue=%x, list=%d, smsg=%p msg=%s\n", queue
->self
, list
,
826 smsg
, SPY_GetMsgName(smsg
->msg
));
827 /* In fact SM_PROCESSING_LIST is a stack, and smsg
828 should be always at the top of the list */
829 if ( (smsg
!= queue
->smProcessing
) || !queue
->smProcessing
)
831 ERR_(sendmsg
)("smsg not at the top of Processing list, smsg=0x%p queue=0x%p\n", smsg
, queue
);
836 queue
->smProcessing
= smsg
->nextProcessing
;
837 smsg
->nextProcessing
= 0;
841 case SM_WAITING_LIST
:
842 /* don't need to be thread safe, only accessed by the
843 thread associated with the receiver queue */
845 /* if smsg is equal to null, it means the first in the list */
847 smsg
= queue
->smWaiting
;
849 TRACE_(sendmsg
)("queue=%x, list=%d, smsg=%p msg=%s\n", queue
->self
, list
,
850 smsg
, SPY_GetMsgName(smsg
->msg
));
851 /* In fact SM_WAITING_LIST is a stack, and smsg
852 should be always at the top of the list */
853 if ( (smsg
!= queue
->smWaiting
) || !queue
->smWaiting
)
855 ERR_(sendmsg
)("smsg not at the top of Waiting list, smsg=0x%p queue=0x%p\n", smsg
, queue
);
860 queue
->smWaiting
= smsg
->nextWaiting
;
861 smsg
->nextWaiting
= 0;
865 case SM_PENDING_LIST
:
866 /* make it thread safe, could be accessed by the sender and
868 EnterCriticalSection( &queue
->cSection
);
871 smsg
= queue
->smPending
;
872 if ( (smsg
!= queue
->smPending
) || !queue
->smPending
)
874 ERR_(sendmsg
)("should always remove the top one in Pending list, smsg=0x%p queue=0x%p\n", smsg
, queue
);
875 LeaveCriticalSection( &queue
->cSection
);
879 TRACE_(sendmsg
)("queue=%x, list=%d, smsg=%p msg=%s\n", queue
->self
, list
,
880 smsg
, SPY_GetMsgName(smsg
->msg
));
882 queue
->smPending
= smsg
->nextPending
;
883 smsg
->nextPending
= 0;
885 /* if no more SMSG in Pending list, clear QS_SENDMESSAGE flag */
886 if (!queue
->smPending
)
887 QUEUE_ClearWakeBit( queue
, QS_SENDMESSAGE
);
889 LeaveCriticalSection( &queue
->cSection
);
893 ERR_(sendmsg
)("Invalid list: %d\n", list
);
901 /***********************************************************************
902 * QUEUE_ReceiveMessage
904 * This routine is called when a sent message is waiting for the queue.
906 void QUEUE_ReceiveMessage( MESSAGEQUEUE
*queue
)
910 MESSAGEQUEUE
*senderQ
;
912 TRACE_(sendmsg
)("queue %04x\n", queue
->self
);
914 if ( !((queue
->wakeBits
& QS_SENDMESSAGE
) && queue
->smPending
) )
916 TRACE_(sendmsg
)("\trcm: nothing to do\n");
920 /* remove smsg on the top of the pending list and put it in the processing list */
921 smsg
= QUEUE_RemoveSMSG(queue
, SM_PENDING_LIST
, 0);
922 QUEUE_AddSMSG(queue
, SM_WAITING_LIST
, smsg
);
924 TRACE_(sendmsg
)("RM: %s [%04x] (%04x -> %04x)\n",
925 SPY_GetMsgName(smsg
->msg
), smsg
->msg
, smsg
->hSrcQueue
, smsg
->hDstQueue
);
927 if (IsWindow( smsg
->hWnd
))
929 WND
*wndPtr
= WIN_FindWndPtr( smsg
->hWnd
);
930 DWORD extraInfo
= queue
->GetMessageExtraInfoVal
; /* save ExtraInfo */
932 /* use sender queue extra info value while calling the window proc */
933 senderQ
= (MESSAGEQUEUE
*)QUEUE_Lock( smsg
->hSrcQueue
);
936 queue
->GetMessageExtraInfoVal
= senderQ
->GetMessageExtraInfoVal
;
937 QUEUE_Unlock( senderQ
);
940 /* call the right version of CallWindowProcXX */
941 if (smsg
->flags
& SMSG_WIN32
)
943 TRACE_(sendmsg
)("\trcm: msg is Win32\n" );
944 if (smsg
->flags
& SMSG_UNICODE
)
945 result
= CallWindowProcW( wndPtr
->winproc
,
946 smsg
->hWnd
, smsg
->msg
,
947 smsg
->wParam
, smsg
->lParam
);
949 result
= CallWindowProcA( wndPtr
->winproc
,
950 smsg
->hWnd
, smsg
->msg
,
951 smsg
->wParam
, smsg
->lParam
);
953 else /* Win16 message */
954 result
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
957 LOWORD (smsg
->wParam
),
960 queue
->GetMessageExtraInfoVal
= extraInfo
; /* Restore extra info */
961 WIN_ReleaseWndPtr(wndPtr
);
962 TRACE_(sendmsg
)("result = %08x\n", (unsigned)result
);
964 else WARN_(sendmsg
)("\trcm: bad hWnd\n");
967 /* set SMSG_SENDING_REPLY flag to tell ReplyMessage16, it's not
969 smsg
->flags
|= SMSG_SENDING_REPLY
;
970 ReplyMessage( result
);
972 TRACE_(sendmsg
)("done!\n" );
977 /***********************************************************************
980 * Add a message to the queue. Return FALSE if queue is full.
982 BOOL
QUEUE_AddMsg( HQUEUE16 hQueue
, int type
, MSG
*msg
, DWORD extraInfo
)
984 MESSAGEQUEUE
*msgQueue
;
988 if (!(msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
))) return FALSE
;
990 /* allocate new message in global heap for now */
991 if (!(qmsg
= (QMSG
*) HeapAlloc( SystemHeap
, 0, sizeof(QMSG
) ) ))
993 QUEUE_Unlock( msgQueue
);
997 EnterCriticalSection( &msgQueue
->cSection
);
1002 qmsg
->extraInfo
= extraInfo
;
1004 /* insert the message in the link list */
1006 qmsg
->prevMsg
= msgQueue
->lastMsg
;
1008 if (msgQueue
->lastMsg
)
1009 msgQueue
->lastMsg
->nextMsg
= qmsg
;
1011 /* update first and last anchor in message queue */
1012 msgQueue
->lastMsg
= qmsg
;
1013 if (!msgQueue
->firstMsg
)
1014 msgQueue
->firstMsg
= qmsg
;
1016 msgQueue
->msgCount
++;
1018 LeaveCriticalSection( &msgQueue
->cSection
);
1020 QUEUE_SetWakeBit( msgQueue
, QS_POSTMESSAGE
);
1021 QUEUE_Unlock( msgQueue
);
1028 /***********************************************************************
1031 * Find a message matching the given parameters. Return -1 if none available.
1033 QMSG
* QUEUE_FindMsg( MESSAGEQUEUE
* msgQueue
, HWND hwnd
, int first
, int last
)
1037 EnterCriticalSection( &msgQueue
->cSection
);
1039 if (!msgQueue
->msgCount
)
1041 else if (!hwnd
&& !first
&& !last
)
1042 qmsg
= msgQueue
->firstMsg
;
1045 /* look in linked list for message matching first and last criteria */
1046 for (qmsg
= msgQueue
->firstMsg
; qmsg
; qmsg
= qmsg
->nextMsg
)
1048 MSG
*msg
= &(qmsg
->msg
);
1050 if (!hwnd
|| (msg
->hwnd
== hwnd
))
1052 if (!first
&& !last
)
1053 break; /* found it */
1055 if ((msg
->message
>= first
) && (!last
|| (msg
->message
<= last
)))
1056 break; /* found it */
1061 LeaveCriticalSection( &msgQueue
->cSection
);
1068 /***********************************************************************
1071 * Remove a message from the queue (pos must be a valid position).
1073 void QUEUE_RemoveMsg( MESSAGEQUEUE
* msgQueue
, QMSG
*qmsg
)
1075 EnterCriticalSection( &msgQueue
->cSection
);
1077 /* set the linked list */
1079 qmsg
->prevMsg
->nextMsg
= qmsg
->nextMsg
;
1082 qmsg
->nextMsg
->prevMsg
= qmsg
->prevMsg
;
1084 if (msgQueue
->firstMsg
== qmsg
)
1085 msgQueue
->firstMsg
= qmsg
->nextMsg
;
1087 if (msgQueue
->lastMsg
== qmsg
)
1088 msgQueue
->lastMsg
= qmsg
->prevMsg
;
1090 /* deallocate the memory for the message */
1091 HeapFree( SystemHeap
, 0, qmsg
);
1093 msgQueue
->msgCount
--;
1094 if (!msgQueue
->msgCount
) msgQueue
->wakeBits
&= ~QS_POSTMESSAGE
;
1096 LeaveCriticalSection( &msgQueue
->cSection
);
1100 /***********************************************************************
1103 * Wake a queue upon reception of a hardware event.
1105 static void QUEUE_WakeSomeone( UINT message
)
1110 HQUEUE16 hQueue
= 0;
1111 MESSAGEQUEUE
*queue
= NULL
;
1114 hQueue
= hCursorQueue
;
1116 if( (message
>= WM_KEYFIRST
) && (message
<= WM_KEYLAST
) )
1120 hQueue
= hActiveQueue
;
1124 wakeBit
= (message
== WM_MOUSEMOVE
) ? QS_MOUSEMOVE
: QS_MOUSEBUTTON
;
1125 if( (hwnd
= GetCapture()) )
1126 if( (wndPtr
= WIN_FindWndPtr( hwnd
)) )
1128 hQueue
= wndPtr
->hmemTaskQ
;
1129 WIN_ReleaseWndPtr(wndPtr
);
1133 if( (hwnd
= GetSysModalWindow16()) )
1135 if( (wndPtr
= WIN_FindWndPtr( hwnd
)) )
1137 hQueue
= wndPtr
->hmemTaskQ
;
1138 WIN_ReleaseWndPtr(wndPtr
);
1143 queue
= QUEUE_Lock( hQueue
);
1147 queue
= QUEUE_Lock( hFirstQueue
);
1150 if (queue
->wakeMask
& wakeBit
) break;
1152 QUEUE_Unlock(queue
);
1153 queue
= QUEUE_Lock( queue
->next
);
1157 WARN_(msg
)("couldn't find queue\n");
1162 QUEUE_SetWakeBit( queue
, wakeBit
);
1164 QUEUE_Unlock( queue
);
1168 /***********************************************************************
1171 * Add an event to the system message queue.
1172 * Note: the position is relative to the desktop window.
1174 void hardware_event( UINT message
, WPARAM wParam
, LPARAM lParam
,
1175 int xPos
, int yPos
, DWORD time
, DWORD extraInfo
)
1181 if (!sysMsgQueue
) return;
1183 EnterCriticalSection( &sysMsgQueue
->cSection
);
1185 /* Merge with previous event if possible */
1186 qmsg
= sysMsgQueue
->lastMsg
;
1188 if ((message
== WM_MOUSEMOVE
) && sysMsgQueue
->lastMsg
)
1190 msg
= &(sysMsgQueue
->lastMsg
->msg
);
1192 if ((msg
->message
== message
) && (msg
->wParam
== wParam
))
1195 qmsg
= sysMsgQueue
->lastMsg
;
1202 /* Should I limit the number of messages in
1203 the system message queue??? */
1205 /* Don't merge allocate a new msg in the global heap */
1207 if (!(qmsg
= (QMSG
*) HeapAlloc( SystemHeap
, 0, sizeof(QMSG
) ) ))
1209 LeaveCriticalSection( &sysMsgQueue
->cSection
);
1213 /* put message at the end of the linked list */
1215 qmsg
->prevMsg
= sysMsgQueue
->lastMsg
;
1217 if (sysMsgQueue
->lastMsg
)
1218 sysMsgQueue
->lastMsg
->nextMsg
= qmsg
;
1220 /* set last and first anchor index in system message queue */
1221 sysMsgQueue
->lastMsg
= qmsg
;
1222 if (!sysMsgQueue
->firstMsg
)
1223 sysMsgQueue
->firstMsg
= qmsg
;
1225 sysMsgQueue
->msgCount
++;
1231 msg
->message
= message
;
1232 msg
->wParam
= wParam
;
1233 msg
->lParam
= lParam
;
1237 qmsg
->extraInfo
= extraInfo
;
1238 qmsg
->type
= QMSG_HARDWARE
;
1240 LeaveCriticalSection( &sysMsgQueue
->cSection
);
1242 QUEUE_WakeSomeone( message
);
1246 /***********************************************************************
1247 * QUEUE_GetQueueTask
1249 HTASK16
QUEUE_GetQueueTask( HQUEUE16 hQueue
)
1253 MESSAGEQUEUE
*queue
= QUEUE_Lock( hQueue
);
1257 hTask
= queue
->teb
->htask16
;
1258 QUEUE_Unlock( queue
);
1266 /***********************************************************************
1267 * QUEUE_IncPaintCount
1269 void QUEUE_IncPaintCount( HQUEUE16 hQueue
)
1271 MESSAGEQUEUE
*queue
;
1273 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
))) return;
1274 queue
->wPaintCount
++;
1275 QUEUE_SetWakeBit( queue
, QS_PAINT
);
1276 QUEUE_Unlock( queue
);
1280 /***********************************************************************
1281 * QUEUE_DecPaintCount
1283 void QUEUE_DecPaintCount( HQUEUE16 hQueue
)
1285 MESSAGEQUEUE
*queue
;
1287 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
))) return;
1288 queue
->wPaintCount
--;
1289 if (!queue
->wPaintCount
) queue
->wakeBits
&= ~QS_PAINT
;
1290 QUEUE_Unlock( queue
);
1294 /***********************************************************************
1295 * QUEUE_IncTimerCount
1297 void QUEUE_IncTimerCount( HQUEUE16 hQueue
)
1299 MESSAGEQUEUE
*queue
;
1301 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
))) return;
1302 queue
->wTimerCount
++;
1303 QUEUE_SetWakeBit( queue
, QS_TIMER
);
1304 QUEUE_Unlock( queue
);
1308 /***********************************************************************
1309 * QUEUE_DecTimerCount
1311 void QUEUE_DecTimerCount( HQUEUE16 hQueue
)
1313 MESSAGEQUEUE
*queue
;
1315 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
))) return;
1316 queue
->wTimerCount
--;
1317 if (!queue
->wTimerCount
) queue
->wakeBits
&= ~QS_TIMER
;
1318 QUEUE_Unlock( queue
);
1322 /***********************************************************************
1323 * PostQuitMessage (USER.6)
1325 void WINAPI
PostQuitMessage16( INT16 exitCode
)
1327 PostQuitMessage( exitCode
);
1331 /***********************************************************************
1332 * PostQuitMessage (USER32.@)
1334 * PostQuitMessage() posts a message to the system requesting an
1335 * application to terminate execution. As a result of this function,
1336 * the WM_QUIT message is posted to the application, and
1337 * PostQuitMessage() returns immediately. The exitCode parameter
1338 * specifies an application-defined exit code, which appears in the
1339 * _wParam_ parameter of the WM_QUIT message posted to the application.
1345 void WINAPI
PostQuitMessage( INT exitCode
)
1347 MESSAGEQUEUE
*queue
;
1349 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return;
1350 queue
->wPostQMsg
= TRUE
;
1351 queue
->wExitCode
= (WORD
)exitCode
;
1352 QUEUE_Unlock( queue
);
1356 /***********************************************************************
1357 * GetWindowTask (USER.224)
1359 HTASK16 WINAPI
GetWindowTask16( HWND16 hwnd
)
1362 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1364 if (!wndPtr
) return 0;
1365 retvalue
= QUEUE_GetQueueTask( wndPtr
->hmemTaskQ
);
1366 WIN_ReleaseWndPtr(wndPtr
);
1370 /***********************************************************************
1371 * GetWindowThreadProcessId (USER32.@)
1373 DWORD WINAPI
GetWindowThreadProcessId( HWND hwnd
, LPDWORD process
)
1376 MESSAGEQUEUE
*queue
;
1378 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1379 if (!wndPtr
) return 0;
1381 queue
= QUEUE_Lock( wndPtr
->hmemTaskQ
);
1382 WIN_ReleaseWndPtr(wndPtr
);
1384 if (!queue
) return 0;
1386 if ( process
) *process
= (DWORD
)queue
->teb
->pid
;
1387 retvalue
= (DWORD
)queue
->teb
->tid
;
1389 QUEUE_Unlock( queue
);
1394 /***********************************************************************
1395 * SetMessageQueue (USER.266)
1397 BOOL16 WINAPI
SetMessageQueue16( INT16 size
)
1399 return SetMessageQueue( size
);
1403 /***********************************************************************
1404 * SetMessageQueue (USER32.@)
1406 BOOL WINAPI
SetMessageQueue( INT size
)
1408 /* now obsolete the message queue will be expanded dynamically
1411 /* access the queue to create it if it's not existing */
1417 /***********************************************************************
1418 * InitThreadInput (USER.409)
1420 HQUEUE16 WINAPI
InitThreadInput16( WORD unknown
, WORD flags
)
1423 MESSAGEQUEUE
*queuePtr
;
1425 TEB
*teb
= NtCurrentTeb();
1430 hQueue
= teb
->queue
;
1434 /* Create thread message queue */
1435 if( !(hQueue
= QUEUE_CreateMsgQueue( TRUE
)))
1437 ERR_(msg
)("failed!\n");
1441 /* Link new queue into list */
1442 queuePtr
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
1443 queuePtr
->teb
= NtCurrentTeb();
1445 HeapLock( SystemHeap
); /* FIXME: a bit overkill */
1446 SetThreadQueue16( 0, hQueue
);
1447 teb
->queue
= hQueue
;
1449 queuePtr
->next
= hFirstQueue
;
1450 hFirstQueue
= hQueue
;
1451 HeapUnlock( SystemHeap
);
1453 QUEUE_Unlock( queuePtr
);
1459 /***********************************************************************
1460 * GetQueueStatus (USER.334)
1462 DWORD WINAPI
GetQueueStatus16( UINT16 flags
)
1464 MESSAGEQUEUE
*queue
;
1467 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
1468 ret
= MAKELONG( queue
->changeBits
, queue
->wakeBits
);
1469 queue
->changeBits
= 0;
1470 QUEUE_Unlock( queue
);
1472 return ret
& MAKELONG( flags
, flags
);
1475 /***********************************************************************
1476 * GetQueueStatus (USER32.@)
1478 DWORD WINAPI
GetQueueStatus( UINT flags
)
1480 MESSAGEQUEUE
*queue
;
1483 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
1484 ret
= MAKELONG( queue
->changeBits
, queue
->wakeBits
);
1485 queue
->changeBits
= 0;
1486 QUEUE_Unlock( queue
);
1488 return ret
& MAKELONG( flags
, flags
);
1492 /***********************************************************************
1493 * GetInputState (USER.335)
1495 BOOL16 WINAPI
GetInputState16(void)
1497 return GetInputState();
1500 /***********************************************************************
1501 * WaitForInputIdle (USER32.@)
1503 DWORD WINAPI
WaitForInputIdle (HANDLE hProcess
, DWORD dwTimeOut
)
1505 DWORD cur_time
, ret
;
1506 HANDLE idle_event
= -1;
1510 struct wait_input_idle_request
*req
= server_alloc_req( sizeof(*req
), 0 );
1511 req
->handle
= hProcess
;
1512 req
->timeout
= dwTimeOut
;
1513 if (!(ret
= server_call( REQ_WAIT_INPUT_IDLE
))) idle_event
= req
->event
;
1516 if (ret
) return 0xffffffff; /* error */
1517 if (!idle_event
) return 0; /* no event to wait on */
1519 cur_time
= GetTickCount();
1521 TRACE_(msg
)("waiting for %x\n", idle_event
);
1522 while ( dwTimeOut
> GetTickCount() - cur_time
|| dwTimeOut
== INFINITE
) {
1524 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
, QS_SENDMESSAGE
);
1525 if ( ret
== ( WAIT_OBJECT_0
+ 1 )) {
1526 MESSAGEQUEUE
* queue
;
1527 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0xFFFFFFFF;
1528 QUEUE_ReceiveMessage ( queue
);
1529 QUEUE_Unlock ( queue
);
1532 if ( ret
== WAIT_TIMEOUT
|| ret
== 0xFFFFFFFF ) {
1533 TRACE_(msg
)("timeout or error\n");
1537 TRACE_(msg
)("finished\n");
1542 return WAIT_TIMEOUT
;
1545 /***********************************************************************
1546 * GetInputState (USER32.@)
1548 BOOL WINAPI
GetInputState(void)
1550 MESSAGEQUEUE
*queue
;
1553 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
1555 ret
= queue
->wakeBits
& (QS_KEY
| QS_MOUSEBUTTON
);
1556 QUEUE_Unlock( queue
);
1561 /***********************************************************************
1562 * UserYield (USER.332)
1564 void WINAPI
UserYield16(void)
1566 MESSAGEQUEUE
*queue
;
1568 /* Handle sent messages */
1569 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() );
1571 while (queue
&& (queue
->wakeBits
& QS_SENDMESSAGE
))
1572 QUEUE_ReceiveMessage( queue
);
1574 QUEUE_Unlock( queue
);
1577 if ( THREAD_IsWin16( NtCurrentTeb() ) )
1582 /* Handle sent messages again */
1583 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() );
1585 while (queue
&& (queue
->wakeBits
& QS_SENDMESSAGE
))
1586 QUEUE_ReceiveMessage( queue
);
1588 QUEUE_Unlock( queue
);
1591 /***********************************************************************
1592 * GetMessagePos (USER.119) (USER32.@)
1594 * The GetMessagePos() function returns a long value representing a
1595 * cursor position, in screen coordinates, when the last message
1596 * retrieved by the GetMessage() function occurs. The x-coordinate is
1597 * in the low-order word of the return value, the y-coordinate is in
1598 * the high-order word. The application can use the MAKEPOINT()
1599 * macro to obtain a POINT structure from the return value.
1601 * For the current cursor position, use GetCursorPos().
1605 * Cursor position of last message on success, zero on failure.
1612 DWORD WINAPI
GetMessagePos(void)
1614 MESSAGEQUEUE
*queue
;
1617 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
1618 ret
= queue
->GetMessagePosVal
;
1619 QUEUE_Unlock( queue
);
1625 /***********************************************************************
1626 * GetMessageTime (USER.120) (USER32.@)
1628 * GetMessageTime() returns the message time for the last message
1629 * retrieved by the function. The time is measured in milliseconds with
1630 * the same offset as GetTickCount().
1632 * Since the tick count wraps, this is only useful for moderately short
1633 * relative time comparisons.
1637 * Time of last message on success, zero on failure.
1644 LONG WINAPI
GetMessageTime(void)
1646 MESSAGEQUEUE
*queue
;
1649 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
1650 ret
= queue
->GetMessageTimeVal
;
1651 QUEUE_Unlock( queue
);
1657 /***********************************************************************
1658 * GetMessageExtraInfo (USER.288) (USER32.@)
1660 LONG WINAPI
GetMessageExtraInfo(void)
1662 MESSAGEQUEUE
*queue
;
1665 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
1666 ret
= queue
->GetMessageExtraInfoVal
;
1667 QUEUE_Unlock( queue
);
1673 /**********************************************************************
1674 * AttachThreadInput (USER32.@) Attaches input of 1 thread to other
1676 * Attaches the input processing mechanism of one thread to that of
1684 * 1. Reset the Key State (currenly per thread key state is not maintained)
1686 BOOL WINAPI
AttachThreadInput(
1687 DWORD idAttach
, /* [in] Thread to attach */
1688 DWORD idAttachTo
, /* [in] Thread to attach to */
1689 BOOL fAttach
) /* [in] Attach or detach */
1691 MESSAGEQUEUE
*pSrcMsgQ
= 0, *pTgtMsgQ
= 0;
1694 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1696 /* A thread cannot attach to itself */
1697 if ( idAttach
== idAttachTo
)
1700 /* According to the docs this method should fail if a
1701 * "Journal record" hook is installed. (attaches all input queues together)
1703 if ( HOOK_IsHooked( WH_JOURNALRECORD
) )
1706 /* Retrieve message queues corresponding to the thread id's */
1707 pTgtMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetThreadQueue16( idAttach
) );
1708 pSrcMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetThreadQueue16( idAttachTo
) );
1710 /* Ensure we have message queues and that Src and Tgt threads
1711 * are not system threads.
1713 if ( !pSrcMsgQ
|| !pTgtMsgQ
|| !pSrcMsgQ
->pQData
|| !pTgtMsgQ
->pQData
)
1716 if (fAttach
) /* Attach threads */
1718 /* Only attach if currently detached */
1719 if ( pTgtMsgQ
->pQData
!= pSrcMsgQ
->pQData
)
1721 /* First release the target threads perQData */
1722 PERQDATA_Release( pTgtMsgQ
->pQData
);
1724 /* Share a reference to the source threads perQDATA */
1725 PERQDATA_Addref( pSrcMsgQ
->pQData
);
1726 pTgtMsgQ
->pQData
= pSrcMsgQ
->pQData
;
1729 else /* Detach threads */
1731 /* Only detach if currently attached */
1732 if ( pTgtMsgQ
->pQData
== pSrcMsgQ
->pQData
)
1734 /* First release the target threads perQData */
1735 PERQDATA_Release( pTgtMsgQ
->pQData
);
1737 /* Give the target thread its own private perQDATA once more */
1738 pTgtMsgQ
->pQData
= PERQDATA_CreateInstance();
1742 /* TODO: Reset the Key State */
1744 bRet
= 1; /* Success */
1748 /* Unlock the queues before returning */
1750 QUEUE_Unlock( pSrcMsgQ
);
1752 QUEUE_Unlock( pTgtMsgQ
);