diff options
author | srinivas%netscape.com <devnull@localhost> | 1999-09-20 02:11:10 +0000 |
---|---|---|
committer | srinivas%netscape.com <devnull@localhost> | 1999-09-20 02:11:10 +0000 |
commit | 9e1172dd7b75ed01a7091d475369f857136ae727 (patch) | |
tree | 57b67b2c02f5aa31335a877d35666c2f578c2dd1 | |
parent | 03afcce0db1a5ea343497879ccbca7310d89c759 (diff) | |
download | nspr-hg-9e1172dd7b75ed01a7091d475369f857136ae727.tar.gz |
Limit the number of events processed by PL_ProcessPendingEvents; check in
troy@netscape.com. Bugzilla 13660.
-rw-r--r-- | lib/ds/plevent.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/ds/plevent.c b/lib/ds/plevent.c index e696e8ce..be13b696 100644 --- a/lib/ds/plevent.c +++ b/lib/ds/plevent.c @@ -338,7 +338,9 @@ PL_GetEvent(PLEventQueue* self) return NULL; mon = self->monitor; - PR_EnterMonitor(mon); + if (mon) { + PR_EnterMonitor(mon); + } if ( self->type == EventQueueIsNative ) err = _pl_AcknowledgeNativeNotify(self); @@ -352,7 +354,9 @@ PL_GetEvent(PLEventQueue* self) } done: - PR_ExitMonitor(mon); + if (mon) { + PR_ExitMonitor(mon); + } return event; } @@ -462,6 +466,7 @@ PL_ProcessPendingEvents(PLEventQueue* self) if (PR_FALSE != self->processingEvents) return; self->processingEvents = PR_TRUE; +#if 0 while (PR_TRUE) { PLEvent* event = PL_GetEvent(self); if (event == NULL) break; @@ -470,6 +475,33 @@ PL_ProcessPendingEvents(PLEventQueue* self) PL_HandleEvent(event); PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ done processing event")); } +#else + /* Only process the events that are already in the queue, and + * not any new events that get added. Do this by making a copy of + * the queue + */ + PR_EnterMonitor(self->monitor); + if (PR_CLIST_IS_EMPTY(&self->queue)) { + PR_ExitMonitor(self->monitor); + } else { + struct PLEventQueue tmpQueue; + /* Copy the events to a temporary queue */ + memcpy(&tmpQueue, self, sizeof(tmpQueue)); + tmpQueue.queue.next->prev = &tmpQueue.queue; + tmpQueue.queue.prev->next = &tmpQueue.queue; + tmpQueue.monitor = 0; /* don't waste time locking this queue when getting events */ + PR_INIT_CLIST(&self->queue); + PR_ExitMonitor(self->monitor); + /* Now process the existing events */ + while (PR_TRUE) { + PLEvent* event = PL_GetEvent(&tmpQueue); + if (event == NULL) break; + PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ processing event")); + PL_HandleEvent(event); + PR_LOG(event_lm, PR_LOG_DEBUG, ("$$$ done processing event")); + } + } +#endif self->processingEvents = PR_FALSE; } |