thread management fixed. 41/16141/11
Cedric Delamarre [Wed, 11 Mar 2015 14:52:36 +0000 (15:52 +0100)]
Change-Id: I23b62b219d61353326b0ba68068da34f09583f39

19 files changed:
scilab/modules/action_binding/src/c/InterpreterManagement.c
scilab/modules/action_binding/src/c/core_Import.def
scilab/modules/ast/includes/types/threadId.hxx
scilab/modules/ast/src/cpp/types/threadId.cpp
scilab/modules/core/includes/InitScilab.h
scilab/modules/core/includes/runner.hxx
scilab/modules/core/includes/storeCommand.h
scilab/modules/core/includes/tasks.hxx
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/src/cpp/runner.cpp
scilab/modules/core/src/cpp/storeCommand.cpp
scilab/modules/core/src/cpp/tasks.cpp
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp
scilab/modules/functions/sci_gateway/cpp/sci_execstr.cpp
scilab/modules/gui/src/c/ScilabTermination.c
scilab/modules/gui/src/c/core_Import.def
scilab/modules/scicos/src/c/scicos.c
scilab/modules/tclsci/core_Import.def
scilab/modules/tclsci/src/c/ScilabEval.c

index c8e3b38..90c5347 100644 (file)
@@ -30,7 +30,7 @@ int putCommandInScilabQueue(char *command)
 */
 int requestScilabExec(char *command)
 {
-    return StorePrioritaryCommandWithFlag(command, 0);
+    return StorePrioritaryCommand(command);
 }
 /*--------------------------------------------------------------------------*/
 int interruptScilab(void)
index 2eaac29..4fe337a 100644 (file)
@@ -6,7 +6,7 @@ EXPORTS
 callFunctionFromGateway
 com_
 StoreCommand
-StorePrioritaryCommandWithFlag
+StorePrioritaryCommand
 freeArrayOfString
 MyHeapAlloc
 MyHeapFree
index 8edd66a..81c15ec 100644 (file)
@@ -75,6 +75,9 @@ public :
     void                    setInterruptible(bool _isInterruptible);
     bool                    isInterruptible();
 
+    void                    setConsoleCommandFlag(bool _isConsoleCommand);
+    bool                    isConsoleCommand();
+
 private :
     std::wstring            StatusToString(Status _status);
 
@@ -96,6 +99,7 @@ private :
     Status                  m_threadStatus;
     bool                    m_doInterrupt;
     bool                    m_isInterruptible;
+    bool                    m_isConsoleCommand;
 };
 }
 #endif /* !__THREADID_HH__ */
index 3b66767..8b3f29a 100644 (file)
@@ -38,6 +38,7 @@ ThreadId::ThreadId(__threadId _id, __threadKey _key)
     m_threadStatus = Running;
     m_isInterruptible = true;
     m_doInterrupt = false;
+    m_isConsoleCommand = false;
 }
 
 __threadId ThreadId::getThreadId()
@@ -166,5 +167,14 @@ bool ThreadId::isInterruptible()
     return m_isInterruptible;
 }
 
+void ThreadId::setConsoleCommandFlag(bool _isConsoleCommand)
+{
+    m_isConsoleCommand = _isConsoleCommand;
 }
 
+bool ThreadId::isConsoleCommand()
+{
+    return m_isConsoleCommand;
+}
+
+}
index 1b0b89b..cc668ac 100644 (file)
@@ -38,6 +38,8 @@ typedef struct
     void* pExpTree;
     int iMultiLine;
     int isInterruptible;
+    int isPrioritary;
+    int isConsoleCommand;
 } ScilabEngineInfo;
 
 ScilabEngineInfo* InitScilabEngineInfo();
index 6fb4138..2171685 100644 (file)
@@ -47,7 +47,8 @@ public :
 
     static void init();
 
-    static void execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor, bool _isPriorityThread);
+    static void execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor,
+                            bool _isInterruptible, bool _isPrioritary, bool _isConsoleCommand);
 
     void exec(ast::Exp* _theProgram, ast::ExecVisitor *_visitor);
 
@@ -81,6 +82,11 @@ public :
         return &m_AstPending;
     }
 
+    static __threadSignal* getConsoleExecDone(void)
+    {
+        return &m_consoleExecDone;
+    }
+
     void setThreadKey(__threadKey _threadId)
     {
         m_threadKey = _threadId;
@@ -100,6 +106,7 @@ private :
     ast::ExecVisitor*   m_visitor;
 
 private :
+    static __threadSignal m_consoleExecDone;
     static __threadSignal m_awakeScilab;
     static __threadSignalLock m_awakeScilabLock;
     static __threadLock m_lock;
index a944079..b88a802 100644 (file)
 #include <wchar.h>
 #include "machine.h"
 
-/*
- * Checks if there's something on the
- * commandQueue
- * @return
+/**
+ * Store a non-prioritary and interruptible command
+ *
+ * @param command : the command
+ * @return <ReturnValue>
  */
-int ismenu(void);
+int StoreCommand(char *command);
 
 /**
- * try to execute a command or add it to the end of command queue
+ * Store a prioritary and interruptible command
  *
- * @param command the command
+ * @param command : the command
  * @return <ReturnValue>
  */
-int StoreCommand (char *command);
 
+int StoreConsoleCommand(char *command);
 /**
- * try to execute a command or add it to the end of command queue
+ * Store a prioritary and non-interruptible command
  *
- * @param command the command
- * @param flag a internal execution flag for sequential execution
+ * @param command : the command
  * @return <ReturnValue>
  */
-int StoreConsoleCommandWithFlag (char *command, int flag);
-int StoreCommandWithFlag (char *command, int flag);
+int StorePrioritaryCommand(char *command);
 
 /**
- * @TODO add comment
+ * Get the next command to execute
  *
- * @param str
- * @return <ReturnValue>
+ * @param command           : command wich will be executed
+ * @param piInterruptible   : 1 if it is a interruptible command
+ * @param piPrioritary      : 1 if it is a prioritary command
+ * @param piConsole         : 1 if it is a console command
+ * @return <ReturnValue>    : 0 if command queue is empty
  */
-int GetCommand (char** str, int* piConsoleCmd);
+int GetCommand (char** command, int* piInterruptible, int* piPrioritary, int* piConsole);
 
 /**
-* try to execute a command or add it to the _BEGINNING_ of command queue
+* check if command queue is empty
+* @return 1 if empty , 0 is not empty
 */
-int StorePrioritaryCommandWithFlag (char *command, int flag);
+int isEmptyCommandQueue(void);
+
+
+
+/*
+ * Checks if there's something on the
+ * commandQueue
+ * @return
+ */
+int ismenu(void);
+
 
 /**
 *
 */
 int C2F(getmen)(char * btn_cmd, int * lb, int * entry);
 
-/**
-* check if command queue is empty
-* @return 1 if empty , 0 is not empty
-*/
-int isEmptyCommandQueue(void);
 
 #endif /* __STORECOMMAND_H__ */
index 9c96637..519a5ba 100644 (file)
@@ -48,7 +48,8 @@ void printAstTask(ast::Exp *tree, bool timed);
 **
 ** Execute the stored AST.
 */
-void execAstTask(ast::Exp *tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose, bool _isPrioritaryThread);
+void execAstTask(ast::Exp *tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose,
+                 bool _isInterruptibleThread, bool _isPrioritaryThread, bool _isConsoleCommand);
 
 /*
 ** Exec Tree with original visitor ( without template )
index 5bea4d3..8f2fa87 100644 (file)
@@ -95,6 +95,7 @@ extern "C"
     extern BOOL isItTheDisabledLib(void);
 }
 
+__threadLock m_StartLock;
 __threadLock m_ParseLock;
 __threadSignal ExecDone;
 __threadSignalLock *pExecDoneLock;
@@ -135,7 +136,8 @@ ScilabEngineInfo* InitScilabEngineInfo()
     pSEI->iNoBanner = 1;
 
     pSEI->iMultiLine = 0;
-    pSEI->isInterruptible = 1; // by default al thread are interruptible
+    pSEI->isInterruptible = 1;  // by default all thread are interruptible
+    pSEI->isPrioritary = 0;     // by default all thread are non-prioritary
 
     return pSEI;
 }
@@ -293,8 +295,7 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
             }
             else
             {
-                _pSEI->pExpTree = parser.getTree();
-                processCommand(_pSEI);
+                StoreConsoleCommand(_pSEI->pstExec);
             }
 
             iMainRet = ConfigVariable::getExitStatus();
@@ -306,12 +307,7 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
             char *pstCommand = (char *)MALLOC(sizeof(char) * (strlen("exec(\"\",-1)") + strlen(_pSEI->pstFile) + 1));
             sprintf(pstCommand, "exec(\"%s\",-1)", _pSEI->pstFile);
 
-            _pSEI->pstExec = pstCommand;
-            parseCommandTask(&parser, _pSEI->iTimed != 0, _pSEI->pstExec);
-            FREE(pstCommand);
-
-            _pSEI->pExpTree = parser.getTree();
-            processCommand(_pSEI);
+            StoreConsoleCommand(pstCommand);
 
             iMainRet = ConfigVariable::getExitStatus();
             _pSEI->pstExec = NULL;
@@ -345,7 +341,11 @@ int ExecExternalCommand(ScilabEngineInfo* _pSEI)
 {
     if (_pSEI->pstExec)
     {
-        processCommand(_pSEI);
+        StoreConsoleCommand(_pSEI->pstExec);
+        __LockSignal(pExecDoneLock);
+        __Wait(Runner::getConsoleExecDone(), pExecDoneLock);
+        __UnLockSignal(pExecDoneLock);
+
         return ConfigVariable::getExitStatus();
     }
 
@@ -475,11 +475,10 @@ static void processCommand(ScilabEngineInfo* _pSEI)
      */
     if (_pSEI->iExecAst)
     {
-        //before calling YaspReader, try to call %onprompt function
-        callOnPrompt();
         execAstTask((ast::Exp*)_pSEI->pExpTree, _pSEI->iSerialize != 0,
                     _pSEI->iTimed != 0, _pSEI->iAstTimed != 0,
-                    _pSEI->iExecVerbose != 0, _pSEI->isInterruptible == 0);
+                    _pSEI->iExecVerbose != 0, _pSEI->isInterruptible != 0,
+                    _pSEI->isPrioritary != 0, _pSEI->isConsoleCommand != 0);
     }
 
     /*
@@ -494,23 +493,31 @@ static void processCommand(ScilabEngineInfo* _pSEI)
 // Thread used to parse and execute Scilab command setted in storeCommand
 void* scilabReadAndExecCommand(void* param)
 {
-    int iconsoleCmd = 0;
-    char* command = NULL;
+
+    int iInterruptibleCmd   = 0;
+    int iPrioritaryCmd      = 0;
+    int iConsoleCmd         = 0;
+    char* command           = NULL;
+
     ScilabEngineInfo* _pSEI = (ScilabEngineInfo*)param;
 
-    while (!ConfigVariable::getForceQuit())
+    while (ConfigVariable::getForceQuit() == false)
     {
-        if (isEmptyCommandQueue())
+        if (GetCommand(&command, &iInterruptibleCmd, &iPrioritaryCmd, &iConsoleCmd) == 0)
         {
+            // command queue is empty
             __LockSignal(pLaunchScilabLock);
             __Wait(&LaunchScilab, pLaunchScilabLock);
             __UnLockSignal(pLaunchScilabLock);
+
+            continue;
         }
 
-        _pSEI->isInterruptible = GetCommand(&command, &iconsoleCmd);
+        _pSEI->isInterruptible = iInterruptibleCmd;
+        _pSEI->isPrioritary = iPrioritaryCmd;
+        _pSEI->isConsoleCommand = iConsoleCmd;
 
         __Lock(&m_ParseLock);
-
         Parser parser;
         parser.setParseTrace(_pSEI->iParseTrace != 0);
         parseCommandTask(&parser, _pSEI->iTimed != 0, command);
@@ -526,13 +533,7 @@ void* scilabReadAndExecCommand(void* param)
         __UnLock(&m_ParseLock);
 
         processCommand(_pSEI);
-
         FREE(command);
-
-        if (iconsoleCmd)
-        {
-            __Signal(&ExecDone);
-        }
     }
 
     return NULL;
@@ -541,6 +542,9 @@ void* scilabReadAndExecCommand(void* param)
 //Thread used to parse and set console commands in storeCommand
 void* scilabReadAndStore(void* param)
 {
+    __Lock(&m_StartLock);
+    __UnLock(&m_StartLock);
+
     Parser::ControlStatus controlStatus = Parser::AllControlClosed;
 
     char *command = NULL;
@@ -553,16 +557,35 @@ void* scilabReadAndStore(void* param)
         command = _pSEI->pstExec;
     }
 
-    while (!ConfigVariable::getForceQuit())
+    if (isEmptyCommandQueue() == false)
+    {
+        // unlock scilabReadAndExecCommand thread
+        __LockSignal(pExecDoneLock);
+        __Signal(&ExecDone);
+        __UnLockSignal(pExecDoneLock);
+
+        // Command stored as console command by -f
+        // We have to wait this execution before
+        // callOnPrompt (ie: onPrompt perform a quit in test_run)
+        __LockSignal(pExecDoneLock);
+        __Wait(Runner::getConsoleExecDone(), pExecDoneLock);
+        __UnLockSignal(pExecDoneLock);
+    }
+
+    // unlock scilabReadAndExecCommand thread
+    __LockSignal(pExecDoneLock);
+    __Signal(&ExecDone);
+    __UnLockSignal(pExecDoneLock);
+
+    callOnPrompt();
+
+    while (ConfigVariable::getForceQuit() == false)
     {
         Parser parser;
         parser.setParseTrace(_pSEI->iParseTrace != 0);
 
         Parser::ParserStatus exitStatus = Parser::Failed;
 
-        //before calling reader, try to call %onprompt function
-        callOnPrompt();
-
         if (ConfigVariable::isEmptyLineShow())
         {
             scilabWriteW(L"\n");
@@ -611,6 +634,10 @@ void* scilabReadAndStore(void* param)
             controlStatus = parser.getControlStatus();
             exitStatus = parser.getExitStatus();
             parserErrorMsg = parser.getErrorMessage();
+            if (parser.getTree())
+            {
+                delete (parser.getTree());
+            }
             __UnLock(&m_ParseLock);
         }
         while (controlStatus != Parser::AllControlClosed);
@@ -628,16 +655,19 @@ void* scilabReadAndStore(void* param)
             continue;
         }
 
-        StoreConsoleCommandWithFlag(command, 1);
+        StoreConsoleCommand(command);
 
         FREE(command);
         command = NULL;
 
         __LockSignal(pExecDoneLock);
-        __Wait(&ExecDone, pExecDoneLock);
+        __Wait(Runner::getConsoleExecDone(), pExecDoneLock);
         __UnLockSignal(pExecDoneLock);
+
+        callOnPrompt();
     }
 
+    __Signal(&LaunchScilab);
     return NULL;
 }
 
@@ -704,13 +734,24 @@ static int interactiveMain(ScilabEngineInfo* _pSEI)
     __threadId threadIdCommand;
     __threadKey threadKeyCommand;
 
+    __InitLock(&m_StartLock);
     __InitLock(&m_ParseLock);
+
     InitializeScilabSignal(&LaunchScilab, &pLaunchScilabLock, ReleaseLaunchScilabSignal);
     InitializeScilabSignal(&ExecDone, &pExecDoneLock, ReleaseDoneScilabSignal);
 
+    __Lock(&m_StartLock);
     // thread to manage console command
     __CreateThreadWithParams(&threadIdConsole, &threadKeyConsole, &scilabReadAndStore, _pSEI);
 
+    // scilabReadAndStore thread must be execute before scilabReadAndExecCommand
+    // to be such that the -f command stored is not removed
+    // from queue before scilabReadAndStore is waiting for.
+    __LockSignal(pExecDoneLock);
+    __UnLock(&m_StartLock);
+    __Wait(&ExecDone, pExecDoneLock);
+    __UnLockSignal(pExecDoneLock);
+
     // thread to manage command stored
     __CreateThreadWithParams(&threadIdCommand, &threadKeyCommand, &scilabReadAndExecCommand, _pSEI);
 
index f17511c..de94254 100644 (file)
@@ -14,6 +14,8 @@
 
 __threadLock Runner::m_lock;
 
+__threadSignal Runner::m_consoleExecDone;
+
 __threadSignal Runner::m_awakeScilab;
 __threadSignalLock Runner::m_awakeScilabLock;
 
@@ -28,12 +30,19 @@ __threadSignal* getAstPendingSignal(void)
     return Runner::getAstPendingSignal();
 }
 
+__threadSignal* getConsoleExecDone(void)
+{
+    return Runner::getConsoleExecDone();
+}
+
 
 void Runner::init()
 {
     __InitSignal(&m_awakeScilab);
     __InitSignalLock(&m_awakeScilabLock);
 
+    __InitSignal(&m_consoleExecDone);
+
     __InitSignal(&m_AstPending);
     __InitSignalLock(&m_AstPendingLock);
 }
@@ -46,6 +55,9 @@ void *Runner::launch(void *args)
     //just release locker
     __UnLock(&m_lock);
 
+    __threadKey currentThreadKey = __GetCurrentThreadKey();
+    ThreadId* pThread = ConfigVariable::getThread(currentThreadKey);
+
     //exec !
     Runner *me = (Runner *)args;
 
@@ -62,25 +74,28 @@ void *Runner::launch(void *args)
     // reset error state when new prompt occurs
     ConfigVariable::resetError();
 
-    __threadKey currentThreadKey = __GetCurrentThreadKey();
-
     //change thread status
-    ThreadId* pThread = ConfigVariable::getThread(currentThreadKey);
     if (pThread->getStatus() != ThreadId::Aborted)
     {
         pThread->setStatus(ThreadId::Done);
         bdoUnlock = true;
     }
 
-    if (pThread->isInterruptible()) // non-prioritary
+    if (pThread->getInterrupt()) // non-prioritary
     {
         // Unlock prioritary thread waiting for
         // non-prioritary thread end this "SeqExp" execution.
         // This case appear when error is throw or when
         // non-prioritary execute this last SeqExp.
+        pThread->setInterrupt(false);
         __Signal(&Runner::m_AstPending);
     }
 
+    if (pThread->isConsoleCommand())
+    {
+        __Signal(&Runner::m_consoleExecDone);
+    }
+
     //unregister thread
     ConfigVariable::deleteThread(currentThreadKey);
 
@@ -111,7 +126,8 @@ void Runner::UnlockPrompt()
 }
 
 
-void Runner::execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor, bool _isPrioritaryThread)
+void Runner::execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor,
+                         bool _isPrioritaryThread, bool _isInterruptibleThread, bool _isConsoleCommand)
 {
     try
     {
@@ -132,7 +148,6 @@ void Runner::execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor, bool
                 if (pInterruptibleThread->isInterruptible())
                 {
                     pInterruptibleThread->setInterrupt(true);
-
                     __LockSignal(&m_AstPendingLock);
                     __Wait(&m_AstPending, &m_AstPendingLock);
                     __UnLockSignal(&m_AstPendingLock);
@@ -158,15 +173,13 @@ void Runner::execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor, bool
         //register thread
         types::ThreadId* pThread = new ThreadId(threadId, threadKey);
         ConfigVariable::addThread(pThread);
-        if (_isPrioritaryThread)
-        {
-            pThread->setInterruptible(false);
-        }
+        pThread->setConsoleCommandFlag(_isConsoleCommand);
+        pThread->setInterruptible(_isInterruptibleThread);
 
         //free locker to release thread && wait and of thread execution
         LockPrompt();
 
-        if (pInterruptibleThread)
+        if (pInterruptibleThread && pInterruptibleThread->getInterrupt())
         {
             pInterruptibleThread->setInterrupt(false);
             pInterruptibleThread->resume();
index 831ef7c..f9799c3 100644 (file)
@@ -43,6 +43,8 @@ using namespace ast;
  *  This function is used to store Scilab command in a queue
  *
  *  PUBLIC : int StoreCommand( char *command)
+ *           int StoreConsoleCommand(char *command)
+ *           int StorePrioritaryCommand(char *command)
  *           int C2F(ismenu)()
  *           int C2F(getmen)(char * btn_cmd,int * lb, int * entry)
  */
@@ -51,8 +53,9 @@ struct CommandRec
 {
     char*   m_command;              /* command info one string two integers */
     int     m_isInterruptible;      /* 1 if the command execution can be interrupted */
-    int     m_consoleCmd;           /* 1 if the command come from console */
-    CommandRec(char* command, int isInterruptible, int consoleCmd) : m_command(command), m_isInterruptible(isInterruptible), m_consoleCmd(consoleCmd) {}
+    int     m_isPrioritary;         /* 1 if the command is prioritary */
+    int     m_isConsole;            /* 1 if the command come from console */
+    CommandRec(char* command, int isInterruptible, int isPrioritary, int isConsole) : m_command(command), m_isInterruptible(isInterruptible), m_isPrioritary(isPrioritary), m_isConsole(isConsole) {}
 };
 /*--------------------------------------------------------------------------*/
 /* Extern Signal to say we git a StoreCommand. */
@@ -89,83 +92,86 @@ static void release(void)
     }
 }
 /*--------------------------------------------------------------------------*/
-int StoreCommand (char *command)
-{
-    return StoreCommandWithFlag (command, 1);
-}
-
-/*--------------------------------------------------------------------------*/
-/*
- * try to execute a command or add it to the end of command queue
- */
-int StoreCommandWithFlag (char *command, int isInterruptible)
+int StoreCommand(char *command)
 {
     __Lock(getCommandQueueSingleAccess());
-    commandQueue.emplace_back(os_strdup(command), isInterruptible, 0);
+    commandQueue.emplace_back(os_strdup(command),
+                              /*is prioritary*/ 0,
+                              /* is interruptible*/ 1,
+                              /* from console */ 0);
     __UnLock(getCommandQueueSingleAccess());
     __Signal(&LaunchScilab);
 
     return 0;
 }
-/*--------------------------------------------------------------------------*/
-/*
- * try to execute a command or add it to the _BEGINNING_ of command queue
- */
-int StoreConsoleCommandWithFlag (char *command, int isInterruptible)
+
+int StoreConsoleCommand(char *command)
 {
     __Lock(getCommandQueueSingleAccess());
-    commandQueuePrioritary.emplace_back(os_strdup(command), isInterruptible, 1);
+    commandQueuePrioritary.emplace_back(os_strdup(command),
+                                        /*is prioritary*/ 1,
+                                        /* is interruptible*/ 1,
+                                        /* from console */ 1);
     __UnLock(getCommandQueueSingleAccess());
     __Signal(&LaunchScilab);
     Runner::UnlockPrompt();
     return 0;
 }
 
-int StorePrioritaryCommandWithFlag (char *command, int isInterruptible)
+int StorePrioritaryCommand(char *command)
 {
     __Lock(getCommandQueueSingleAccess());
-    commandQueuePrioritary.emplace_back(os_strdup(command), isInterruptible, 0);
+    commandQueuePrioritary.emplace_back(os_strdup(command),
+                                        /*is prioritary*/ 1,
+                                        /* is interruptible*/ 0,
+                                        /* from console */ 0);
     __UnLock(getCommandQueueSingleAccess());
     __Signal(&LaunchScilab);
     Runner::UnlockPrompt();
     return 0;
 }
-/*--------------------------------------------------------------------------*/
+
 int isEmptyCommandQueue(void)
 {
     return (commandQueuePrioritary.empty() && commandQueue.empty());
 }
-/*--------------------------------------------------------------------------*/
+
 /*
- * Gets info on the first queue element
+ * Gets the next command to execute
  * and remove it from the queue
  */
-int GetCommand (char** cmd, int* piConsoleCmd)
+int GetCommand (char** cmd, int* piInterruptible, int* piPrioritary, int* piConsole)
 {
-    int isInterruptible = 0;
-    __Lock(getCommandQueueSingleAccess());
+    int iCommandReturned = 0;
 
+    __Lock(getCommandQueueSingleAccess());
     if (commandQueuePrioritary.empty() == false)
     {
         *cmd = os_strdup(commandQueuePrioritary.front().m_command);
-        isInterruptible = commandQueuePrioritary.front().m_isInterruptible;
-        *piConsoleCmd = commandQueuePrioritary.front().m_consoleCmd;
+        *piInterruptible = commandQueuePrioritary.front().m_isInterruptible;
+        *piPrioritary = commandQueuePrioritary.front().m_isPrioritary;
+        *piConsole = commandQueuePrioritary.front().m_isConsole;
 
         FREE (commandQueuePrioritary.front().m_command);
         commandQueuePrioritary.pop_front();
+
+        iCommandReturned = 1;
     }
     else if (commandQueue.empty() == false)
     {
         *cmd = os_strdup(commandQueue.front().m_command);
-        isInterruptible = commandQueue.front().m_isInterruptible;
-        *piConsoleCmd = commandQueue.front().m_consoleCmd;
+        *piInterruptible = commandQueue.front().m_isInterruptible;
+        *piPrioritary = commandQueue.front().m_isPrioritary;
+        *piConsole = commandQueue.front().m_isConsole;
 
         FREE (commandQueue.front().m_command);
         commandQueue.pop_front();
+
+        iCommandReturned = 1;
     }
     __UnLock(getCommandQueueSingleAccess());
 
-    return isInterruptible;
+    return iCommandReturned;
 }
 /*--------------------------------------------------------------------------*/
 int ismenu(void)
index 8ceabf5..91f7063 100644 (file)
@@ -134,7 +134,8 @@ void printAstTask(ast::Exp *tree, bool timed)
 **
 ** Execute the stored AST.
 */
-void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose, bool isPriorityThread)
+void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose,
+                 bool isInterruptibleThread, bool isPrioritaryThread, bool isConsoleCommand)
 {
     if (tree == NULL)
     {
@@ -188,7 +189,7 @@ void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool
         exec = new ast::ExecVisitor();
     }
 
-    Runner::execAndWait(newTree, exec, isPriorityThread);
+    Runner::execAndWait(newTree, exec, isInterruptibleThread, isPrioritaryThread, isConsoleCommand);
     //DO NOT DELETE tree or newTree, they was deleted by Runner or previously;
 
     if (timed)
@@ -236,7 +237,7 @@ void execScilabStartTask(bool _bSerialize)
         return;
     }
 
-    execAstTask(parse.getTree(), _bSerialize, false, false, false, true);
+    execAstTask(parse.getTree(), _bSerialize, false, false, false, true, true, false);
 }
 
 /*
@@ -258,7 +259,7 @@ void execScilabQuitTask(bool _bSerialize)
         return;
     }
 
-    execAstTask(parse.getTree(), _bSerialize, false, false, false, true);
+    execAstTask(parse.getTree(), _bSerialize, false, false, false, true, true, false);
 }
 
 
index f5a6bb7..621dcf2 100644 (file)
@@ -24,6 +24,7 @@
 #include "scilabexception.hxx"
 #include "configvariable.hxx"
 #include "types_tools.hxx"
+#include "runner.hxx"
 
 #include <iostream>
 #include <fstream>
@@ -287,10 +288,18 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
 
     ConfigVariable::setPromptMode(promptMode);
 
+    types::ThreadId* pThreadMe = ConfigVariable::getThread(__GetCurrentThreadKey());
+
     for (ast::exps_t::iterator j = LExp.begin(), itEnd = LExp.end() ; j != itEnd ; ++j)
     {
         try
         {
+            if (pThreadMe && pThreadMe->getInterrupt())
+            {
+                __Signal(getAstPendingSignal());
+                pThreadMe->suspend();
+            }
+
             ast::exps_t::iterator k = j;
             //mode == 0, print new variable but not command
             if (file && ConfigVariable::getPromptMode() != 0 && ConfigVariable::getPromptMode() != 2)
index 0f197b7..8c5b324 100644 (file)
@@ -23,6 +23,7 @@
 #include "scilabexception.hxx"
 #include "configvariable.hxx"
 #include "context.hxx"
+#include "runner.hxx"
 
 #include <iostream>
 #include <fstream>
@@ -204,10 +205,18 @@ Function::ReturnValue sci_execstr(types::typed_list &in, int _iRetCount, types::
 
     ast::exps_t LExp = pExp->getAs<SeqExp>()->getExps();
 
+    types::ThreadId* pThreadMe = ConfigVariable::getThread(__GetCurrentThreadKey());
+
     for (ast::exps_t::iterator j = LExp.begin(), itEnd = LExp.end(); j != itEnd ; ++j)
     {
         try
         {
+            if (pThreadMe && pThreadMe->getInterrupt())
+            {
+                __Signal(getAstPendingSignal());
+                pThreadMe->suspend();
+            }
+
             //excecute script
             ExecVisitor execMe;
             (*j)->accept(execMe);
index 3a901ab..b3ed102 100644 (file)
@@ -14,5 +14,5 @@
 /*--------------------------------------------------------------------------*/
 void ScilabExit(void)
 {
-    StorePrioritaryCommandWithFlag("exit(0)", 0);
+    StorePrioritaryCommand("exit(0)");
 }
index 38916d4..993d9c7 100644 (file)
@@ -4,7 +4,7 @@ LIBRARY    core.dll
 EXPORTS
 ;
 StoreCommand
-StorePrioritaryCommandWithFlag
+StorePrioritaryCommand
 freeArrayOfString
 MyHeapAlloc
 MyHeapFree
index ca9774b..4d00c9c 100644 (file)
@@ -1769,7 +1769,7 @@ static void cossim(double *told)
         {
             int ierr2 = 0;
             int iUnused;
-            SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
+            GetCommand(&CommandToUnstack, &SeqSync, &iUnused, &iUnused); //** get to the action
             CommandLength = (int)strlen(CommandToUnstack);
             //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
             FREE(CommandToUnstack);
@@ -2954,7 +2954,7 @@ static void cossimdaskr(double *told)
         {
             int ierr2 = 0;
             int iUnused;
-            SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
+            GetCommand(&CommandToUnstack, &SeqSync, &iUnused, &iUnused); //** get to the action
             CommandLength = (int)strlen(CommandToUnstack);
             //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
             FREE(CommandToUnstack);
@@ -3142,7 +3142,7 @@ L30:
                         {
                             int ierr2 = 0;
                             int iUnused;
-                            SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
+                            GetCommand(&CommandToUnstack, &SeqSync, &iUnused, &iUnused); //** get to the action
                             CommandLength = (int)strlen(CommandToUnstack);
                             //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
                             FREE(CommandToUnstack);
@@ -3494,7 +3494,7 @@ L30:
                 {
                     int ierr2 = 0;
                     int iUnused;
-                    SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
+                    GetCommand(&CommandToUnstack, &SeqSync, &iUnused, &iUnused); //** get to the action
                     CommandLength = (int)strlen(CommandToUnstack);
                     //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
                     FREE(CommandToUnstack);
@@ -7163,7 +7163,7 @@ static int CallKinsol(double *told)
             {
                 int ierr2 = 0;
                 int iUnused;
-                SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
+                GetCommand(&CommandToUnstack, &SeqSync, &iUnused, &iUnused); //** get to the action
                 CommandLength = (int)strlen(CommandToUnstack);
                 //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
                 FREE(CommandToUnstack);
index 5aed47f..3c3d349 100644 (file)
@@ -2,17 +2,16 @@ LIBRARY    core.dll
 
 
 EXPORTS
-callFunctionFromGateway 
+callFunctionFromGateway
 com_
 intersci_
 stack_
 vstk_
 iop_
 StoreCommand
-StoreCommandWithFlag
-GetCommand 
+GetCommand
 ismenu
-StorePrioritaryCommandWithFlag
+StorePrioritaryCommand
 freeArrayOfString
 MyHeapAlloc
 MyHeapFree
index a313ba3..e6ddef1 100644 (file)
@@ -91,7 +91,7 @@ int TCL_EvalScilabCmd(ClientData clientData, Tcl_Interp * theinterp, int objc, C
             So far as Tcl has it's own thread now mixing global values
             and threads within parse makes Scilab crash often.
             */
-            StorePrioritaryCommandWithFlag(pwstCommand, seq);
+            //            StorePrioritaryCommandWithFlag(pwstCommand, seq);
             ierr = 0;
 
             if (C2F(iop).ddt == -1)
@@ -156,7 +156,7 @@ int TCL_EvalScilabCmd(ClientData clientData, Tcl_Interp * theinterp, int objc, C
                 and threads within parse makes Scilab crash often.
                 */
                 pwstComm = to_wide_string(comm[nc]);
-                StorePrioritaryCommandWithFlag(pwstComm, seqf[nc]);
+                //                StorePrioritaryCommandWithFlag(pwstComm, seqf[nc]);
                 FREE(pwstComm);
                 if (C2F(iop).ddt == -1)
                 {
@@ -182,12 +182,12 @@ int TCL_EvalScilabCmd(ClientData clientData, Tcl_Interp * theinterp, int objc, C
             if ( (argv[2] != (char *)0) && (strncmp(argv[2], "seq", 3) == 0) )
             {
                 /* seq */
-                StoreCommandWithFlag(pwstCommand, 1);
+                //                StoreCommandWithFlag(pwstCommand, 1);
             }
             else
             {
                 /* no option or unknown option (TODO: no error for this latter case?) */
-                StoreCommand(pwstCommand);
+                //                StoreCommand(pwstCommand);
                 Tcl_SetResult(theinterp, NULL, NULL);
             }
         }