2000-01-25 14:48:51 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
2003-03-25 01:38:53 +00:00
|
|
|
*
|
2000-01-25 14:48:51 +00:00
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
2003-03-25 01:38:53 +00:00
|
|
|
*
|
2000-01-25 14:48:51 +00:00
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
#if defined(_WIN32)
|
2000-01-25 14:48:51 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(XP_OS2)
|
|
|
|
#define INCL_WIN
|
|
|
|
#include <os2.h>
|
|
|
|
#define DefWindowProc WinDefWindowProc
|
|
|
|
#endif /* XP_OS2 */
|
|
|
|
|
|
|
|
#include "nspr.h"
|
|
|
|
#include "plevent.h"
|
|
|
|
|
|
|
|
#if !defined(WIN32)
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#if !defined(XP_OS2)
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif /* !XP_OS2 */
|
|
|
|
#endif /* !Win32 */
|
|
|
|
|
|
|
|
#if defined(XP_UNIX)
|
|
|
|
/* for fcntl */
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(XP_BEOS)
|
|
|
|
#include <kernel/OS.h>
|
|
|
|
#endif
|
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(XP_MAC) || defined(XP_MACOSX)
|
|
|
|
#if !defined(MOZ_WIDGET_COCOA) && TARGET_CARBON
|
|
|
|
#include <CarbonEvents.h>
|
|
|
|
#define MAC_USE_CARBON_EVENT
|
|
|
|
#else
|
|
|
|
#include <Processes.h>
|
|
|
|
#define MAC_USE_WAKEUPPROCESS
|
|
|
|
#endif
|
2000-03-11 03:08:04 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
#if defined(XP_MAC)
|
|
|
|
#include "pprthred.h"
|
|
|
|
#else
|
|
|
|
#include "private/pprthred.h"
|
2002-12-19 15:25:57 +00:00
|
|
|
#endif /* defined(XP_MAC) */
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
#if defined(VMS)
|
|
|
|
/*
|
2003-03-25 01:38:53 +00:00
|
|
|
** On OpenVMS, XtAppAddInput doesn't want a regular fd, instead it
|
|
|
|
** wants an event flag. So, we don't create and use a pipe for
|
2000-01-25 14:48:51 +00:00
|
|
|
** notification of when an event queue has something ready, instead
|
|
|
|
** we use an event flag. Shouldn't be a problem if we only have
|
|
|
|
** a few event queues.
|
|
|
|
*/
|
|
|
|
#include <lib$routines.h>
|
|
|
|
#include <starlet.h>
|
|
|
|
#include <stsdef.h>
|
|
|
|
#endif /* VMS */
|
|
|
|
|
2002-08-29 23:04:14 +00:00
|
|
|
#if defined(_WIN32)
|
2003-03-25 01:38:53 +00:00
|
|
|
/* Comment out the following USE_TIMER define to prevent
|
|
|
|
* WIN32 from using a WIN32 native timer for PLEvent notification.
|
|
|
|
* With USE_TIMER defined we will use a timer when pending input
|
|
|
|
* or paint events are starved, otherwise it will use a posted
|
|
|
|
* WM_APP msg for PLEvent notification.
|
2002-08-29 23:04:14 +00:00
|
|
|
*/
|
|
|
|
#define USE_TIMER
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
/* Threshold defined in milliseconds for determining when the input
|
2002-08-29 23:04:14 +00:00
|
|
|
* and paint events have been held in the WIN32 msg queue too long
|
|
|
|
*/
|
|
|
|
#define INPUT_STARVATION_LIMIT 50
|
2003-03-25 01:38:53 +00:00
|
|
|
/* The paint starvation limit is set to the smallest value which
|
2002-08-29 23:04:14 +00:00
|
|
|
* does not cause performance degradation while running page load tests
|
|
|
|
*/
|
|
|
|
#define PAINT_STARVATION_LIMIT 750
|
2003-03-25 01:38:53 +00:00
|
|
|
/* The WIN9X paint starvation limit is larger because it was
|
2002-08-29 23:04:14 +00:00
|
|
|
* determined that the following value was required to prevent performance
|
|
|
|
* degradation on page load tests for WIN98/95 only.
|
|
|
|
*/
|
|
|
|
#define WIN9X_PAINT_STARVATION_LIMIT 3000
|
|
|
|
|
|
|
|
#define TIMER_ID 0
|
2002-10-01 03:04:22 +00:00
|
|
|
/* If _md_PerformanceSetting <=0 then no event starvation otherwise events will be starved */
|
|
|
|
static PRInt32 _md_PerformanceSetting = 0;
|
2002-09-19 02:53:05 +00:00
|
|
|
static PRUint32 _md_StarvationDelay = 0;
|
|
|
|
static PRUint32 _md_SwitchTime = 0;
|
2002-08-29 23:04:14 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
static PRLogModuleInfo *event_lm = NULL;
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Private Stuff
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** EventQueueType -- Defines notification type for an event queue
|
|
|
|
**
|
|
|
|
*/
|
2003-03-25 01:38:53 +00:00
|
|
|
typedef enum {
|
2000-01-25 14:48:51 +00:00
|
|
|
EventQueueIsNative = 1,
|
|
|
|
EventQueueIsMonitored = 2
|
|
|
|
} EventQueueType;
|
|
|
|
|
|
|
|
|
|
|
|
struct PLEventQueue {
|
2003-03-25 01:38:53 +00:00
|
|
|
const char* name;
|
|
|
|
PRCList queue;
|
|
|
|
PRMonitor* monitor;
|
|
|
|
PRThread* handlerThread;
|
|
|
|
EventQueueType type;
|
|
|
|
PRPackedBool processingEvents;
|
|
|
|
PRPackedBool notified;
|
2002-08-29 23:04:14 +00:00
|
|
|
#if defined(_WIN32)
|
2003-03-25 01:38:53 +00:00
|
|
|
PRPackedBool timerSet;
|
2002-08-29 23:04:14 +00:00
|
|
|
#endif
|
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
2000-01-25 14:48:51 +00:00
|
|
|
#if defined(VMS)
|
2003-03-25 01:38:53 +00:00
|
|
|
int efn;
|
2001-03-16 21:39:49 +00:00
|
|
|
#else
|
2003-03-25 01:38:53 +00:00
|
|
|
PRInt32 eventPipe[2];
|
2001-03-16 21:39:49 +00:00
|
|
|
#endif
|
2003-03-25 01:38:53 +00:00
|
|
|
PLGetEventIDFunc idFunc;
|
|
|
|
void* idFuncClosure;
|
2002-08-29 23:04:14 +00:00
|
|
|
#elif defined(_WIN32) || defined(XP_OS2)
|
2003-03-25 01:38:53 +00:00
|
|
|
HWND eventReceiverWindow;
|
|
|
|
PRBool removeMsg;
|
2000-01-25 14:48:51 +00:00
|
|
|
#elif defined(XP_BEOS)
|
2003-03-25 01:38:53 +00:00
|
|
|
port_id eventport;
|
2002-12-19 15:25:57 +00:00
|
|
|
#elif defined(XP_MAC) || defined(XP_MACOSX)
|
|
|
|
#if defined(MAC_USE_CARBON_EVENT)
|
2003-03-25 01:38:53 +00:00
|
|
|
EventHandlerUPP eventHandlerUPP;
|
|
|
|
EventHandlerRef eventHandlerRef;
|
2002-12-19 15:25:57 +00:00
|
|
|
#elif defined(MAC_USE_WAKEUPPROCESS)
|
2002-03-27 07:16:12 +00:00
|
|
|
ProcessSerialNumber psn;
|
2000-01-25 14:48:51 +00:00
|
|
|
#endif
|
2002-12-19 15:25:57 +00:00
|
|
|
#endif
|
2000-01-25 14:48:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define PR_EVENT_PTR(_qp) \
|
|
|
|
((PLEvent*) ((char*) (_qp) - offsetof(PLEvent, link)))
|
|
|
|
|
|
|
|
static PRStatus _pl_SetupNativeNotifier(PLEventQueue* self);
|
|
|
|
static void _pl_CleanupNativeNotifier(PLEventQueue* self);
|
|
|
|
static PRStatus _pl_NativeNotify(PLEventQueue* self);
|
|
|
|
static PRStatus _pl_AcknowledgeNativeNotify(PLEventQueue* self);
|
|
|
|
static void _md_CreateEventQueue( PLEventQueue *eventQueue );
|
|
|
|
static PRInt32 _pl_GetEventCount(PLEventQueue* self);
|
|
|
|
|
|
|
|
|
2002-08-29 23:04:14 +00:00
|
|
|
#if defined(_WIN32) || defined(XP_OS2)
|
2000-01-25 14:48:51 +00:00
|
|
|
#if defined(XP_OS2)
|
|
|
|
ULONG _pr_PostEventMsgId;
|
|
|
|
#else
|
|
|
|
UINT _pr_PostEventMsgId;
|
|
|
|
#endif /* OS2 */
|
2001-11-14 01:37:41 +00:00
|
|
|
static char *_pr_eventWindowClass = "XPCOM:EventWindow";
|
2002-08-29 23:04:14 +00:00
|
|
|
#endif /* Win32, OS2 */
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
|
|
|
static LPCTSTR _md_GetEventQueuePropName() {
|
2003-03-25 01:38:53 +00:00
|
|
|
static ATOM atom = 0;
|
|
|
|
if (!atom) {
|
|
|
|
atom = GlobalAddAtom("XPCOM_EventQueue");
|
|
|
|
}
|
|
|
|
return MAKEINTATOM(atom);
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
2000-01-25 14:48:51 +00:00
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(MAC_USE_CARBON_EVENT)
|
|
|
|
enum {
|
|
|
|
kEventClassPL = FOUR_CHAR_CODE('PLEC'),
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
kEventProcessPLEvents = 1,
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
kEventParamPLEventQueue = FOUR_CHAR_CODE('OWNQ')
|
|
|
|
};
|
|
|
|
|
|
|
|
static pascal Boolean _md_CarbonEventComparator(EventRef inEvent, void *inCompareData);
|
|
|
|
#endif
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Event Queue Operations
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** _pl_CreateEventQueue() -- Create the event queue
|
|
|
|
**
|
|
|
|
**
|
|
|
|
*/
|
2003-02-24 17:43:22 +00:00
|
|
|
static PLEventQueue * _pl_CreateEventQueue(const char *name,
|
2000-09-11 20:59:56 +00:00
|
|
|
PRThread *handlerThread,
|
|
|
|
EventQueueType qtype)
|
2000-01-25 14:48:51 +00:00
|
|
|
{
|
|
|
|
PRStatus err;
|
|
|
|
PLEventQueue* self = NULL;
|
|
|
|
PRMonitor* mon = NULL;
|
|
|
|
|
|
|
|
if (event_lm == NULL)
|
|
|
|
event_lm = PR_NewLogModule("event");
|
|
|
|
|
|
|
|
self = PR_NEWZAP(PLEventQueue);
|
|
|
|
if (self == NULL) return NULL;
|
|
|
|
|
|
|
|
mon = PR_NewNamedMonitor(name);
|
|
|
|
if (mon == NULL) goto error;
|
|
|
|
|
|
|
|
self->name = name;
|
|
|
|
self->monitor = mon;
|
|
|
|
self->handlerThread = handlerThread;
|
|
|
|
self->processingEvents = PR_FALSE;
|
|
|
|
self->type = qtype;
|
2003-03-25 01:38:53 +00:00
|
|
|
#if defined(_WIN32)
|
2002-08-29 23:04:14 +00:00
|
|
|
self->timerSet = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
#if defined(_WIN32) || defined(XP_OS2)
|
2000-01-25 14:48:51 +00:00
|
|
|
self->removeMsg = PR_TRUE;
|
|
|
|
#endif
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(MAC_USE_WAKEUPPROCESS)
|
2002-03-27 07:16:12 +00:00
|
|
|
self->psn.lowLongOfPSN = kNoProcess;
|
|
|
|
#endif
|
2000-09-11 20:59:56 +00:00
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
self->notified = PR_FALSE;
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
PR_INIT_CLIST(&self->queue);
|
2000-03-04 03:17:01 +00:00
|
|
|
if ( qtype == EventQueueIsNative ) {
|
2000-01-25 14:48:51 +00:00
|
|
|
err = _pl_SetupNativeNotifier(self);
|
|
|
|
if (err) goto error;
|
2000-03-04 03:17:01 +00:00
|
|
|
_md_CreateEventQueue( self );
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (mon != NULL)
|
2000-03-04 03:17:01 +00:00
|
|
|
PR_DestroyMonitor(mon);
|
2000-01-25 14:48:51 +00:00
|
|
|
PR_DELETE(self);
|
|
|
|
return NULL;
|
2003-03-25 01:38:53 +00:00
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_IMPLEMENT(PLEventQueue*)
|
2003-02-24 17:43:22 +00:00
|
|
|
PL_CreateEventQueue(const char* name, PRThread* handlerThread)
|
2000-01-25 14:48:51 +00:00
|
|
|
{
|
|
|
|
return( _pl_CreateEventQueue( name, handlerThread, EventQueueIsNative ));
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_EXTERN(PLEventQueue *)
|
2003-02-24 17:43:22 +00:00
|
|
|
PL_CreateNativeEventQueue(const char *name, PRThread *handlerThread)
|
2000-01-25 14:48:51 +00:00
|
|
|
{
|
|
|
|
return( _pl_CreateEventQueue( name, handlerThread, EventQueueIsNative ));
|
2003-03-25 01:38:53 +00:00
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_EXTERN(PLEventQueue *)
|
2003-02-24 17:43:22 +00:00
|
|
|
PL_CreateMonitoredEventQueue(const char *name, PRThread *handlerThread)
|
2000-01-25 14:48:51 +00:00
|
|
|
{
|
|
|
|
return( _pl_CreateEventQueue( name, handlerThread, EventQueueIsMonitored ));
|
2003-03-25 01:38:53 +00:00
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_IMPLEMENT(PRMonitor*)
|
|
|
|
PL_GetEventQueueMonitor(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
return self->monitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PR_CALLBACK
|
|
|
|
_pl_destroyEvent(PLEvent* event, void* data, PLEventQueue* queue)
|
|
|
|
{
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma unused (data, queue)
|
|
|
|
#endif
|
|
|
|
PL_DequeueEvent(event, queue);
|
|
|
|
PL_DestroyEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_DestroyEventQueue(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
PR_EnterMonitor(self->monitor);
|
|
|
|
|
|
|
|
/* destroy undelivered events */
|
|
|
|
PL_MapEvents(self, _pl_destroyEvent, NULL);
|
|
|
|
|
|
|
|
if ( self->type == EventQueueIsNative )
|
|
|
|
_pl_CleanupNativeNotifier(self);
|
|
|
|
|
|
|
|
/* destroying the monitor also destroys the name */
|
|
|
|
PR_ExitMonitor(self->monitor);
|
|
|
|
PR_DestroyMonitor(self->monitor);
|
|
|
|
PR_DELETE(self);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(PRStatus)
|
|
|
|
PL_PostEvent(PLEventQueue* self, PLEvent* event)
|
|
|
|
{
|
|
|
|
PRStatus err = PR_SUCCESS;
|
|
|
|
PRMonitor* mon;
|
|
|
|
|
|
|
|
if (self == NULL)
|
2000-07-07 04:17:24 +00:00
|
|
|
return PR_FAILURE;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
mon = self->monitor;
|
|
|
|
PR_EnterMonitor(mon);
|
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
2001-03-12 23:57:18 +00:00
|
|
|
if (self->idFunc && event)
|
2003-03-25 01:38:53 +00:00
|
|
|
event->id = self->idFunc(self->idFuncClosure);
|
2001-03-13 00:36:54 +00:00
|
|
|
#endif
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
/* insert event into thread's event queue: */
|
|
|
|
if (event != NULL) {
|
2003-03-25 01:38:53 +00:00
|
|
|
PR_APPEND_LINK(&event->link, &self->queue);
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
if (self->type == EventQueueIsNative && !self->notified) {
|
|
|
|
err = _pl_NativeNotify(self);
|
|
|
|
|
|
|
|
if (err != PR_SUCCESS)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
self->notified = PR_TRUE;
|
2000-09-12 04:37:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
/*
|
|
|
|
* This may fall on deaf ears if we're really notifying the native
|
|
|
|
* thread, and no one has called PL_WaitForEvent (or PL_EventLoop):
|
|
|
|
*/
|
|
|
|
err = PR_Notify(mon);
|
2000-01-25 14:48:51 +00:00
|
|
|
|
2000-09-11 20:59:56 +00:00
|
|
|
error:
|
2000-01-25 14:48:51 +00:00
|
|
|
PR_ExitMonitor(mon);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void*)
|
|
|
|
PL_PostSynchronousEvent(PLEventQueue* self, PLEvent* event)
|
|
|
|
{
|
|
|
|
void* result;
|
|
|
|
|
|
|
|
if (self == NULL)
|
2003-03-25 01:38:53 +00:00
|
|
|
return NULL;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_ASSERT(event != NULL);
|
2000-09-01 00:50:51 +00:00
|
|
|
PR_Lock(event->lock);
|
2000-07-07 04:17:24 +00:00
|
|
|
|
2002-09-03 14:51:05 +00:00
|
|
|
if (PR_GetCurrentThread() == self->handlerThread) {
|
2003-03-25 01:38:53 +00:00
|
|
|
/* Handle the case where the thread requesting the event handling
|
|
|
|
is also the thread that's supposed to do the handling. */
|
|
|
|
result = event->handler(event);
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-03-25 01:38:53 +00:00
|
|
|
int i, entryCount = PR_GetMonitorEntryCount(self->monitor);
|
|
|
|
|
|
|
|
event->synchronousResult = (void*)PR_TRUE;
|
|
|
|
|
|
|
|
PL_PostEvent(self, event);
|
|
|
|
|
|
|
|
/* We need temporarily to give up our event queue monitor if
|
|
|
|
we're holding it, otherwise, the thread we're going to wait
|
|
|
|
for notification from won't be able to enter it to process
|
|
|
|
the event. */
|
|
|
|
if (entryCount) {
|
|
|
|
for (i = 0; i < entryCount; i++)
|
|
|
|
PR_ExitMonitor(self->monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
event->handled = PR_FALSE;
|
|
|
|
|
|
|
|
while (!event->handled) {
|
|
|
|
/* wait for event to be handled or destroyed */
|
|
|
|
PR_WaitCondVar(event->condVar, PR_INTERVAL_NO_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entryCount) {
|
|
|
|
for (i = 0; i < entryCount; i++)
|
|
|
|
PR_EnterMonitor(self->monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = event->synchronousResult;
|
|
|
|
event->synchronousResult = NULL;
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
|
2000-09-01 00:50:51 +00:00
|
|
|
PR_Unlock(event->lock);
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
/* For synchronous events, they're destroyed here on the caller's
|
|
|
|
thread before the result is returned. See PL_HandleEvent. */
|
|
|
|
PL_DestroyEvent(event);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(PLEvent*)
|
|
|
|
PL_GetEvent(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
PLEvent* event = NULL;
|
|
|
|
PRStatus err = PR_SUCCESS;
|
|
|
|
|
|
|
|
if (self == NULL)
|
2003-03-25 01:38:53 +00:00
|
|
|
return NULL;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_EnterMonitor(self->monitor);
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
if (!PR_CLIST_IS_EMPTY(&self->queue)) {
|
|
|
|
if ( self->type == EventQueueIsNative &&
|
|
|
|
self->notified &&
|
|
|
|
!self->processingEvents &&
|
|
|
|
0 == _pl_GetEventCount(self) )
|
|
|
|
{
|
|
|
|
err = _pl_AcknowledgeNativeNotify(self);
|
|
|
|
self->notified = PR_FALSE;
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* then grab the event and return it: */
|
|
|
|
event = PR_EVENT_PTR(self->queue.next);
|
|
|
|
PR_REMOVE_AND_INIT_LINK(&event->link);
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
PR_ExitMonitor(self->monitor);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(PRBool)
|
|
|
|
PL_EventAvailable(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
if (self == NULL)
|
2003-03-25 01:38:53 +00:00
|
|
|
return PR_FALSE;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_EnterMonitor(self->monitor);
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
if (!PR_CLIST_IS_EMPTY(&self->queue))
|
|
|
|
result = PR_TRUE;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_ExitMonitor(self->monitor);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_MapEvents(PLEventQueue* self, PLEventFunProc fun, void* data)
|
|
|
|
{
|
|
|
|
PRCList* qp;
|
|
|
|
|
|
|
|
if (self == NULL)
|
2003-03-25 01:38:53 +00:00
|
|
|
return;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_EnterMonitor(self->monitor);
|
|
|
|
qp = self->queue.next;
|
|
|
|
while (qp != &self->queue) {
|
2003-03-25 01:38:53 +00:00
|
|
|
PLEvent* event = PR_EVENT_PTR(qp);
|
|
|
|
qp = qp->next;
|
|
|
|
(*fun)(event, data, self);
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
PR_ExitMonitor(self->monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PR_CALLBACK
|
|
|
|
_pl_DestroyEventForOwner(PLEvent* event, void* owner, PLEventQueue* queue)
|
|
|
|
{
|
|
|
|
PR_ASSERT(PR_GetMonitorEntryCount(queue->monitor) > 0);
|
|
|
|
if (event->owner == owner) {
|
2003-03-25 01:38:53 +00:00
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
|
|
|
("$$$ \tdestroying event %0x for owner %0x", event, owner));
|
|
|
|
PL_DequeueEvent(event, queue);
|
|
|
|
if (event->synchronousResult == (void*)PR_TRUE) {
|
|
|
|
PR_Lock(event->lock);
|
|
|
|
event->synchronousResult = NULL;
|
|
|
|
event->handled = PR_TRUE;
|
|
|
|
PR_NotifyCondVar(event->condVar);
|
|
|
|
PR_Unlock(event->lock);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PL_DestroyEvent(event);
|
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-03-25 01:38:53 +00:00
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
|
|
|
("$$$ \tskipping event %0x for owner %0x", event, owner));
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_RevokeEvents(PLEventQueue* self, void* owner)
|
|
|
|
{
|
|
|
|
if (self == NULL)
|
2003-03-25 01:38:53 +00:00
|
|
|
return;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
|
|
|
("$$$ revoking events for owner %0x", owner));
|
|
|
|
|
|
|
|
/*
|
|
|
|
** First we enter the monitor so that no one else can post any events
|
|
|
|
** to the queue:
|
|
|
|
*/
|
|
|
|
PR_EnterMonitor(self->monitor);
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ owner %0x, entered monitor", owner));
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Discard any pending events for this owner:
|
|
|
|
*/
|
|
|
|
PL_MapEvents(self, _pl_DestroyEventForOwner, owner);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
PRCList* qp = self->queue.next;
|
|
|
|
while (qp != &self->queue) {
|
|
|
|
PLEvent* event = PR_EVENT_PTR(qp);
|
|
|
|
qp = qp->next;
|
|
|
|
PR_ASSERT(event->owner != owner);
|
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
PR_ExitMonitor(self->monitor);
|
|
|
|
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
|
|
|
("$$$ revoking events for owner %0x", owner));
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRInt32
|
|
|
|
_pl_GetEventCount(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
PRCList* node;
|
|
|
|
PRInt32 count = 0;
|
|
|
|
|
|
|
|
PR_EnterMonitor(self->monitor);
|
|
|
|
node = PR_LIST_HEAD(&self->queue);
|
|
|
|
while (node != &self->queue) {
|
|
|
|
count++;
|
|
|
|
node = PR_NEXT_LINK(node);
|
|
|
|
}
|
|
|
|
PR_ExitMonitor(self->monitor);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_ProcessPendingEvents(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
PRInt32 count;
|
2000-03-05 21:01:33 +00:00
|
|
|
|
2000-10-03 00:20:05 +00:00
|
|
|
if (self == NULL)
|
2003-03-25 01:38:53 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
2000-09-11 20:59:56 +00:00
|
|
|
PR_EnterMonitor(self->monitor);
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2000-10-04 19:47:12 +00:00
|
|
|
if (self->processingEvents) {
|
2003-03-25 01:38:53 +00:00
|
|
|
_pl_AcknowledgeNativeNotify(self);
|
|
|
|
self->notified = PR_FALSE;
|
|
|
|
PR_ExitMonitor(self->monitor);
|
|
|
|
return;
|
2000-10-04 19:47:12 +00:00
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
self->processingEvents = PR_TRUE;
|
|
|
|
|
|
|
|
/* Only process the events that are already in the queue, and
|
|
|
|
* not any new events that get added. Do this by counting the
|
|
|
|
* number of events currently in the queue
|
|
|
|
*/
|
|
|
|
count = _pl_GetEventCount(self);
|
2000-09-11 20:59:56 +00:00
|
|
|
PR_ExitMonitor(self->monitor);
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
while (count-- > 0) {
|
2003-03-25 01:38:53 +00:00
|
|
|
PLEvent* event = PL_GetEvent(self);
|
|
|
|
if (event == NULL)
|
|
|
|
break;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ processing event"));
|
|
|
|
PL_HandleEvent(event);
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ done processing event"));
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
2000-03-02 21:38:19 +00:00
|
|
|
|
|
|
|
PR_EnterMonitor(self->monitor);
|
2000-09-11 20:59:56 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
if (self->type == EventQueueIsNative) {
|
|
|
|
count = _pl_GetEventCount(self);
|
|
|
|
|
|
|
|
if (count <= 0) {
|
|
|
|
_pl_AcknowledgeNativeNotify(self);
|
|
|
|
self->notified = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_pl_NativeNotify(self);
|
|
|
|
self->notified = PR_TRUE;
|
|
|
|
}
|
2000-09-11 20:59:56 +00:00
|
|
|
|
2000-03-02 21:38:19 +00:00
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
self->processingEvents = PR_FALSE;
|
2000-09-11 20:59:56 +00:00
|
|
|
|
|
|
|
PR_ExitMonitor(self->monitor);
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Event Operations
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_InitEvent(PLEvent* self, void* owner,
|
2000-09-11 20:59:56 +00:00
|
|
|
PLHandleEventProc handler,
|
|
|
|
PLDestroyEventProc destructor)
|
2000-01-25 14:48:51 +00:00
|
|
|
{
|
2000-09-01 00:50:51 +00:00
|
|
|
#ifdef PL_POST_TIMINGS
|
|
|
|
self->postTime = PR_IntervalNow();
|
|
|
|
#endif
|
2000-01-25 14:48:51 +00:00
|
|
|
PR_INIT_CLIST(&self->link);
|
|
|
|
self->handler = handler;
|
|
|
|
self->destructor = destructor;
|
|
|
|
self->owner = owner;
|
|
|
|
self->synchronousResult = NULL;
|
2000-09-01 00:50:51 +00:00
|
|
|
self->handled = PR_FALSE;
|
|
|
|
self->lock = PR_NewLock();
|
|
|
|
PR_ASSERT(self->lock);
|
|
|
|
self->condVar = PR_NewCondVar(self->lock);
|
|
|
|
PR_ASSERT(self->condVar);
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
2001-03-12 23:57:18 +00:00
|
|
|
self->id = 0;
|
2001-03-13 00:42:07 +00:00
|
|
|
#endif
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void*)
|
|
|
|
PL_GetEventOwner(PLEvent* self)
|
|
|
|
{
|
|
|
|
return self->owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_HandleEvent(PLEvent* self)
|
2003-03-25 01:38:53 +00:00
|
|
|
{
|
2000-01-25 14:48:51 +00:00
|
|
|
void* result;
|
|
|
|
if (self == NULL)
|
|
|
|
return;
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
/* This event better not be on an event queue anymore. */
|
|
|
|
PR_ASSERT(PR_CLIST_IS_EMPTY(&self->link));
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
result = self->handler(self);
|
2000-01-25 14:48:51 +00:00
|
|
|
if (NULL != self->synchronousResult) {
|
2003-03-25 01:38:53 +00:00
|
|
|
PR_Lock(self->lock);
|
|
|
|
self->synchronousResult = result;
|
|
|
|
self->handled = PR_TRUE;
|
|
|
|
PR_NotifyCondVar(self->condVar);
|
|
|
|
PR_Unlock(self->lock);
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-03-25 01:38:53 +00:00
|
|
|
/* For asynchronous events, they're destroyed by the event-handler
|
|
|
|
thread. See PR_PostSynchronousEvent. */
|
|
|
|
PL_DestroyEvent(self);
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
}
|
2000-09-01 00:50:51 +00:00
|
|
|
#ifdef PL_POST_TIMINGS
|
|
|
|
static long s_eventCount = 0;
|
|
|
|
static long s_totalTime = 0;
|
|
|
|
#endif
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_DestroyEvent(PLEvent* self)
|
|
|
|
{
|
|
|
|
if (self == NULL)
|
2000-09-01 00:50:51 +00:00
|
|
|
return;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
/* This event better not be on an event queue anymore. */
|
|
|
|
PR_ASSERT(PR_CLIST_IS_EMPTY(&self->link));
|
|
|
|
|
2000-09-01 00:50:51 +00:00
|
|
|
PR_DestroyCondVar(self->condVar);
|
|
|
|
PR_DestroyLock(self->lock);
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2000-09-01 00:50:51 +00:00
|
|
|
#ifdef PL_POST_TIMINGS
|
|
|
|
s_totalTime += PR_IntervalNow() - self->postTime;
|
|
|
|
s_eventCount++;
|
|
|
|
printf("$$$ running avg (%d) \n", PR_IntervalToMilliseconds(s_totalTime/s_eventCount));
|
|
|
|
#endif
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
self->destructor(self);
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_DequeueEvent(PLEvent* self, PLEventQueue* queue)
|
|
|
|
{
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma unused (queue)
|
|
|
|
#endif
|
|
|
|
if (self == NULL)
|
2003-03-25 01:38:53 +00:00
|
|
|
return;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
/* Only the owner is allowed to dequeue events because once the
|
|
|
|
client has put it in the queue, they have no idea whether it's
|
2000-01-25 14:48:51 +00:00
|
|
|
been processed and destroyed or not. */
|
2000-09-11 20:59:56 +00:00
|
|
|
|
2002-09-03 14:51:05 +00:00
|
|
|
PR_ASSERT(queue->handlerThread == PR_GetCurrentThread());
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_EnterMonitor(queue->monitor);
|
|
|
|
|
|
|
|
PR_ASSERT(!PR_CLIST_IS_EMPTY(&self->link));
|
2000-09-11 20:59:56 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* I do not think that we need to do this anymore.
|
|
|
|
if we do not acknowledge and this is the only
|
|
|
|
only event in the queue, any calls to process
|
|
|
|
the eventQ will be effective noop.
|
|
|
|
*/
|
2000-05-31 02:19:17 +00:00
|
|
|
if (queue->type == EventQueueIsNative)
|
|
|
|
_pl_AcknowledgeNativeNotify(queue);
|
2000-09-11 20:59:56 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
PR_REMOVE_AND_INIT_LINK(&self->link);
|
|
|
|
|
|
|
|
PR_ExitMonitor(queue->monitor);
|
|
|
|
}
|
|
|
|
|
2002-09-19 02:53:05 +00:00
|
|
|
PR_IMPLEMENT(void)
|
2003-03-25 01:38:53 +00:00
|
|
|
PL_FavorPerformanceHint(PRBool favorPerformanceOverEventStarvation,
|
|
|
|
PRUint32 starvationDelay)
|
2002-09-19 02:53:05 +00:00
|
|
|
{
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
_md_StarvationDelay = starvationDelay;
|
2002-10-01 03:04:22 +00:00
|
|
|
|
|
|
|
if (favorPerformanceOverEventStarvation) {
|
2003-03-25 01:38:53 +00:00
|
|
|
_md_PerformanceSetting++;
|
|
|
|
return;
|
2002-10-01 03:04:22 +00:00
|
|
|
}
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2002-10-01 03:04:22 +00:00
|
|
|
_md_PerformanceSetting--;
|
|
|
|
|
|
|
|
if (_md_PerformanceSetting == 0) {
|
|
|
|
/* Switched from allowing event starvation to no event starvation so grab
|
|
|
|
the current time to determine when to actually switch to using timers
|
|
|
|
instead of posted WM_APP messages. */
|
|
|
|
_md_SwitchTime = PR_IntervalToMilliseconds(PR_IntervalNow());
|
2002-09-19 02:53:05 +00:00
|
|
|
}
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2002-09-19 02:53:05 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Pure Event Queues
|
|
|
|
*
|
|
|
|
* For when you're only processing PLEvents and there is no native
|
|
|
|
* select, thread messages, or AppleEvents.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
PR_IMPLEMENT(PLEvent*)
|
|
|
|
PL_WaitForEvent(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
PLEvent* event;
|
|
|
|
PRMonitor* mon;
|
|
|
|
|
|
|
|
if (self == NULL)
|
2003-03-25 01:38:53 +00:00
|
|
|
return NULL;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
mon = self->monitor;
|
|
|
|
PR_EnterMonitor(mon);
|
|
|
|
|
|
|
|
while ((event = PL_GetEvent(self)) == NULL) {
|
|
|
|
PRStatus err;
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ waiting for event"));
|
|
|
|
err = PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
|
|
|
|
if ((err == PR_FAILURE)
|
|
|
|
&& (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_ExitMonitor(mon);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_EventLoop(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
if (self == NULL)
|
2003-03-25 01:38:53 +00:00
|
|
|
return;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
while (PR_TRUE) {
|
2000-09-11 20:59:56 +00:00
|
|
|
PLEvent* event = PL_WaitForEvent(self);
|
|
|
|
if (event == NULL) {
|
|
|
|
/* This can only happen if the current thread is interrupted */
|
|
|
|
return;
|
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ processing event"));
|
2000-09-11 20:59:56 +00:00
|
|
|
PL_HandleEvent(event);
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ done processing event"));
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Native Event Queues
|
|
|
|
*
|
|
|
|
* For when you need to call select, or WaitNextEvent, and yet also want
|
|
|
|
* to handle PLEvents.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
static PRStatus
|
|
|
|
_pl_SetupNativeNotifier(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
#if defined(XP_MAC)
|
|
|
|
#pragma unused (self)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(VMS)
|
2001-03-16 21:39:49 +00:00
|
|
|
unsigned int status;
|
|
|
|
self->idFunc = 0;
|
|
|
|
self->idFuncClosure = 0;
|
|
|
|
status = LIB$GET_EF(&self->efn);
|
|
|
|
if (!$VMS_STATUS_SUCCESS(status))
|
|
|
|
return PR_FAILURE;
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
2003-03-25 01:38:53 +00:00
|
|
|
("$$$ Allocated event flag %d", self->efn));
|
2001-03-16 21:39:49 +00:00
|
|
|
return PR_SUCCESS;
|
2002-12-19 15:25:57 +00:00
|
|
|
#elif defined(XP_UNIX) && !defined(XP_MACOSX)
|
2000-01-25 14:48:51 +00:00
|
|
|
int err;
|
|
|
|
int flags;
|
|
|
|
|
2001-03-12 23:57:18 +00:00
|
|
|
self->idFunc = 0;
|
|
|
|
self->idFuncClosure = 0;
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
err = pipe(self->eventPipe);
|
|
|
|
if (err != 0) {
|
|
|
|
return PR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make the pipe nonblocking */
|
|
|
|
flags = fcntl(self->eventPipe[0], F_GETFL, 0);
|
|
|
|
if (flags == -1) {
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
err = fcntl(self->eventPipe[0], F_SETFL, flags | O_NONBLOCK);
|
|
|
|
if (err == -1) {
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
flags = fcntl(self->eventPipe[1], F_GETFL, 0);
|
|
|
|
if (flags == -1) {
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
err = fcntl(self->eventPipe[1], F_SETFL, flags | O_NONBLOCK);
|
|
|
|
if (err == -1) {
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
return PR_SUCCESS;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
close(self->eventPipe[0]);
|
|
|
|
close(self->eventPipe[1]);
|
|
|
|
return PR_FAILURE;
|
|
|
|
#elif defined(XP_BEOS)
|
2003-03-25 01:38:53 +00:00
|
|
|
/* hook up to the nsToolkit queue, however the appshell
|
|
|
|
* isn't necessairly started, so we might have to create
|
|
|
|
* the queue ourselves
|
|
|
|
*/
|
|
|
|
char portname[64];
|
|
|
|
char semname[64];
|
|
|
|
sprintf(portname, "event%lx", self->handlerThread);
|
|
|
|
sprintf(semname, "sync%lx", self->handlerThread);
|
|
|
|
|
|
|
|
if((self->eventport = find_port(portname)) < 0)
|
|
|
|
{
|
|
|
|
/* create port
|
|
|
|
*/
|
|
|
|
self->eventport = create_port(500, portname);
|
|
|
|
|
|
|
|
/* We don't use the sem, but it has to be there
|
|
|
|
*/
|
|
|
|
create_sem(0, semname);
|
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
return PR_SUCCESS;
|
|
|
|
#else
|
|
|
|
return PR_SUCCESS;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_pl_CleanupNativeNotifier(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
#if defined(XP_MAC)
|
|
|
|
#pragma unused (self)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(VMS)
|
|
|
|
{
|
|
|
|
unsigned int status;
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
|
|
|
("$$$ Freeing event flag %d", self->efn));
|
|
|
|
status = LIB$FREE_EF(&self->efn);
|
|
|
|
}
|
2002-12-19 15:25:57 +00:00
|
|
|
#elif defined(XP_UNIX) && !defined(XP_MACOSX)
|
2000-01-25 14:48:51 +00:00
|
|
|
close(self->eventPipe[0]);
|
|
|
|
close(self->eventPipe[1]);
|
2003-03-25 01:38:53 +00:00
|
|
|
#elif defined(_WIN32)
|
2002-08-29 23:04:14 +00:00
|
|
|
if (self->timerSet) {
|
2003-03-25 01:38:53 +00:00
|
|
|
KillTimer(self->eventReceiverWindow, TIMER_ID);
|
|
|
|
self->timerSet = PR_FALSE;
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
|
|
|
RemoveProp(self->eventReceiverWindow, _md_GetEventQueuePropName());
|
2003-01-14 23:50:01 +00:00
|
|
|
|
2003-01-15 19:35:28 +00:00
|
|
|
// DestroyWindow doesn't do anything when called from a non ui thread. Since
|
2003-01-14 23:50:01 +00:00
|
|
|
// self->eventReceiverWindow was created on the ui thread, it must be destroyed
|
|
|
|
// on the ui thread.
|
|
|
|
SendMessage(self->eventReceiverWindow, WM_CLOSE, 0, 0);
|
|
|
|
|
2000-10-03 00:20:05 +00:00
|
|
|
#elif defined(XP_OS2)
|
2003-02-21 14:52:06 +00:00
|
|
|
WinDestroyWindow(self->eventReceiverWindow);
|
2002-12-19 15:25:57 +00:00
|
|
|
#elif defined(MAC_USE_CARBON_EVENT)
|
|
|
|
EventComparatorUPP comparator = NewEventComparatorUPP(_md_CarbonEventComparator);
|
|
|
|
PR_ASSERT(comparator != NULL);
|
|
|
|
if (comparator) {
|
|
|
|
FlushSpecificEventsFromQueue(GetMainEventQueue(), comparator, self);
|
|
|
|
DisposeEventComparatorUPP(comparator);
|
|
|
|
}
|
|
|
|
DisposeEventHandlerUPP(self->eventHandlerUPP);
|
|
|
|
RemoveEventHandler(self->eventHandlerRef);
|
2000-01-25 14:48:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
#if defined(_WIN32)
|
2002-08-29 23:04:14 +00:00
|
|
|
|
|
|
|
static PRBool _md_WasInputPending = PR_FALSE;
|
|
|
|
static PRUint32 _md_InputTime = 0;
|
|
|
|
static PRBool _md_WasPaintPending = PR_FALSE;
|
|
|
|
static PRUint32 _md_PaintTime = 0;
|
|
|
|
/* last mouse location */
|
|
|
|
static POINT _md_LastMousePos;
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Timer callback function. Timers are used on WIN32 instead of APP events
|
|
|
|
* when there are pending UI events because APP events can cause the GUI to lockup
|
|
|
|
* because posted messages are processed before other messages.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
static void CALLBACK _md_TimerProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
|
|
|
|
{
|
|
|
|
PREventQueue* queue = (PREventQueue *) GetProp(hwnd, _md_GetEventQueuePropName());
|
|
|
|
PR_ASSERT(queue != NULL);
|
|
|
|
|
|
|
|
KillTimer(hwnd, TIMER_ID);
|
|
|
|
queue->timerSet = PR_FALSE;
|
|
|
|
queue->removeMsg = PR_FALSE;
|
|
|
|
PL_ProcessPendingEvents( queue );
|
|
|
|
queue->removeMsg = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool _md_IsWIN9X = PR_FALSE;
|
|
|
|
static PRBool _md_IsOSSet = PR_FALSE;
|
|
|
|
|
|
|
|
static void _md_DetermineOSType()
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
OSVERSIONINFO os;
|
|
|
|
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
GetVersionEx(&os);
|
|
|
|
if (VER_PLATFORM_WIN32_WINDOWS == os.dwPlatformId) {
|
|
|
|
_md_IsWIN9X = PR_TRUE;
|
|
|
|
}
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
static PRUint32 _md_GetPaintStarvationLimit()
|
|
|
|
{
|
|
|
|
if (! _md_IsOSSet) {
|
|
|
|
_md_DetermineOSType();
|
|
|
|
_md_IsOSSet = PR_TRUE;
|
|
|
|
}
|
2002-08-29 23:04:14 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
if (_md_IsWIN9X) {
|
|
|
|
return WIN9X_PAINT_STARVATION_LIMIT;
|
|
|
|
}
|
2002-08-29 23:04:14 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
return PAINT_STARVATION_LIMIT;
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
/*
|
|
|
|
* Determine if an event is being starved (i.e the starvation limit has
|
|
|
|
* been exceeded.
|
|
|
|
* Note: this function uses the current setting and updates the contents
|
|
|
|
* of the wasPending and lastTime arguments
|
2002-08-29 23:04:14 +00:00
|
|
|
*
|
2003-03-25 01:38:53 +00:00
|
|
|
* ispending: PR_TRUE if the event is currently pending
|
|
|
|
* starvationLimit: Threshold defined in milliseconds for determining when
|
|
|
|
* the event has been held in the queue too long
|
|
|
|
* wasPending: PR_TRUE if the last time _md_EventIsStarved was called
|
|
|
|
* the event was pending. This value is updated within
|
|
|
|
* this function.
|
|
|
|
* lastTime: Holds the last time the event was in the queue.
|
2002-08-29 23:04:14 +00:00
|
|
|
* This value is updated within this function
|
|
|
|
* returns: PR_TRUE if the event is starved, PR_FALSE otherwise
|
|
|
|
*/
|
2003-03-25 01:38:53 +00:00
|
|
|
|
|
|
|
static PRBool _md_EventIsStarved(PRBool isPending, PRUint32 starvationLimit,
|
2002-09-19 02:53:05 +00:00
|
|
|
PRBool *wasPending, PRUint32 *lastTime,
|
2003-03-25 01:38:53 +00:00
|
|
|
PRUint32 currentTime)
|
2002-08-29 23:04:14 +00:00
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
if (*wasPending && isPending) {
|
|
|
|
/*
|
|
|
|
* It was pending previously and the event is still
|
|
|
|
* pending so check to see if the elapsed time is
|
|
|
|
* over the limit which indicates the event was starved
|
|
|
|
*/
|
|
|
|
if ((currentTime - *lastTime) > starvationLimit) {
|
|
|
|
return PR_TRUE; /* pending and over the limit */
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE; /* pending but within the limit */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPending) {
|
|
|
|
/*
|
|
|
|
* was_pending must be false so record the current time
|
|
|
|
* so the elapsed time can be computed the next time this
|
|
|
|
* function is called
|
|
|
|
*/
|
|
|
|
*lastTime = currentTime;
|
|
|
|
*wasPending = PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Event is no longer pending */
|
|
|
|
*wasPending = PR_FALSE;
|
|
|
|
return PR_FALSE;
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Determines if the there is a pending Mouse or input event */
|
|
|
|
|
|
|
|
static PRBool _md_IsInputPending(WORD qstatus)
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
/* Return immediately there aren't any pending input or paints. */
|
|
|
|
if (qstatus == 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is there anything other than a QS_MOUSEMOVE pending? */
|
|
|
|
if ((qstatus & QS_MOUSEBUTTON) ||
|
|
|
|
(qstatus & QS_KEY) ||
|
|
|
|
(qstatus & QS_HOTKEY)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mouse moves need extra processing to determine if the mouse
|
|
|
|
* pointer actually changed location because Windows automatically
|
|
|
|
* generates WM_MOVEMOVE events when a new window is created which
|
|
|
|
* we need to filter out.
|
|
|
|
*/
|
|
|
|
if (qstatus & QS_MOUSEMOVE) {
|
|
|
|
POINT cursorPos;
|
|
|
|
GetCursorPos(&cursorPos);
|
|
|
|
if ((_md_LastMousePos.x == cursorPos.x) &&
|
|
|
|
(_md_LastMousePos.y == cursorPos.y)) {
|
|
|
|
return PR_FALSE; /* This is a fake mouse move */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Real mouse move */
|
|
|
|
_md_LastMousePos.x = cursorPos.x;
|
|
|
|
_md_LastMousePos.y = cursorPos.y;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
static PRStatus
|
|
|
|
_pl_NativeNotify(PLEventQueue* self)
|
|
|
|
{
|
2002-08-29 23:04:14 +00:00
|
|
|
#ifdef USE_TIMER
|
|
|
|
WORD qstatus;
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
PRUint32 now = PR_IntervalToMilliseconds(PR_IntervalNow());
|
2002-09-19 02:53:05 +00:00
|
|
|
|
2002-10-01 03:04:22 +00:00
|
|
|
/* Since calls to set the _md_PerformanceSetting can be nested
|
|
|
|
* only performance setting values <= 0 will potentially trigger
|
|
|
|
* the use of a timer.
|
|
|
|
*/
|
2003-03-25 01:38:53 +00:00
|
|
|
if ((_md_PerformanceSetting <= 0) &&
|
2002-09-19 02:53:05 +00:00
|
|
|
((now - _md_SwitchTime) > _md_StarvationDelay)) {
|
2003-03-25 01:38:53 +00:00
|
|
|
SetTimer(self->eventReceiverWindow, TIMER_ID, 0 ,_md_TimerProc);
|
|
|
|
self->timerSet = PR_TRUE;
|
|
|
|
_md_WasInputPending = PR_FALSE;
|
|
|
|
_md_WasPaintPending = PR_FALSE;
|
|
|
|
return PR_SUCCESS;
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qstatus = HIWORD(GetQueueStatus(QS_INPUT | QS_PAINT));
|
|
|
|
|
|
|
|
/* Check for starved input */
|
2003-03-25 01:38:53 +00:00
|
|
|
if (_md_EventIsStarved( _md_IsInputPending(qstatus),
|
|
|
|
INPUT_STARVATION_LIMIT,
|
|
|
|
&_md_WasInputPending,
|
|
|
|
&_md_InputTime,
|
|
|
|
now )) {
|
|
|
|
/*
|
|
|
|
* Use a timer for notification. Timers have the lowest priority.
|
|
|
|
* They are not processed until all other events have been processed.
|
|
|
|
* This allows any starved paints and input to be processed.
|
|
|
|
*/
|
|
|
|
SetTimer(self->eventReceiverWindow, TIMER_ID, 0 ,_md_TimerProc);
|
|
|
|
self->timerSet = PR_TRUE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear any pending paint. _md_WasInputPending was cleared in
|
|
|
|
* _md_EventIsStarved.
|
|
|
|
*/
|
|
|
|
_md_WasPaintPending = PR_FALSE;
|
|
|
|
return PR_SUCCESS;
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
2003-03-25 01:38:53 +00:00
|
|
|
|
|
|
|
if (_md_EventIsStarved( (qstatus & QS_PAINT),
|
|
|
|
_md_GetPaintStarvationLimit(),
|
|
|
|
&_md_WasPaintPending,
|
|
|
|
&_md_PaintTime,
|
|
|
|
now) ) {
|
|
|
|
/*
|
|
|
|
* Use a timer for notification. Timers have the lowest priority.
|
|
|
|
* They are not processed until all other events have been processed.
|
|
|
|
* This allows any starved paints and input to be processed
|
|
|
|
*/
|
|
|
|
SetTimer(self->eventReceiverWindow, TIMER_ID, 0 ,_md_TimerProc);
|
|
|
|
self->timerSet = PR_TRUE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear any pending input. _md_WasPaintPending was cleared in
|
|
|
|
* _md_EventIsStarved.
|
|
|
|
*/
|
|
|
|
_md_WasInputPending = PR_FALSE;
|
|
|
|
return PR_SUCCESS;
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
2003-03-25 01:38:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing is being starved so post a message instead of using a timer.
|
|
|
|
* Posted messages are processed before other messages so they have the
|
|
|
|
* highest priority.
|
2002-08-29 23:04:14 +00:00
|
|
|
*/
|
|
|
|
#endif
|
2000-10-03 00:20:05 +00:00
|
|
|
PostMessage( self->eventReceiverWindow, _pr_PostEventMsgId,
|
2002-08-29 23:04:14 +00:00
|
|
|
(WPARAM)0, (LPARAM)self );
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
return PR_SUCCESS;
|
|
|
|
}/* --- end _pl_NativeNotify() --- */
|
|
|
|
#endif
|
|
|
|
|
2002-08-29 23:04:14 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
#if defined(XP_OS2)
|
|
|
|
static PRStatus
|
|
|
|
_pl_NativeNotify(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
BOOL rc = WinPostMsg( self->eventReceiverWindow, _pr_PostEventMsgId,
|
2000-10-03 00:20:05 +00:00
|
|
|
0, MPFROMP(self));
|
2000-01-25 14:48:51 +00:00
|
|
|
return (rc == TRUE) ? PR_SUCCESS : PR_FAILURE;
|
|
|
|
}/* --- end _pl_NativeNotify() --- */
|
|
|
|
#endif /* XP_OS2 */
|
|
|
|
|
|
|
|
#if defined(VMS)
|
|
|
|
/* Just set the event flag */
|
|
|
|
static PRStatus
|
|
|
|
_pl_NativeNotify(PLEventQueue* self)
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
unsigned int status;
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
2000-09-11 20:59:56 +00:00
|
|
|
("_pl_NativeNotify: self=%p efn=%d",
|
|
|
|
self, self->efn));
|
2003-03-25 01:38:53 +00:00
|
|
|
status = SYS$SETEF(self->efn);
|
|
|
|
return ($VMS_STATUS_SUCCESS(status)) ? PR_SUCCESS : PR_FAILURE;
|
2000-01-25 14:48:51 +00:00
|
|
|
}/* --- end _pl_NativeNotify() --- */
|
2002-12-19 15:25:57 +00:00
|
|
|
#elif defined(XP_UNIX) && !defined(XP_MACOSX)
|
2000-09-11 20:59:56 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
static PRStatus
|
|
|
|
_pl_NativeNotify(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
#define NOTIFY_TOKEN 0xFA
|
|
|
|
PRInt32 count;
|
|
|
|
unsigned char buf[] = { NOTIFY_TOKEN };
|
|
|
|
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
2000-09-11 20:59:56 +00:00
|
|
|
("_pl_NativeNotify: self=%p",
|
|
|
|
self));
|
2000-01-25 14:48:51 +00:00
|
|
|
count = write(self->eventPipe[1], buf, 1);
|
2003-03-25 01:38:53 +00:00
|
|
|
if (count == 1)
|
|
|
|
return PR_SUCCESS;
|
|
|
|
if (count == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
|
|
|
|
return PR_SUCCESS;
|
|
|
|
return PR_FAILURE;
|
2000-01-25 14:48:51 +00:00
|
|
|
}/* --- end _pl_NativeNotify() --- */
|
2002-12-19 15:25:57 +00:00
|
|
|
#endif /* defined(XP_UNIX) && !defined(XP_MACOSX) */
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
#if defined(XP_BEOS)
|
|
|
|
struct ThreadInterfaceData
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
void *data;
|
|
|
|
int32 sync;
|
2000-01-25 14:48:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static PRStatus
|
|
|
|
_pl_NativeNotify(PLEventQueue* self)
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
struct ThreadInterfaceData id;
|
|
|
|
id.data = self;
|
|
|
|
id.sync = false;
|
|
|
|
write_port(self->eventport, 'natv', &id, sizeof(id));
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
return PR_SUCCESS; /* Is this correct? */
|
|
|
|
}
|
|
|
|
#endif /* XP_BEOS */
|
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(XP_MAC) || defined(XP_MACOSX)
|
2000-01-25 14:48:51 +00:00
|
|
|
static PRStatus
|
|
|
|
_pl_NativeNotify(PLEventQueue* self)
|
|
|
|
{
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(MAC_USE_CARBON_EVENT)
|
|
|
|
OSErr err;
|
|
|
|
EventRef newEvent;
|
|
|
|
if (CreateEvent(NULL, kEventClassPL, kEventProcessPLEvents,
|
|
|
|
0, kEventAttributeNone, &newEvent) != noErr)
|
|
|
|
return PR_FAILURE;
|
|
|
|
err = SetEventParameter(newEvent, kEventParamPLEventQueue,
|
|
|
|
typeUInt32, sizeof(PREventQueue*), &self);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = PostEventToQueue(GetMainEventQueue(), newEvent, kEventPriorityLow);
|
|
|
|
ReleaseEvent(newEvent);
|
|
|
|
}
|
|
|
|
if (err != noErr)
|
|
|
|
return PR_FAILURE;
|
|
|
|
#elif defined(MAC_USE_WAKEUPPROCESS)
|
2002-03-27 07:16:12 +00:00
|
|
|
WakeUpProcess(&self->psn);
|
2002-12-19 15:25:57 +00:00
|
|
|
#endif
|
|
|
|
return PR_SUCCESS;
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
2002-12-19 15:25:57 +00:00
|
|
|
#endif /* defined(XP_MAC) || defined(XP_MACOSX) */
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
static PRStatus
|
|
|
|
_pl_AcknowledgeNativeNotify(PLEventQueue* self)
|
|
|
|
{
|
2002-08-29 23:04:14 +00:00
|
|
|
#if defined(_WIN32) || defined(XP_OS2)
|
2000-10-03 00:20:05 +00:00
|
|
|
#ifdef XP_OS2
|
|
|
|
QMSG aMsg;
|
|
|
|
#else
|
2000-01-25 14:48:51 +00:00
|
|
|
MSG aMsg;
|
2000-10-03 00:20:05 +00:00
|
|
|
#endif
|
2000-01-25 14:48:51 +00:00
|
|
|
/*
|
|
|
|
* only remove msg when we've been called directly by
|
|
|
|
* PL_ProcessPendingEvents, not when we've been called by
|
|
|
|
* the window proc because the window proc will remove the
|
|
|
|
* msg for us.
|
|
|
|
*/
|
|
|
|
if (self->removeMsg) {
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
2003-03-25 01:38:53 +00:00
|
|
|
("_pl_AcknowledgeNativeNotify: self=%p", self));
|
2000-10-03 00:20:05 +00:00
|
|
|
#ifdef XP_OS2
|
|
|
|
WinPeekMsg((HAB)0, &aMsg, self->eventReceiverWindow,
|
|
|
|
_pr_PostEventMsgId, _pr_PostEventMsgId, PM_REMOVE);
|
|
|
|
#else
|
2000-01-25 14:48:51 +00:00
|
|
|
PeekMessage(&aMsg, self->eventReceiverWindow,
|
2003-03-25 01:38:53 +00:00
|
|
|
_pr_PostEventMsgId, _pr_PostEventMsgId, PM_REMOVE);
|
2002-08-29 23:04:14 +00:00
|
|
|
if (self->timerSet) {
|
2003-03-25 01:38:53 +00:00
|
|
|
KillTimer(self->eventReceiverWindow, TIMER_ID);
|
|
|
|
self->timerSet = PR_FALSE;
|
2002-08-29 23:04:14 +00:00
|
|
|
}
|
2000-10-03 00:20:05 +00:00
|
|
|
#endif
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
return PR_SUCCESS;
|
|
|
|
#elif defined(VMS)
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
2000-09-11 20:59:56 +00:00
|
|
|
("_pl_AcknowledgeNativeNotify: self=%p efn=%d",
|
|
|
|
self, self->efn));
|
2000-01-25 14:48:51 +00:00
|
|
|
/*
|
|
|
|
** If this is the last entry, then clear the event flag. Also make sure
|
|
|
|
** the flag is cleared on any spurious wakeups.
|
|
|
|
*/
|
2000-09-11 20:59:56 +00:00
|
|
|
sys$clref(self->efn);
|
2000-01-25 14:48:51 +00:00
|
|
|
return PR_SUCCESS;
|
2002-12-19 15:25:57 +00:00
|
|
|
#elif defined(XP_UNIX) && !defined(XP_MACOSX)
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
PRInt32 count;
|
|
|
|
unsigned char c;
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
2000-09-11 20:59:56 +00:00
|
|
|
("_pl_AcknowledgeNativeNotify: self=%p",
|
|
|
|
self));
|
2003-03-25 01:38:53 +00:00
|
|
|
/* consume the byte NativeNotify put in our pipe: */
|
2000-01-25 14:48:51 +00:00
|
|
|
count = read(self->eventPipe[0], &c, 1);
|
2003-03-25 01:38:53 +00:00
|
|
|
if ((count == 1) && (c == NOTIFY_TOKEN))
|
|
|
|
return PR_SUCCESS;
|
|
|
|
if ((count == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK)))
|
|
|
|
return PR_SUCCESS;
|
|
|
|
return PR_FAILURE;
|
2000-01-25 14:48:51 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
#if defined(XP_MAC)
|
|
|
|
#pragma unused (self)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* nothing to do on the other platforms */
|
|
|
|
return PR_SUCCESS;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(PRInt32)
|
|
|
|
PL_GetEventQueueSelectFD(PLEventQueue* self)
|
|
|
|
{
|
|
|
|
if (self == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
#if defined(VMS)
|
|
|
|
return -(self->efn);
|
2002-12-19 15:25:57 +00:00
|
|
|
#elif defined(XP_UNIX) && !defined(XP_MACOSX)
|
2000-01-25 14:48:51 +00:00
|
|
|
return self->eventPipe[0];
|
|
|
|
#else
|
|
|
|
return -1; /* other platforms don't handle this (yet) */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(PRBool)
|
|
|
|
PL_IsQueueOnCurrentThread( PLEventQueue *queue )
|
|
|
|
{
|
|
|
|
PRThread *me = PR_GetCurrentThread();
|
2003-03-25 01:38:53 +00:00
|
|
|
return me == queue->handlerThread;
|
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
|
2000-03-04 03:17:01 +00:00
|
|
|
PR_EXTERN(PRBool)
|
|
|
|
PL_IsQueueNative(PLEventQueue *queue)
|
|
|
|
{
|
|
|
|
return queue->type == EventQueueIsNative ? PR_TRUE : PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-08-29 23:04:14 +00:00
|
|
|
#if defined(_WIN32)
|
2000-01-25 14:48:51 +00:00
|
|
|
/*
|
|
|
|
** Global Instance handle...
|
|
|
|
** In Win32 this is the module handle of the DLL.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
static HINSTANCE _pr_hInstance;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
|
|
|
|
/*
|
2001-11-14 01:37:41 +00:00
|
|
|
** Initialization routine for the DLL...
|
2000-01-25 14:48:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
switch (dwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
_pr_hInstance = hDLL;
|
|
|
|
break;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
break;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
break;
|
2000-01-25 14:48:51 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
_pr_hInstance = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-08-29 23:04:14 +00:00
|
|
|
#if defined(_WIN32) || defined(XP_OS2)
|
2000-01-25 14:48:51 +00:00
|
|
|
#ifdef XP_OS2
|
|
|
|
MRESULT EXPENTRY
|
|
|
|
_md_EventReceiverProc(HWND hwnd, ULONG uMsg, MPARAM wParam, MPARAM lParam)
|
|
|
|
#else
|
2003-03-25 01:38:53 +00:00
|
|
|
LRESULT CALLBACK
|
2000-01-25 14:48:51 +00:00
|
|
|
_md_EventReceiverProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (_pr_PostEventMsgId == uMsg )
|
|
|
|
{
|
2000-10-03 00:20:05 +00:00
|
|
|
PREventQueue *queue = (PREventQueue *)lParam;
|
2000-01-25 14:48:51 +00:00
|
|
|
queue->removeMsg = PR_FALSE;
|
2000-07-07 04:17:24 +00:00
|
|
|
PL_ProcessPendingEvents(queue);
|
2000-01-25 14:48:51 +00:00
|
|
|
queue->removeMsg = PR_TRUE;
|
|
|
|
#ifdef XP_OS2
|
2000-10-03 00:20:05 +00:00
|
|
|
return MRFROMLONG(TRUE);
|
2000-01-25 14:48:51 +00:00
|
|
|
#else
|
2000-10-03 00:20:05 +00:00
|
|
|
return TRUE;
|
2000-01-25 14:48:51 +00:00
|
|
|
#endif
|
2000-10-03 00:20:05 +00:00
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool isInitialized;
|
|
|
|
static PRCallOnceType once;
|
|
|
|
static PRLock *initLock;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** InitWinEventLib() -- Create the Windows initialization lock
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
static PRStatus InitEventLib( void )
|
|
|
|
{
|
|
|
|
PR_ASSERT( initLock == NULL );
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
initLock = PR_NewLock();
|
2003-03-25 01:38:53 +00:00
|
|
|
return initLock ? PR_SUCCESS : PR_FAILURE;
|
|
|
|
}
|
2000-01-25 14:48:51 +00:00
|
|
|
|
2002-08-29 23:04:14 +00:00
|
|
|
#endif /* Win32, OS2 */
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
#if defined(_WIN32)
|
2002-08-29 23:04:14 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
/*
|
|
|
|
** _md_CreateEventQueue() -- ModelDependent initializer
|
|
|
|
*/
|
|
|
|
static void _md_CreateEventQueue( PLEventQueue *eventQueue )
|
|
|
|
{
|
|
|
|
WNDCLASS wc;
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
/*
|
|
|
|
** If this is the first call to PL_InitializeEventsLib(),
|
|
|
|
** make the call to InitWinEventLib() to create the initLock.
|
|
|
|
**
|
|
|
|
** Then lock the initializer lock to insure that
|
|
|
|
** we have exclusive control over the initialization sequence.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2001-11-14 01:37:41 +00:00
|
|
|
/* Register the windows message for XPCOM Event notification */
|
|
|
|
_pr_PostEventMsgId = RegisterWindowMessage("XPCOM_PostEvent");
|
2000-01-25 14:48:51 +00:00
|
|
|
|
|
|
|
/* Register the class for the event receiver window */
|
|
|
|
if (!GetClassInfo(_pr_hInstance, _pr_eventWindowClass, &wc)) {
|
|
|
|
wc.style = 0;
|
|
|
|
wc.lpfnWndProc = _md_EventReceiverProc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = _pr_hInstance;
|
|
|
|
wc.hIcon = NULL;
|
|
|
|
wc.hCursor = NULL;
|
|
|
|
wc.hbrBackground = (HBRUSH) NULL;
|
|
|
|
wc.lpszMenuName = (LPCSTR) NULL;
|
|
|
|
wc.lpszClassName = _pr_eventWindowClass;
|
|
|
|
RegisterClass(&wc);
|
2003-03-25 01:38:53 +00:00
|
|
|
}
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
/* Create the event receiver window */
|
|
|
|
eventQueue->eventReceiverWindow = CreateWindow(_pr_eventWindowClass,
|
2001-11-14 01:37:41 +00:00
|
|
|
"XPCOM:EventReceiver",
|
2000-01-25 14:48:51 +00:00
|
|
|
0, 0, 0, 10, 10,
|
|
|
|
NULL, NULL, _pr_hInstance,
|
|
|
|
NULL);
|
|
|
|
PR_ASSERT(eventQueue->eventReceiverWindow);
|
2003-03-25 01:38:53 +00:00
|
|
|
/* Set a property which can be used to retrieve the event queue
|
|
|
|
* within the _md_TimerProc callback
|
2002-08-29 23:04:14 +00:00
|
|
|
*/
|
|
|
|
SetProp(eventQueue->eventReceiverWindow,
|
|
|
|
_md_GetEventQueuePropName(), (HANDLE)eventQueue);
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
return;
|
2000-01-25 14:48:51 +00:00
|
|
|
} /* end _md_CreateEventQueue() */
|
|
|
|
#endif /* Winxx */
|
|
|
|
|
|
|
|
#if defined(XP_OS2)
|
2003-03-21 22:26:41 +00:00
|
|
|
/* These functions/values are defined in the EMX libraries, but are not declared
|
|
|
|
in the GCC 3.2.1 headers. */
|
|
|
|
#ifdef XP_OS2_EMX
|
|
|
|
unsigned _control87 (unsigned, unsigned);
|
|
|
|
#define MCW_EM 0x003f
|
|
|
|
#define MCW_IC 0x1000
|
|
|
|
#define MCW_RC 0x0c00
|
|
|
|
#define MCW_PC 0x0300
|
|
|
|
#endif
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
/*
|
|
|
|
** _md_CreateEventQueue() -- ModelDependent initializer
|
|
|
|
*/
|
|
|
|
static void _md_CreateEventQueue( PLEventQueue *eventQueue )
|
|
|
|
{
|
|
|
|
/* Must have HMQ for this & can't assume we already have appshell */
|
|
|
|
if( FALSE == WinQueryQueueInfo( HMQ_CURRENT, NULL, 0))
|
|
|
|
{
|
2003-03-21 22:26:41 +00:00
|
|
|
unsigned cw;
|
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
HAB hab = WinInitialize( 0);
|
2003-03-21 22:26:41 +00:00
|
|
|
|
|
|
|
#ifdef XP_OS2_EMX
|
|
|
|
/* It seems that WinCreateMsgQueue likes to change the floating point
|
|
|
|
control word for undocumented reasons. Unfortunately, it causes
|
|
|
|
floating point exceptions (SIGFPE) to be unmasked, so we crash in
|
|
|
|
javascript on startup. The two calls to _control87 simply save the
|
|
|
|
current value of the control word and resets it after the call */
|
|
|
|
cw = _control87(0,0);
|
|
|
|
#endif
|
2000-01-25 14:48:51 +00:00
|
|
|
WinCreateMsgQueue( hab, 0);
|
2003-03-21 22:26:41 +00:00
|
|
|
#ifdef XP_OS2_EMX
|
|
|
|
_control87(cw, MCW_EM | MCW_IC | MCW_RC | MCW_PC);
|
|
|
|
#endif
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !_pr_PostEventMsgId)
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
WinRegisterClass( 0 /* hab_current */,
|
2000-01-25 14:48:51 +00:00
|
|
|
_pr_eventWindowClass,
|
|
|
|
_md_EventReceiverProc,
|
|
|
|
0, 0);
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
_pr_PostEventMsgId = WinAddAtom( WinQuerySystemAtomTable(),
|
2001-11-14 01:37:41 +00:00
|
|
|
"XPCOM_PostEvent");
|
2000-01-25 14:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
eventQueue->eventReceiverWindow = WinCreateWindow( HWND_DESKTOP,
|
|
|
|
_pr_eventWindowClass,
|
|
|
|
"", 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
HWND_DESKTOP,
|
|
|
|
HWND_TOP,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
PR_ASSERT(eventQueue->eventReceiverWindow);
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
return;
|
2000-01-25 14:48:51 +00:00
|
|
|
} /* end _md_CreateEventQueue() */
|
|
|
|
#endif /* XP_OS2 */
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
#if (defined(XP_UNIX) && !defined(XP_MACOSX)) || defined(XP_BEOS)
|
2000-01-25 14:48:51 +00:00
|
|
|
/*
|
|
|
|
** _md_CreateEventQueue() -- ModelDependent initializer
|
|
|
|
*/
|
|
|
|
static void _md_CreateEventQueue( PLEventQueue *eventQueue )
|
|
|
|
{
|
|
|
|
/* there's really nothing special to do here,
|
|
|
|
** the guts of the unix stuff is in the setupnativenotify
|
|
|
|
** and related functions.
|
|
|
|
*/
|
2003-03-25 01:38:53 +00:00
|
|
|
return;
|
2000-01-25 14:48:51 +00:00
|
|
|
} /* end _md_CreateEventQueue() */
|
2002-12-19 15:25:57 +00:00
|
|
|
#endif /* (defined(XP_UNIX) && !defined(XP_MACOSX)) || defined(XP_BEOS) */
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(MAC_USE_CARBON_EVENT)
|
2002-03-27 07:16:12 +00:00
|
|
|
/*
|
|
|
|
** _md_CreateEventQueue() -- ModelDependent initializer
|
|
|
|
*/
|
2002-12-19 15:25:57 +00:00
|
|
|
|
|
|
|
static pascal OSStatus _md_EventReceiverProc(EventHandlerCallRef nextHandler,
|
2003-03-25 01:38:53 +00:00
|
|
|
EventRef inEvent,
|
2002-12-19 15:25:57 +00:00
|
|
|
void* userData)
|
|
|
|
{
|
|
|
|
if (GetEventClass(inEvent) == kEventClassPL &&
|
|
|
|
GetEventKind(inEvent) == kEventProcessPLEvents)
|
|
|
|
{
|
|
|
|
PREventQueue *queue;
|
|
|
|
if (GetEventParameter(inEvent, kEventParamPLEventQueue,
|
|
|
|
typeUInt32, NULL, sizeof(PREventQueue*), NULL,
|
|
|
|
&queue) == noErr)
|
|
|
|
{
|
|
|
|
PL_ProcessPendingEvents(queue);
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return eventNotHandledErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pascal Boolean _md_CarbonEventComparator(EventRef inEvent,
|
|
|
|
void *inCompareData)
|
|
|
|
{
|
|
|
|
Boolean match = false;
|
2003-03-25 01:38:53 +00:00
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
if (GetEventClass(inEvent) == kEventClassPL &&
|
|
|
|
GetEventKind(inEvent) == kEventProcessPLEvents)
|
|
|
|
{
|
|
|
|
PREventQueue *queue;
|
|
|
|
match = ((GetEventParameter(inEvent, kEventParamPLEventQueue,
|
|
|
|
typeUInt32, NULL, sizeof(PREventQueue*), NULL,
|
|
|
|
&queue) == noErr) && (queue == inCompareData));
|
|
|
|
}
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* defined(MAC_USE_CARBON_EVENT) */
|
|
|
|
|
|
|
|
#if defined(XP_MAC) || defined(XP_MACOSX)
|
2002-03-27 07:16:12 +00:00
|
|
|
static void _md_CreateEventQueue( PLEventQueue *eventQueue )
|
|
|
|
{
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(MAC_USE_CARBON_EVENT)
|
|
|
|
eventQueue->eventHandlerUPP = NewEventHandlerUPP(_md_EventReceiverProc);
|
|
|
|
PR_ASSERT(eventQueue->eventHandlerUPP);
|
|
|
|
if (eventQueue->eventHandlerUPP)
|
|
|
|
{
|
|
|
|
EventTypeSpec eventType;
|
|
|
|
|
|
|
|
eventType.eventClass = kEventClassPL;
|
2003-03-25 01:38:53 +00:00
|
|
|
eventType.eventKind = kEventProcessPLEvents;
|
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
InstallApplicationEventHandler(eventQueue->eventHandlerUPP, 1, &eventType,
|
|
|
|
eventQueue, &eventQueue->eventHandlerRef);
|
|
|
|
PR_ASSERT(eventQueue->eventHandlerRef);
|
|
|
|
}
|
|
|
|
#elif defined(MAC_USE_WAKEUPPROCESS)
|
2002-03-27 07:16:12 +00:00
|
|
|
OSErr err = GetCurrentProcess(&eventQueue->psn);
|
|
|
|
PR_ASSERT(err == noErr);
|
2002-12-19 15:25:57 +00:00
|
|
|
#endif
|
2002-03-27 07:16:12 +00:00
|
|
|
} /* end _md_CreateEventQueue() */
|
2002-12-19 15:25:57 +00:00
|
|
|
#endif /* defined(XP_MAC) || defined(XP_MACOSX) */
|
2002-03-27 07:16:12 +00:00
|
|
|
|
2001-03-12 23:57:18 +00:00
|
|
|
/* extra functions for unix */
|
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
2001-03-12 23:57:18 +00:00
|
|
|
|
|
|
|
PR_IMPLEMENT(PRInt32)
|
|
|
|
PL_ProcessEventsBeforeID(PLEventQueue *aSelf, unsigned long aID)
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
PRInt32 count = 0;
|
|
|
|
PRInt32 fullCount;
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
if (aSelf == NULL)
|
|
|
|
return -1;
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
PR_EnterMonitor(aSelf->monitor);
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
if (aSelf->processingEvents) {
|
|
|
|
PR_ExitMonitor(aSelf->monitor);
|
|
|
|
return 0;
|
|
|
|
}
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
aSelf->processingEvents = PR_TRUE;
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
/* Only process the events that are already in the queue, and
|
|
|
|
* not any new events that get added. Do this by counting the
|
|
|
|
* number of events currently in the queue
|
|
|
|
*/
|
|
|
|
fullCount = _pl_GetEventCount(aSelf);
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG,
|
|
|
|
("$$$ fullCount is %d id is %ld\n", fullCount, aID));
|
|
|
|
|
|
|
|
if (fullCount == 0) {
|
|
|
|
aSelf->processingEvents = PR_FALSE;
|
|
|
|
PR_ExitMonitor(aSelf->monitor);
|
|
|
|
return 0;
|
2001-03-12 23:57:18 +00:00
|
|
|
}
|
2003-03-25 01:38:53 +00:00
|
|
|
|
|
|
|
PR_ExitMonitor(aSelf->monitor);
|
|
|
|
|
|
|
|
while (fullCount-- > 0) {
|
|
|
|
/* peek at the next event */
|
|
|
|
PLEvent *event;
|
|
|
|
event = PR_EVENT_PTR(aSelf->queue.next);
|
|
|
|
if (event == NULL)
|
|
|
|
break;
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ processing event %ld\n",
|
|
|
|
event->id));
|
|
|
|
if (event->id >= aID) {
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ skipping event and breaking"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
event = PL_GetEvent(aSelf);
|
|
|
|
PL_HandleEvent(event);
|
|
|
|
PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ done processing event"));
|
|
|
|
count++;
|
2001-03-12 23:57:18 +00:00
|
|
|
}
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
PR_EnterMonitor(aSelf->monitor);
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
/* if full count still had items left then there's still items left
|
|
|
|
in the queue. Let the native notify token stay. */
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
if (aSelf->type == EventQueueIsNative) {
|
|
|
|
fullCount = _pl_GetEventCount(aSelf);
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
if (fullCount <= 0) {
|
|
|
|
_pl_AcknowledgeNativeNotify(aSelf);
|
|
|
|
aSelf->notified = PR_FALSE;
|
|
|
|
}
|
2001-03-12 23:57:18 +00:00
|
|
|
}
|
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
aSelf->processingEvents = PR_FALSE;
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2003-03-25 01:38:53 +00:00
|
|
|
PR_ExitMonitor(aSelf->monitor);
|
|
|
|
|
|
|
|
return count;
|
2001-03-12 23:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_RegisterEventIDFunc(PLEventQueue *aSelf, PLGetEventIDFunc aFunc,
|
|
|
|
void *aClosure)
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
aSelf->idFunc = aFunc;
|
|
|
|
aSelf->idFuncClosure = aClosure;
|
2001-03-12 23:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_IMPLEMENT(void)
|
|
|
|
PL_UnregisterEventIDFunc(PLEventQueue *aSelf)
|
|
|
|
{
|
2003-03-25 01:38:53 +00:00
|
|
|
aSelf->idFunc = 0;
|
|
|
|
aSelf->idFuncClosure = 0;
|
2001-03-12 23:57:18 +00:00
|
|
|
}
|
|
|
|
|
2002-12-19 15:25:57 +00:00
|
|
|
#endif /* defined(XP_UNIX) && !defined(XP_MACOSX) */
|
2001-03-12 23:57:18 +00:00
|
|
|
|
2000-01-25 14:48:51 +00:00
|
|
|
/* --- end plevent.c --- */
|