summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfraser%netscape.com <devnull@localhost>2002-07-30 00:28:38 +0000
committersfraser%netscape.com <devnull@localhost>2002-07-30 00:28:38 +0000
commitd6593b0e119d474cc1ba1991fe3f6c53c11cb10d (patch)
treeedd466d646588837af4aa922de374a63d0bd20c8
parent54a4974b42d720e6fa8b6e3f890c151cd7399722 (diff)
downloadnspr-hg-d6593b0e119d474cc1ba1991fe3f6c53c11cb10d.tar.gz
Fix for 158927 on the 1.0 branch. r=wtc, sdagley. a=adt.
-rw-r--r--pr/include/md/_macos.h32
-rw-r--r--pr/src/md/mac/macthr.c27
2 files changed, 43 insertions, 16 deletions
diff --git a/pr/include/md/_macos.h b/pr/include/md/_macos.h
index d2c25d1d..4b301377 100644
--- a/pr/include/md/_macos.h
+++ b/pr/include/md/_macos.h
@@ -65,6 +65,7 @@
#include <Errors.h>
#include <OpenTransport.h>
+#include <DriverServices.h>
#define _PR_HAVE_PEEK_BUFFER
#define _PR_PEEK_BUFFER_MAX (16 * 1024)
@@ -105,7 +106,9 @@ struct _MDSegment {
};
struct _MDCPU {
- PRInt8 notused;
+ AbsoluteTime lastThreadSwitch;
+ AbsoluteTime lastWakeUpProcess;
+ PRBool trackScheduling;
};
typedef struct _MDSocketCallerInfo {
@@ -175,7 +178,7 @@ extern void _MD_SetIntsOff(PRInt32 ints);
#define _MD_CLEANUP_BEFORE_EXIT()
#define _MD_EXIT(status) exit(status)
#define _MD_INIT_CPUS()
-#define _MD_INIT_RUNNING_CPU(cpu)
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_InitRunningCPU(cpu)
/*
** Process Related definitions
@@ -299,16 +302,20 @@ extern PRStatus _MD_InitThread(PRThread *thread);
** context switch because it might have changed.
*/
/* ResetTimer(); before _PR_Schedule() */
-#define _MD_SWITCH_CONTEXT(_thread) \
- PR_BEGIN_MACRO \
- PR_ASSERT(_thread->no_sched); \
- if (!setjmp(_thread->md.jb)) { \
- _MD_SET_LAST_THREAD(_thread); \
- _PR_Schedule(); \
- } else { \
- PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
- _MD_LAST_THREAD()->no_sched = 0; \
- } \
+
+
+#define _MD_SWITCH_CONTEXT(_thread) \
+ PR_BEGIN_MACRO \
+ PR_ASSERT(_thread->no_sched); \
+ if (!setjmp(_thread->md.jb)) { \
+ _MD_SET_LAST_THREAD(_thread); \
+ if (_PR_MD_CURRENT_CPU()->md.trackScheduling) \
+ _PR_MD_CURRENT_CPU()->md.lastThreadSwitch = UpTime(); \
+ _PR_Schedule(); \
+ } else { \
+ PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
+ _MD_LAST_THREAD()->no_sched = 0; \
+ } \
PR_END_MACRO
/*
@@ -517,7 +524,6 @@ extern PRStatus _MD_gethostname(char *name, int namelen);
** Time Related definitions
*/
-#define kMacTimerInMiliSecs 8L
#define _MD_GET_INTERVAL _MD_GetInterval
#define _MD_INTERVAL_PER_SEC() PR_MSEC_PER_SEC
#define _MD_INTERVAL_INIT()
diff --git a/pr/src/md/mac/macthr.c b/pr/src/md/mac/macthr.c
index 6a1f18d4..fd3b489d 100644
--- a/pr/src/md/mac/macthr.c
+++ b/pr/src/md/mac/macthr.c
@@ -39,7 +39,7 @@
#include <MacTypes.h>
#include <Timer.h>
#include <OSUtils.h>
-
+#include <Math64.h>
#include <LowMem.h>
#include <Multiprocessing.h>
#include <Gestalt.h>
@@ -184,6 +184,8 @@ _PRInterruptTable _pr_interruptTable[] = {
{ 0 }
};
+#define kMacTimerInMiliSecs 8L
+
pascal void TimerCallback(TMTaskPtr tmTaskPtr)
{
_PRCPU *cpu = _PR_MD_CURRENT_CPU();
@@ -201,8 +203,17 @@ pascal void TimerCallback(TMTaskPtr tmTaskPtr)
_PR_ClockInterrupt();
if ((_PR_RUNQREADYMASK(cpu)) >> ((_PR_MD_CURRENT_THREAD()->priority))) {
- if (gTimeManagerTaskDoesWUP)
- WakeUpProcess(&gApplicationProcess);
+ if (gTimeManagerTaskDoesWUP) {
+ // We only want to call WakeUpProcess if we know that NSPR has managed to switch threads
+ // since the last call, otherwise we end up spewing out WakeUpProcess() calls while the
+ // application is blocking somewhere. This can interfere with events loops other than
+ // our own (see bug 158927).
+ if (UnsignedWideToUInt64(cpu->md.lastThreadSwitch) > UnsignedWideToUInt64(cpu->md.lastWakeUpProcess))
+ {
+ WakeUpProcess(&gApplicationProcess);
+ cpu->md.lastWakeUpProcess = UpTime();
+ }
+ }
_PR_SET_RESCHED_FLAG();
}
@@ -263,6 +274,16 @@ void _MD_PauseCPU(PRIntervalTime timeout)
}
}
+void _MD_InitRunningCPU(_PRCPU* cpu)
+{
+ cpu->md.trackScheduling = RunningOnOSX();
+ if (cpu->md.trackScheduling) {
+ AbsoluteTime zeroTime = {0, 0};
+ cpu->md.lastThreadSwitch = UpTime();
+ cpu->md.lastWakeUpProcess = zeroTime;
+ }
+}
+
//##############################################################################
//##############################################################################