More interrupt handling cleanups!

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@104 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-06-27 13:22:30 +00:00
parent 362bf807a4
commit efd998524f
7 changed files with 89 additions and 46 deletions

View File

@ -1977,7 +1977,7 @@ absmi(int inp)
* *cannot* fail before having woken up all suspended goals. * *cannot* fail before having woken up all suspended goals.
*/ */
/* make sure we are here because of an awoken goal */ /* make sure we are here because of an awoken goal */
if (CFREG == Unsigned(LCL0) && !(PrologMode & AbortMode)) { if (CFREG == Unsigned(LCL0) && !(PrologMode & (InterruptMode|AbortMode))) {
Term WGs; Term WGs;
Term my_goal; Term my_goal;
@ -2051,11 +2051,17 @@ absmi(int inp)
} }
else { else {
#endif #endif
if (PrologMode & AbortMode) { if (PrologMode & (AbortMode|InterruptMode)) {
PrologMode &= ~AbortMode;
CFREG = CalculateStackGap(); CFREG = CalculateStackGap();
/* same instruction */ /* same instruction */
if (ProcessSIGINT() < 0) Abort(""); if (PrologMode & InterruptMode) {
PrologMode &= ~InterruptMode;
ProcessSIGINT();
}
if (PrologMode & AbortMode) {
PrologMode &= ~AbortMode;
Abort("");
}
JMPNext(); JMPNext();
} }
#if SHADOW_S #if SHADOW_S

View File

@ -211,6 +211,7 @@ Abort (char *format,...)
va_list ap; va_list ap;
va_start (ap, format); va_start (ap, format);
PrologMode &= ~AbortMode;
if (format) if (format)
{ {
char ch; char ch;

View File

@ -138,7 +138,8 @@ char FileNameBuf[YAP_FILENAME_MAX], FileNameBuf2[YAP_FILENAME_MAX];
/********* Prolog State ********************************************/ /********* Prolog State ********************************************/
int PrologMode = BootMode; prolog_exec_mode PrologMode = BootMode;
int CritLocks = 0;
#if PUSH_REGS #if PUSH_REGS
REGSTORE standard_regs; REGSTORE standard_regs;

View File

@ -1196,26 +1196,23 @@ ConsoleGetc(int sno)
strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT); strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT);
newline = FALSE; newline = FALSE;
} }
in_getc = TRUE;
#if HAVE_SIGINTERRUPT #if HAVE_SIGINTERRUPT
siginterrupt(SIGINT, TRUE); siginterrupt(SIGINT, TRUE);
#endif #endif
in_getc = TRUE;
ch = YP_fgetc(s->u.file.file); ch = YP_fgetc(s->u.file.file);
in_getc = FALSE;
#if HAVE_SIGINTERRUPT #if HAVE_SIGINTERRUPT
siginterrupt(SIGINT, FALSE); siginterrupt(SIGINT, FALSE);
#endif #endif
in_getc = FALSE; if (PrologMode & InterruptMode) {
if (PrologMode & AbortMode) { PrologMode &= ~InterruptMode;
PrologMode &= ~AbortMode; ProcessSIGINT();
CreepFlag = CalculateStackGap();
if (ProcessSIGINT() < 0) Abort("");
newline = TRUE;
goto restart;
} else if (ch == -1 && errno == EINTR) {
errno = 0;
PrologMode &= ~AbortMode;
if (ProcessSIGINT() < 0) Abort("");
newline = TRUE; newline = TRUE;
if (PrologMode & AbortMode) {
PrologMode &= ~AbortMode;
Abort("");
}
goto restart; goto restart;
} }
return(console_post_process_read_char(ch, s, sno)); return(console_post_process_read_char(ch, s, sno));

View File

@ -1076,7 +1076,7 @@ InteractSIGINT(char ch) {
/* we can't do a direct abort, so ask the system to do /* we can't do a direct abort, so ask the system to do
it for us */ it for us */
p_creep(); p_creep();
PutValue(AtomThrow, MkAtomTerm(AtomTrue)); PrologMode |= AbortMode;
return(-1); return(-1);
case 'c': case 'c':
/* continue */ /* continue */
@ -1177,16 +1177,6 @@ ProcessSIGINT(void)
{ {
int ch, out; int ch, out;
#if HAVE_ISATTY
if (!isatty(0)) {
InteractSIGINT('e');
}
#if !HAVE_LIBREADLINE
if (in_getc) {
return(0);
}
#endif
#endif
do { do {
#if HAVE_LIBREADLINE #if HAVE_LIBREADLINE
if (_line != (char *) NULL && _line != (char *) EOF) if (_line != (char *) NULL && _line != (char *) EOF)
@ -1227,10 +1217,22 @@ HandleSIGINT (int sig)
#endif #endif
{ {
my_signal(SIGINT, HandleSIGINT); my_signal(SIGINT, HandleSIGINT);
#if (_MSC_VER || defined(__MINGW32__)) #if HAVE_ISATTY
printf("hello\n"); if (!isatty(0)) {
return; InteractSIGINT('e');
}
#endif #endif
#if !HAVE_LIBREADLINE
if (in_getc) {
PrologMode |= InterruptMode;
return;
}
#endif
if (PrologMode & CritMode) {
/* delay processing if we are messing with the Code space */
PrologMode |= InterruptMode;
return;
}
#ifdef HAVE_SETBUF #ifdef HAVE_SETBUF
/* make sure we are not waiting for the end of line */ /* make sure we are not waiting for the end of line */
YP_setbuf (stdin, NULL); YP_setbuf (stdin, NULL);
@ -1301,7 +1303,7 @@ MSCHandleSignal(DWORD dwCtrlType) {
case CTRL_C_EVENT: case CTRL_C_EVENT:
case CTRL_BREAK_EVENT: case CTRL_BREAK_EVENT:
p_creep(); p_creep();
PrologMode |= AbortMode; PrologMode |= InterruptMode;
return(TRUE); return(TRUE);
default: default:
return(FALSE); return(FALSE);

View File

@ -16,6 +16,11 @@
<h2>Yap-4.3.19:</h2> <h2>Yap-4.3.19:</h2>
<ul> <ul>
<li>FIXED: make ^c-a work within gc.</li>
<li>FIXED: handle correctly very deep nested terms while gc
marking.</li>
<li>FIXED: ArityOfFunctor was giving trouble with HP-UX cc
(Stasinos Konstantinos).</li>
<li>FIXED: ^c works with Yap/MINGW32 (not in cygwin).</li> <li>FIXED: ^c works with Yap/MINGW32 (not in cygwin).</li>
<li>FIXED: ^c a should never core dump.</li> <li>FIXED: ^c a should never core dump.</li>
<li>FIXED: comparison of variables in sub-terms.</li> <li>FIXED: comparison of variables in sub-terms.</li>

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 * * File: Yap.h.m4 *
* mods: * * mods: *
* comments: main header file for YAP * * comments: main header file for YAP *
* version: $Id: Yap.h.m4,v 1.5 2001-06-22 17:53:36 vsc Exp $ * * version: $Id: Yap.h.m4,v 1.6 2001-06-27 13:22:30 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#include "config.h" #include "config.h"
@ -754,14 +754,16 @@ extern int CurFileNo;
/********* Prolog may be in several modes *******************************/ /********* Prolog may be in several modes *******************************/
#define BootMode 1 /* if booting or restoring */ typedef enum {
#define UserMode 2 /* Normal mode */ BootMode = 1, /* if booting or restoring */
#define CritMode 4 /* If we are meddling with the heap */ UserMode = 2, /* Normal mode */
#define FullLMode 8 /* to access the hidden atoms chain */ CritMode = 4, /* If we are meddling with the heap */
#define AbortMode 16 /* expecting to abort */ AbortMode = 8, /* expecting to abort */
#define InterruptMode 32 /* under an interrupt */ InterruptMode = 16 /* under an interrupt */
} prolog_exec_mode;
extern int PrologMode; extern prolog_exec_mode PrologMode;
extern int CritLocks;
#if SIZEOF_INT_P==4 #if SIZEOF_INT_P==4
#if defined(YAPOR) || defined(TABLING) #if defined(YAPOR) || defined(TABLING)
@ -802,17 +804,46 @@ extern int yap_argc;
GLOBAL_LOCKS_who_locked_heap = worker_id; \ GLOBAL_LOCKS_who_locked_heap = worker_id; \
} \ } \
PrologMode |= CritMode; \ PrologMode |= CritMode; \
CritLocks++; \
} }
#define YAPLeaveCriticalSection() \ #define YAPLeaveCriticalSection() \
{ \ { \
if ((PrologMode ^= CritMode) & AbortMode) Abort((char *)NIL); \ CritLocks--; \
GLOBAL_LOCKS_who_locked_heap = MAX_WORKERS; \ if (!CritLocks) { \
UNLOCK(GLOBAL_LOCKS_heap_access); \ PrologMode &= ~CritMode; \
if (PrologMode & InterruptMode) { \
PrologMode &= ~InterruptMode; \
ProcessSIGINT(); \
} \
if (PrologMode & AbortMode) { \
PrologMode &= ~AbortMode; \
Abort(""); \
} \
GLOBAL_LOCKS_who_locked_heap = MAX_WORKERS; \
UNLOCK(GLOBAL_LOCKS_heap_access); \
} \
} }
#else #else
#define YAPEnterCriticalSection() PrologMode |= CritMode; #define YAPEnterCriticalSection() \
#define YAPLeaveCriticalSection() \ { \
if((PrologMode ^= CritMode) & AbortMode) Abort((char *)NIL); PrologMode |= CritMode; \
CritLocks++; \
}
#define YAPLeaveCriticalSection() \
{ \
CritLocks--; \
if (!CritLocks) { \
PrologMode &= ~CritMode; \
if (PrologMode & InterruptMode) { \
PrologMode &= ~InterruptMode; \
ProcessSIGINT(); \
} \
if (PrologMode & AbortMode) { \
PrologMode &= ~AbortMode; \
Abort(""); \
} \
} \
}
#endif /* YAPOR */ #endif /* YAPOR */
/* when we are calling the InitStaff procedures */ /* when we are calling the InitStaff procedures */