Mercurial > cpython-lru_cache-weakref
diff Mac/Python/macglue.c @ 4197:b70baba1c789 legacy-trunk
- Fixed PyMac_DoYield:
- Update lastyield correctly
- Do event handling if PyMac_YieldEnabled > 0 (previous cmd-. fix
broke this)
- Use our own GUSISpin routine: fixes crash when exiting with sockets
open and keeps windows, etc reacting consistently when waiting for
accepts(), etc.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Wed, 04 Sep 1996 15:24:59 +0000 |
| parents | 53d511c0029f |
| children | 3126f8a146a6 |
line wrap: on
line diff
--- a/Mac/Python/macglue.c Wed Sep 04 15:21:55 1996 +0000 +++ b/Mac/Python/macglue.c Wed Sep 04 15:24:59 1996 +0000 @@ -65,6 +65,7 @@ #ifdef USE_GUSI #include <TFileSpec.h> /* For Path2FSSpec */ #include <LowMem.h> /* For SetSFCurDir, etc */ +#include <GUSI.h> #endif #ifndef HAVE_UNIVERSAL_HEADERS @@ -110,6 +111,8 @@ static int interrupted; /* Set to true when cmd-. seen */ static RETSIGTYPE intcatcher Py_PROTO((int)); +static void PyMac_DoYield Py_PROTO((int)); + /* ** We attempt to be a good citizen by giving up the CPU periodically. ** When in the foreground we do this less often and for shorter periods @@ -135,6 +138,11 @@ int PyMac_DoYieldEnabled = 1; /* +** Workaround for sioux/gusi combo: set when we are exiting +*/ +int PyMac_ConsoleIsDead; + +/* ** Some stuff for our GetDirectory and PromptGetFile routines */ struct hook_args { @@ -171,6 +179,40 @@ void SpinCursor(short x) { /* Dummy */ } #endif /* __CFM68K */ +/* +** Replacement GUSI Spin function +*/ +static int +PyMac_GUSISpin(spin_msg msg, long arg) +{ + static Boolean inForeground = true; + WindowPtr win; + EventRecord ev; + int maysleep; + + if (PyMac_ConsoleIsDead) return 0; +#if 0 + if (inForeground) + SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1); +#endif + + if (interrupted) return -1; + + if ( msg == SP_AUTO_SPIN || ((msg==SP_SLEEP||msg==SP_SELECT) && arg <= yield_fg)) + maysleep = 0; + else + maysleep = 0; + + PyMac_DoYield(maysleep); + + return 0; +} + +void +PyMac_SetGUSISpin() { + GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin); +} + #endif @@ -403,7 +445,7 @@ ** Yield the CPU to other tasks. */ static void -PyMac_DoYield() +PyMac_DoYield(int maysleep) { EventRecord ev; long yield; @@ -415,19 +457,25 @@ NGetTrapAddress(_Unimplemented, ToolTrap)); } - if ( PyMac_DoYieldEnabled >= 0) { + lastyield = TickCount(); #ifndef THINK_C - /* Under think this has been done before in intrcheck() or intrpeek() */ + /* Under think this has been done before in intrcheck() or intrpeek() */ + if (PyMac_DoYieldEnabled >= 0) scan_event_queue(0); #endif + if (PyMac_DoYieldEnabled == 0) return; - } in_foreground = PyMac_InForeground(); - if ( in_foreground ) - yield = yield_fg; - else - yield = yield_bg; + if ( maysleep ) { + if ( in_foreground ) + yield = yield_fg; + else + yield = yield_bg; + } else { + yield = 0; + } + while ( 1 ) { if ( no_waitnextevent ) { SystemTask(); @@ -440,7 +488,6 @@ break; PyMac_HandleEvent(&ev); } - lastyield = TickCount(); } /* @@ -455,9 +502,10 @@ else iv = interval_bg; if ( TickCount() > lastyield + iv ) - PyMac_DoYield(); + PyMac_DoYield(1); } +#ifdef USE_MACTCP /* ** Idle routine for busy-wait loops. ** Gives up CPU, handles events and returns true if an interrupt is pending @@ -466,9 +514,11 @@ int PyMac_Idle() { - PyMac_DoYield(); + PyMac_DoYield(1); return intrpeek(); } +#endif + /* ** Returns true if the argument has a resource fork, and it contains ** a 'PYC ' resource of the correct name
