Commit a4c8445b authored by Stephane Lussier's avatar Stephane Lussier Committed by Alexandre Julliard

- Changing MESSAGEQUEUE structure according to Ulrich proposition.

- One message queue for every thread needing it. - Messages in the message queue are now stored in a linked list - Messages are allocated in the system heap. - Messages in the message queue are 32 bits (MSG32). - All read/write operations regarding messages in the message queue are thread safe.
parent d68d5014
......@@ -9,12 +9,17 @@
#include "wine/winuser16.h"
#include "windows.h"
#include "thread.h"
/* Message as stored in the queue (contains the extraInfo field) */
typedef struct tagQMSG
{
MSG32 msg;
DWORD extraInfo; /* Only in 3.1 */
MSG16 msg;
struct tagQMSG *nextMsg;
struct tagQMSG *prevMsg;
} QMSG;
typedef struct
......@@ -23,49 +28,63 @@ typedef struct
BOOL16 bPending;
} QSMCTRL;
#pragma pack(1)
/* Per-queue system windows */
typedef struct tagPERQUEUEDATA
{
HWND32 hWndCapture;
HWND32 hWndFocus;
HWND32 hWndActive;
} PERQUEUEDATA;
typedef struct tagMESSAGEQUEUE
{
HQUEUE16 next; /* 00 Next queue */
HTASK16 hTask; /* 02 hTask owning the queue */
WORD msgSize; /* 04 Size of messages in the queue */
WORD msgCount; /* 06 Number of waiting messages */
WORD nextMessage; /* 08 Next message to be retrieved */
WORD nextFreeMessage; /* 0a Next available slot in the queue */
WORD queueSize; /* 0c Size of the queue */
DWORD GetMessageTimeVal WINE_PACKED; /* 0e Value for GetMessageTime */
DWORD GetMessagePosVal WINE_PACKED; /* 12 Value for GetMessagePos */
HQUEUE16 self; /* 16 Handle to self (was: reserved) */
DWORD GetMessageExtraInfoVal; /* 18 Value for GetMessageExtraInfo */
WORD wParamHigh; /* 1c High word of wParam (was: reserved)*/
LPARAM lParam WINE_PACKED; /* 1e Next 4 values set by SendMessage */
WPARAM16 wParam; /* 22 */
UINT16 msg; /* 24 */
HWND16 hWnd; /* 26 */
DWORD SendMessageReturn; /* 28 Return value for SendMessage */
WORD wPostQMsg; /* 2c PostQuitMessage flag */
WORD wExitCode; /* 2e PostQuitMessage exit code */
WORD flags; /* 30 Queue flags */
QSMCTRL* smResultInit; /* 32 1st LRESULT ptr - was: reserved */
WORD wWinVersion; /* 36 Expected Windows version */
HQUEUE16 InSendMessageHandle; /* 38 Queue of task that sent a message */
HTASK16 hSendingTask; /* 3a Handle of task that sent a message */
HTASK16 hPrevSendingTask; /* 3c Handle of previous sender */
WORD wPaintCount; /* 3e Number of WM_PAINT needed */
WORD wTimerCount; /* 40 Number of timers for this task */
WORD changeBits; /* 42 Changed wake-up bits */
WORD wakeBits; /* 44 Queue wake-up bits */
WORD wakeMask; /* 46 Queue wake-up mask */
QSMCTRL* smResultCurrent; /* 48 ptrs to SendMessage() LRESULT - point to */
WORD SendMsgReturnPtr[1]; /* values on stack */
HANDLE16 hCurHook; /* 4e Current hook */
HANDLE16 hooks[WH_NB_HOOKS]; /* 50 Task hooks list */
QSMCTRL* smResult; /* 6c 3rd LRESULT ptr - was: reserved */
QMSG messages[1]; /* 70 Queue messages */
HQUEUE16 next; /* NNext queue */
HQUEUE16 self; /* Handle to self (was: reserved) */
THDB* thdb; /* Thread owning queue */
HANDLE32 hEvent; /* Event handle */
CRITICAL_SECTION cSection; /* Queue access critical section */
WORD flags; /* Queue flags */
WORD wWinVersion; /* Expected Windows version */
WORD msgCount; /* Number of waiting messages */
QMSG* firstMsg; /* First message in linked list */
QMSG* lastMsg; /* Last message in linked list */
WORD wPostQMsg; /* PostQuitMessage flag */
WORD wExitCode; /* PostQuitMessage exit code */
WORD wPaintCount; /* Number of WM_PAINT needed */
WORD wTimerCount; /* Number of timers for this task */
WORD changeBits; /* Changed wake-up bits */
WORD wakeBits; /* Queue wake-up bits */
WORD wakeMask; /* Queue wake-up mask */
DWORD GetMessageTimeVal; /* Value for GetMessageTime */
DWORD GetMessagePosVal; /* Value for GetMessagePos */
DWORD GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */
HQUEUE16 InSendMessageHandle; /* Queue of task that sent a message */
HTASK16 hSendingTask; /* Handle of task that sent a message */
HTASK16 hPrevSendingTask; /* Handle of previous sender */
HWND32 hWnd32; /* Send message arguments */
UINT32 msg32;
WPARAM32 wParam32;
LPARAM lParam;
DWORD SendMessageReturn; /* Return value for SendMessage */
QSMCTRL* smResultInit; /* SendMesage result pointers */
QSMCTRL* smResultCurrent;
QSMCTRL* smResult;
HANDLE16 hCurHook; /* Current hook */
HANDLE16 hooks[WH_NB_HOOKS]; /* Task hooks list */
HANDLE16 hPerQueue; /* handle on PERQUEUEDATA structure */
} MESSAGEQUEUE;
#pragma pack(4)
/* Extra (undocumented) queue wake bits - see "Undoc. Windows" */
#define QS_SMRESULT 0x8000 /* Queue has a SendMessage() result */
......@@ -80,7 +99,7 @@ extern void QUEUE_WalkQueues(void);
extern BOOL32 QUEUE_IsExitingQueue( HQUEUE16 hQueue );
extern void QUEUE_SetExitingQueue( HQUEUE16 hQueue );
extern MESSAGEQUEUE *QUEUE_GetSysQueue(void);
extern void QUEUE_Signal( HTASK16 hTask );
extern void QUEUE_Signal( THDB *thdb );
extern void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit );
extern void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit );
extern void QUEUE_ReceiveMessage( MESSAGEQUEUE *queue );
......@@ -89,13 +108,13 @@ extern void QUEUE_IncPaintCount( HQUEUE16 hQueue );
extern void QUEUE_DecPaintCount( HQUEUE16 hQueue );
extern void QUEUE_IncTimerCount( HQUEUE16 hQueue );
extern void QUEUE_DecTimerCount( HQUEUE16 hQueue );
extern BOOL32 QUEUE_CreateSysMsgQueue( int size );
extern BOOL32 QUEUE_CreateSysMsgQueue( );
extern BOOL32 QUEUE_DeleteMsgQueue( HQUEUE16 hQueue );
extern HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue );
extern BOOL32 QUEUE_AddMsg( HQUEUE16 hQueue, MSG16 * msg, DWORD extraInfo );
extern int QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND32 hwnd,
extern BOOL32 QUEUE_AddMsg( HQUEUE16 hQueue, MSG32 * msg, DWORD extraInfo );
extern QMSG* QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND32 hwnd,
int first, int last );
extern void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, int pos );
extern void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, QMSG *qmsg );
extern void QUEUE_FlushMessages(HQUEUE16);
extern void hardware_event( WORD message, WORD wParam, LONG lParam,
int xPos, int yPos, DWORD time, DWORD extraInfo );
......
......@@ -441,9 +441,12 @@ static int MSG_JournalPlayBackMsg(void)
static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
BOOL32 remove )
{
/* FIXME: should deal with MSG32 instead of MSG16 */
DWORD status = SYSQ_MSG_ACCEPT;
MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
int i, kbd_msg, pos = sysMsgQueue->nextMessage;
int kbd_msg;
QMSG *nextqmsg, *qmsg = sysMsgQueue->firstMsg;
/* FIXME: there has to be a better way to do this */
joySendMessages();
......@@ -453,16 +456,20 @@ static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
&& EVENT_Pending())
EVENT_WaitNetEvent( FALSE, FALSE );
for (i = kbd_msg = 0; i < sysMsgQueue->msgCount; i++, pos++)
for ( kbd_msg = 0; qmsg; qmsg = nextqmsg)
{
if (pos >= sysMsgQueue->queueSize) pos = 0;
*msg = sysMsgQueue->messages[pos].msg;
/* FIXME: this line will be reenabled when msg will be a MSG32 */
/* *msg = qmsg->msg; */
STRUCT32_MSG32to16(&qmsg->msg, msg);
nextqmsg = qmsg->nextMsg;
/* Translate message */
if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
{
HWND32 hWndScope = (HWND32)sysMsgQueue->messages[pos].extraInfo;
HWND32 hWndScope = (HWND32)qmsg->extraInfo;
status = MSG_TranslateMouseMsg(hwnd, filter, msg, remove,
(Options.managed && IsWindow32(hWndScope) )
......@@ -490,7 +497,7 @@ static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
SEGPTR_FREE(hook);
if (ret)
{
QUEUE_RemoveMsg( sysMsgQueue, pos );
QUEUE_RemoveMsg( sysMsgQueue, qmsg );
continue;
}
status = SYSQ_MSG_ACCEPT;
......@@ -525,7 +532,7 @@ static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
}
if (remove)
QUEUE_RemoveMsg( sysMsgQueue, pos );
QUEUE_RemoveMsg( sysMsgQueue, qmsg );
/* continue */
case SYSQ_MSG_CONTINUE:
......@@ -538,7 +545,7 @@ static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
if (remove)
{
if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
QUEUE_RemoveMsg( sysMsgQueue, pos );
QUEUE_RemoveMsg( sysMsgQueue, qmsg );
}
return TRUE;
}
......@@ -546,6 +553,7 @@ static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
}
/**********************************************************************
* SetDoubleClickTime16 (USER.20)
*/
......@@ -611,11 +619,9 @@ static LRESULT MSG_SendMessage( HQUEUE16 hDestQueue, HWND16 hwnd, UINT16 msg,
}
/* resume sending */
queue->hWnd = hwnd;
queue->msg = msg;
queue->wParam = LOWORD(wParam);
queue->wParamHigh = HIWORD(wParam);
queue->hWnd32 = hwnd;
queue->msg32 = msg;
queue->wParam32 = wParam;
queue->lParam = lParam;
queue->hPrevSendingTask = destQ->hSendingTask;
destQ->hSendingTask = GetFastQueue();
......@@ -635,7 +641,8 @@ static LRESULT MSG_SendMessage( HQUEUE16 hDestQueue, HWND16 hwnd, UINT16 msg,
{
if (!(queue->wakeBits & QS_SMRESULT))
{
if (THREAD_IsWin16( THREAD_Current() )) DirectedYield( destQ->hTask );
if (THREAD_IsWin16( THREAD_Current() ))
DirectedYield( destQ->thdb->teb.htask16 );
QUEUE_WaitBits( QS_SMRESULT );
TRACE(sendmsg,"\tsm: have result!\n");
}
......@@ -675,8 +682,8 @@ void WINAPI ReplyMessage16( LRESULT result )
while( (senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->InSendMessageHandle)))
{
TRACE(msg,"\trpm: replying to %04x (%04x -> %04x)\n",
queue->msg, queue->self, senderQ->self);
TRACE(msg,"\trpm: replying to %08x (%04x -> %04x)\n",
queue->msg32, queue->self, senderQ->self);
if( queue->wakeBits & QS_SENDMESSAGE )
{
......@@ -697,7 +704,8 @@ void WINAPI ReplyMessage16( LRESULT result )
queue->InSendMessageHandle = 0;
QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
if (THREAD_IsWin16(THREAD_Current())) DirectedYield( senderQ->hTask );
if (THREAD_IsWin16( THREAD_Current() ))
DirectedYield( senderQ->thdb->teb.htask16 );
}
......@@ -707,7 +715,7 @@ void WINAPI ReplyMessage16( LRESULT result )
static BOOL32 MSG_PeekMessage( LPMSG16 msg, HWND16 hwnd, WORD first, WORD last,
WORD flags, BOOL32 peek )
{
int pos, mask;
int mask;
MESSAGEQUEUE *msgQueue;
HQUEUE16 hQueue;
......@@ -735,6 +743,8 @@ static BOOL32 MSG_PeekMessage( LPMSG16 msg, HWND16 hwnd, WORD first, WORD last,
while(1)
{
QMSG *qmsg;
hQueue = GetFastQueue();
msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
if (!msgQueue) return FALSE;
......@@ -762,15 +772,17 @@ static BOOL32 MSG_PeekMessage( LPMSG16 msg, HWND16 hwnd, WORD first, WORD last,
/* Now find a normal message */
if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
((pos = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != -1))
((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
{
QMSG *qmsg = &msgQueue->messages[pos];
*msg = qmsg->msg;
/* FIXME: this line will be reenabled when msg will be a MSG32 */
/* *msg = qmsg->msg; */
STRUCT32_MSG32to16(&qmsg->msg, msg);
msgQueue->GetMessageTimeVal = msg->time;
msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, pos );
if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
break;
}
......@@ -1129,7 +1141,7 @@ BOOL32 WINAPI GetMessage32W(
BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
LPARAM lParam )
{
MSG16 msg;
MSG32 msg;
WND *wndPtr;
msg.hwnd = hwnd;
......@@ -1204,7 +1216,7 @@ BOOL32 WINAPI PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
LPARAM lParam )
{
MSG16 msg;
MSG32 msg;
if (GetTaskQueue(hTask) == 0) return FALSE;
msg.hwnd = 0;
......
......@@ -292,19 +292,19 @@ static WND* WIN_DestroyWindow( WND* wndPtr )
if( wndPtr->hmemTaskQ )
{
int pos;
BOOL32 bPostQuit = FALSE;
WPARAM32 wQuitParam = 0;
MESSAGEQUEUE* msgQ = (MESSAGEQUEUE*) GlobalLock16(wndPtr->hmemTaskQ);
QMSG *qmsg;
while( (pos = QUEUE_FindMsg(msgQ, hwnd, 0, 0)) != -1 )
while( (qmsg = QUEUE_FindMsg(msgQ, hwnd, 0, 0)) != 0 )
{
if( msgQ->messages[pos].msg.message == WM_QUIT )
if( qmsg->msg.message == WM_QUIT )
{
bPostQuit = TRUE;
wQuitParam = msgQ->messages[pos].msg.wParam;
wQuitParam = qmsg->msg.wParam;
}
QUEUE_RemoveMsg(msgQ, pos);
QUEUE_RemoveMsg(msgQ, qmsg);
}
/* repost WM_QUIT to make sure this app exits its message loop */
if( bPostQuit ) PostQuitMessage32(wQuitParam);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment