Ignore:
Timestamp:
Aug 1, 2002, 6:05:51 PM (23 years ago)
Author:
sandervl
Message:

MsgWaitForMultipleObjects changes for posted messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/windowmsg.cpp

    r8949 r8954  
    1 /* $Id: windowmsg.cpp,v 1.35 2002-07-31 16:51:00 sandervl Exp $ */
     1/* $Id: windowmsg.cpp,v 1.36 2002-08-01 16:05:51 sandervl Exp $ */
    22/*
    33 * Win32 window message APIs for OS/2
     
    2020#include <os2sel.h>
    2121
     22#include <string.h>
    2223#include <os2win.h>
    2324#include <misc.h>
     
    2627#include <heapstring.h>
    2728#include <handlemanager.h>
     29#include <wprocess.h>
    2830#include "oslibutil.h"
    2931#include "oslibwin.h"
     
    834836    //      in the queue.
    835837    //      Very obscure behaviour, so it's unlikely any application depends on it
     838
     839    //4 cases:
     840    //1: Wait for all   -> check for message arrival, call WaitForMultipleObjects
     841    //2: Timeout = 0 ms -> check for message arrival, call WaitForMultipleObjects with timeout 0
     842    //3: nCount = 0     -> check for message arrival
     843    //4: rest           -> check for either message arrival or signalled object
     844
    836845    dprintf(("MsgWaitForMultipleObjects %x %x %d %d %x", nCount, pHandles, fWaitAll, dwMilliseconds, dwWakeMask));
    837     if(fWaitAll)
     846    if(fWaitAll) //case 1
    838847    {   //wait for message arrival first
    839848        curtime = GetCurrentTime();
     
    874883        return ret;
    875884    }
    876     if(dwMilliseconds == 0) {
     885    if(dwMilliseconds == 0) { //case 2
    877886        //TODO: what has a higher priority; message presence or signalled object?
    878887        if(GetQueueStatus(dwWakeMask) == 0) {
     
    884893        return WAIT_OBJECT_0 + nCount;  //right message has arrived
    885894    }
     895    if(nCount == 0) //case 3
     896    {
     897        //SvL: Check time, wait for any message, check msg type and determine if
     898        //     we have to return
     899        //TODO: Timeout isn't handled correctly (can return too late)
     900        curtime = GetCurrentTime();
     901        endtime = curtime + dwMilliseconds;
     902        while(curtime < endtime || dwMilliseconds == INFINITE) {
     903                if(OSLibWinWaitMessage() == FALSE) {
     904                        dprintf(("OSLibWinWaitMessage returned FALSE!"));
     905                        return WAIT_ABANDONED;
     906                }
     907                if(GetQueueStatus(dwWakeMask) != 0) {
     908                        return WAIT_OBJECT_0;
     909                }
     910                //TODO: Ignoring all messages could be dangerous. But processing them,
     911                //while the app doesn't expect any, isn't safe either.
     912                if(PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
     913                {
     914                    if (msg.message == WM_QUIT) {
     915                         dprintf(("ERROR: MsgWaitForMultipleObjects call abandoned because WM_QUIT msg was received!!"));
     916                         return WAIT_ABANDONED;
     917                    }
     918   
     919                    /* otherwise dispatch it */
     920                    DispatchMessageA(&msg);
     921                }
     922                curtime = GetCurrentTime();
     923        }
     924        return WAIT_TIMEOUT;
     925    }
     926
     927    //Case 4:
     928#if 1
     929    //Note: The WGSS implementation of this function is flawed. Returns
     930    //      when a message is sent to the msg queue, regardless of dwWakeMask
     931    TEB *teb = GetTEBFromThreadId(GetCurrentThreadId());
     932    if(teb == NULL) {
     933       DebugInt3();
     934       return WAIT_ABANDONED;
     935    }
     936    if(dwWakeMask & QS_POSTMESSAGE) {
     937        if(GetQueueStatus(dwWakeMask) != 0) {
     938            return WAIT_OBJECT_0+nCount;
     939        }
     940
     941        HANDLE *pHandlesTmp = (HANDLE *)alloca((nCount+1)*sizeof(HANDLE));
     942        if(pHandlesTmp == NULL || !teb->o.odin.hPostMsgEvent) {
     943            DebugInt3();
     944            return WAIT_ABANDONED;
     945        }
     946        memcpy(pHandlesTmp, pHandles, nCount*sizeof(HANDLE));
     947        pHandlesTmp[nCount] = teb->o.odin.hPostMsgEvent;
     948        teb->o.odin.dwWakeMask = dwWakeMask;
     949
     950        ResetEvent(teb->o.odin.hPostMsgEvent);
     951        ret = HMMsgWaitForMultipleObjects(nCount+1,pHandlesTmp,fWaitAll,dwMilliseconds,dwWakeMask);
     952        //nCount + 2 -> message event -> return nCount + 1
     953        teb->o.odin.dwWakeMask = 0;
     954        return (ret == nCount + 2) ? (nCount + 1) : ret;
     955    }
     956    //Call handlemanager function as we need to translate handles (KERNEL32)
     957    ret = HMMsgWaitForMultipleObjects(nCount,pHandles,fWaitAll,dwMilliseconds,dwWakeMask);
     958    return ret;
     959#else
     960    //This method has a high latency (too high for some apps)
    886961    //TODO: Timeout isn't handled correctly (can return too late)
    887962    curtime = GetCurrentTime();
     
    906981        }
    907982        //check if any object is signalled (timeout 10ms)
    908         ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 10);
     983        ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 4);
    909984        if(ret < WAIT_OBJECT_0 + nCount) {
    910985            //an object was signalled, return immediately
     
    921996    }
    922997    return WAIT_TIMEOUT;
    923 
    924 //  //Call handlemanager function as we need to translate handles (KERNEL32)
    925 //  ret = HMMsgWaitForMultipleObjects(nCount,pHandles,fWaitAll,dwMilliseconds,dwWakeMask);
    926 //  return ret;
    927 }
     998#endif
     999}
Note: See TracChangeset for help on using the changeset viewer.