Threads execution managemement. 09/16109/6
Cedric Delamarre [Fri, 6 Mar 2015 13:13:21 +0000 (14:13 +0100)]
Change-Id: Ib804f5421a89a51bf660d6a8aea24ffb7d21b65c

32 files changed:
scilab/modules/action_binding/src/c/InterpreterManagement.c
scilab/modules/action_binding/src/c/core_Import.def
scilab/modules/ast/core_Import.def
scilab/modules/ast/includes/parse/parser.hxx
scilab/modules/ast/includes/types/threadId.hxx
scilab/modules/ast/src/cpp/ast/runvisitor.cpp
scilab/modules/ast/src/cpp/parse/parser.cpp
scilab/modules/ast/src/cpp/types/threadId.cpp
scilab/modules/ast/threads_Import.def
scilab/modules/call_scilab/core_Import.def
scilab/modules/call_scilab/src/c/call_scilab.c
scilab/modules/core/Makefile.am
scilab/modules/core/Makefile.in
scilab/modules/core/includes/InitScilab.h
scilab/modules/core/includes/LaunchScilabSignal.h [deleted file]
scilab/modules/core/includes/runner.hxx
scilab/modules/core/includes/storeCommand.h
scilab/modules/core/includes/tasks.hxx
scilab/modules/core/src/c/LaunchScilabSignal.c [deleted file]
scilab/modules/core/src/c/core.vcxproj
scilab/modules/core/src/c/core.vcxproj.filters
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/gui/src/c/ScilabTermination.c
scilab/modules/gui/src/c/core_Import.def
scilab/modules/gui/src/java/org/scilab/modules/gui/events/callback/ScilabCloseCallBack.java
scilab/modules/scicos/src/c/scicos.c
scilab/modules/tclsci/src/c/ScilabEval.c
scilab/modules/windows_tools/src/c/scilab_windows/core_Import.def
scilab/modules/windows_tools/src/c/scilab_windows/scilab_main.c

index 609f6d2..c8e3b38 100644 (file)
 /*--------------------------------------------------------------------------*/
 int putCommandInScilabQueue(char *command)
 {
-    wchar_t* pstCommand = to_wide_string(command);
-    int iRet = StoreCommand(pstCommand);
-    FREE(pstCommand);
-    return iRet;
+    return StoreCommand(command);
 }
 /*--------------------------------------------------------------------------*/
 /*
@@ -33,10 +30,7 @@ int putCommandInScilabQueue(char *command)
 */
 int requestScilabExec(char *command)
 {
-    wchar_t* pstCommand = to_wide_string(command);
-    int iRet = StoreCommandWithFlag(pstCommand, 1);
-    FREE(pstCommand);
-    return iRet;
+    return StorePrioritaryCommandWithFlag(command, 0);
 }
 /*--------------------------------------------------------------------------*/
 int interruptScilab(void)
index c60cee3..2eaac29 100644 (file)
@@ -6,7 +6,7 @@ EXPORTS
 callFunctionFromGateway
 com_
 StoreCommand
-StoreCommandWithFlag
+StorePrioritaryCommandWithFlag
 freeArrayOfString
 MyHeapAlloc
 MyHeapFree
index 0cae9bb..916e131 100644 (file)
@@ -3,4 +3,5 @@ LIBRARY    core.dll
 
 EXPORTS
 MyHeapFree
-MyHeapAlloc
\ No newline at end of file
+MyHeapAlloc
+getAstPendingSignal
\ No newline at end of file
index a7811f8..97be86c 100644 (file)
@@ -81,6 +81,7 @@ public:
     void parseFile(const std::wstring& name, const std::wstring& progName);
 
     /** \brief parse the given file command */
+    void parse(char *command);
     void parse(wchar_t *command);
 
     /** \brief enable Bison trace mode */
index c726b36..8edd66a 100644 (file)
@@ -68,6 +68,13 @@ public :
     void                    suspend();
     void                    resume();
     void                    abort();
+
+    void                    setInterrupt(bool _doInterrupt);
+    bool                    getInterrupt();
+
+    void                    setInterruptible(bool _isInterruptible);
+    bool                    isInterruptible();
+
 private :
     std::wstring            StatusToString(Status _status);
 
@@ -87,7 +94,8 @@ private :
     __threadKey             m_threadKey;
     __threadLock            m_threadLock;
     Status                  m_threadStatus;
-
+    bool                    m_doInterrupt;
+    bool                    m_isInterruptible;
 };
 }
 #endif /* !__THREADID_HH__ */
index 955ad79..dbb812a 100644 (file)
 #include "macrofile.hxx"
 #include "macro.hxx"
 
+#include "runner.hxx"
+
 extern "C"
 {
 #include "sciprint.h"
 #include "os_string.h"
 #include "elem_common.h"
+
+#include "Thread_Wrapper.h"
 }
 
 namespace ast
@@ -762,8 +766,16 @@ void RunVisitorT<T>::visitprivate(const SeqExp  &e)
     exps_t::const_iterator itExp;
     exps_t exps = e.getExps();
 
+    types::ThreadId* pThreadMe = ConfigVariable::getThread(__GetCurrentThreadKey());
+
     for (itExp = exps.begin (); itExp != exps.end (); ++itExp)
     {
+        if (pThreadMe && pThreadMe->getInterrupt())
+        {
+            __Signal(getAstPendingSignal());
+            pThreadMe->suspend();
+        }
+
         if (e.isBreakable())
         {
             (*itExp)->resetBreak();
index 1ace2e3..ddde74a 100644 (file)
@@ -106,7 +106,7 @@ void ParserSingleInstance::parseFile(const std::wstring& fileName, const std::ws
     fclose(yyin);
 }
 
-void Parser::parse(wchar_t *command)
+void Parser::parse(char *command)
 {
     // Calling Parse state machine in C with global values
     // Must be locked to avoid concurrent access
@@ -120,8 +120,7 @@ void Parser::parse(wchar_t *command)
         ParserSingleInstance::disableParseTrace();
     }
 
-    char* pstCommand = wide_string_to_UTF8(command);
-    ParserSingleInstance::parse(pstCommand);
+    ParserSingleInstance::parse(command);
     this->setExitStatus(ParserSingleInstance::getExitStatus());
     this->setControlStatus(ParserSingleInstance::getControlStatus());
     if (getExitStatus() == Parser::Succeded)
@@ -139,10 +138,16 @@ void Parser::parse(wchar_t *command)
         scan_throw(YYEOF);
     }
 
-    FREE(pstCommand);
     // FIXME : UNLOCK
 }
 
+void Parser::parse(wchar_t *command)
+{
+    char* pstCommand = wide_string_to_UTF8(command);
+    parse(pstCommand);
+    FREE(pstCommand);
+}
+
 /** \brief parse the given file command */
 void ParserSingleInstance::parse(char *command)
 {
index b1f57ba..3b66767 100644 (file)
@@ -36,6 +36,8 @@ ThreadId::ThreadId(__threadId _id, __threadKey _key)
     m_threadKey = _key;
     __InitLock(&m_threadLock);
     m_threadStatus = Running;
+    m_isInterruptible = true;
+    m_doInterrupt = false;
 }
 
 __threadId ThreadId::getThreadId()
@@ -143,5 +145,26 @@ bool ThreadId::toString(std::wostringstream& ostr)
     ostr << L"Status : " << StatusToString(this->getStatus());
     return true;
 }
+
+void ThreadId::setInterrupt(bool _doInterrupt)
+{
+    m_doInterrupt = _doInterrupt;
+}
+
+bool ThreadId::getInterrupt()
+{
+    return m_doInterrupt;
+}
+
+void ThreadId::setInterruptible(bool _isInterruptible)
+{
+    m_isInterruptible = _isInterruptible;
+}
+
+bool ThreadId::isInterruptible()
+{
+    return m_isInterruptible;
+}
+
 }
 
index ad682f0..84a7738 100644 (file)
@@ -6,3 +6,4 @@ __InitLock
 __SuspendThread
 __ResumeThread
 __GetCurrentThreadKey
+__Signal
index 1e4ecca..9aeaf25 100644 (file)
@@ -4,7 +4,6 @@ LIBRARY    core.dll
 EXPORTS
 scirun_
 settmpdir_
-InitializeLaunchScilabSignal
 ReleaseLaunchScilabSignal
 TerminateCorePart2
 ExitScilab
index ba39f8e..eaac6cc 100644 (file)
@@ -20,7 +20,6 @@
 #include "sci_malloc.h"
 #include "configvariable_interface.h"
 #include "fromc.h"
-#include "LaunchScilabSignal.h"
 #include "isdir.h"
 #include "sci_path.h"
 #include "scilabDefaults.h"
@@ -165,7 +164,6 @@ BOOL TerminateScilab(char *ScilabQuit)
         pSEI->pstFile = ScilabQuit;
         StopScilabEngine(pSEI);
 
-        ReleaseLaunchScilabSignal();
         setCallScilabEngineState(CALL_SCILAB_ENGINE_STOP);
 
         /* restore default mode */
index 72465f9..146eaf9 100644 (file)
@@ -38,7 +38,6 @@ CORE_C_SOURCES = \
     src/c/dynamic_gateways.c \
     src/c/comparehandles.c \
     src/c/setPrecisionFPU.c \
-    src/c/LaunchScilabSignal.c \
     src/c/getos.c \
     src/c/mode_exec.c \
     src/c/transposeMatrix.c \
index e9c22d3..d17a3f0 100644 (file)
@@ -205,7 +205,6 @@ am__objects_1 = src/c/libscicore_algo_la-csignal.lo \
        src/c/libscicore_algo_la-dynamic_gateways.lo \
        src/c/libscicore_algo_la-comparehandles.lo \
        src/c/libscicore_algo_la-setPrecisionFPU.lo \
-       src/c/libscicore_algo_la-LaunchScilabSignal.lo \
        src/c/libscicore_algo_la-getos.lo \
        src/c/libscicore_algo_la-mode_exec.lo \
        src/c/libscicore_algo_la-transposeMatrix.lo \
@@ -738,7 +737,6 @@ CORE_C_SOURCES = \
     src/c/dynamic_gateways.c \
     src/c/comparehandles.c \
     src/c/setPrecisionFPU.c \
-    src/c/LaunchScilabSignal.c \
     src/c/getos.c \
     src/c/mode_exec.c \
     src/c/transposeMatrix.c \
@@ -1199,8 +1197,6 @@ src/c/libscicore_algo_la-comparehandles.lo: src/c/$(am__dirstamp) \
        src/c/$(DEPDIR)/$(am__dirstamp)
 src/c/libscicore_algo_la-setPrecisionFPU.lo: src/c/$(am__dirstamp) \
        src/c/$(DEPDIR)/$(am__dirstamp)
-src/c/libscicore_algo_la-LaunchScilabSignal.lo: src/c/$(am__dirstamp) \
-       src/c/$(DEPDIR)/$(am__dirstamp)
 src/c/libscicore_algo_la-getos.lo: src/c/$(am__dirstamp) \
        src/c/$(DEPDIR)/$(am__dirstamp)
 src/c/libscicore_algo_la-mode_exec.lo: src/c/$(am__dirstamp) \
@@ -1599,7 +1595,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscicore_algo_la-GetXmlFileEncoding.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscicore_algo_la-InitializeCore.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscicore_algo_la-InitializePreferences.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscicore_algo_la-LaunchScilabSignal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscicore_algo_la-backtrace.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscicore_algo_la-callFunctionFromGateway.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/c/$(DEPDIR)/libscicore_algo_la-commandwords.Plo@am__quote@
@@ -1888,13 +1883,6 @@ src/c/libscicore_algo_la-setPrecisionFPU.lo: src/c/setPrecisionFPU.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/c/libscicore_algo_la-setPrecisionFPU.lo `test -f 'src/c/setPrecisionFPU.c' || echo '$(srcdir)/'`src/c/setPrecisionFPU.c
 
-src/c/libscicore_algo_la-LaunchScilabSignal.lo: src/c/LaunchScilabSignal.c
-@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/c/libscicore_algo_la-LaunchScilabSignal.lo -MD -MP -MF src/c/$(DEPDIR)/libscicore_algo_la-LaunchScilabSignal.Tpo -c -o src/c/libscicore_algo_la-LaunchScilabSignal.lo `test -f 'src/c/LaunchScilabSignal.c' || echo '$(srcdir)/'`src/c/LaunchScilabSignal.c
-@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) src/c/$(DEPDIR)/libscicore_algo_la-LaunchScilabSignal.Tpo src/c/$(DEPDIR)/libscicore_algo_la-LaunchScilabSignal.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='src/c/LaunchScilabSignal.c' object='src/c/libscicore_algo_la-LaunchScilabSignal.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/c/libscicore_algo_la-LaunchScilabSignal.lo `test -f 'src/c/LaunchScilabSignal.c' || echo '$(srcdir)/'`src/c/LaunchScilabSignal.c
-
 src/c/libscicore_algo_la-getos.lo: src/c/getos.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscicore_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/c/libscicore_algo_la-getos.lo -MD -MP -MF src/c/$(DEPDIR)/libscicore_algo_la-getos.Tpo -c -o src/c/libscicore_algo_la-getos.lo `test -f 'src/c/getos.c' || echo '$(srcdir)/'`src/c/getos.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) src/c/$(DEPDIR)/libscicore_algo_la-getos.Tpo src/c/$(DEPDIR)/libscicore_algo_la-getos.Plo
index 5215cf8..1b0b89b 100644 (file)
@@ -35,6 +35,9 @@ typedef struct
     int iSerialize;
     int iKeepConsole;
     int iNoBanner;
+    void* pExpTree;
+    int iMultiLine;
+    int isInterruptible;
 } ScilabEngineInfo;
 
 ScilabEngineInfo* InitScilabEngineInfo();
diff --git a/scilab/modules/core/includes/LaunchScilabSignal.h b/scilab/modules/core/includes/LaunchScilabSignal.h
deleted file mode 100644 (file)
index bdc7a01..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) DIGITEO - 2010 - Allan CORNET
-*
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution.  The terms
-* are also available at
-* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
-*
-*/
-
-/*--------------------------------------------------------------------------*/
-#ifndef __LAUNCHSCILABSIGNAL_H__
-#define __LAUNCHSCILABSIGNAL_H__
-
-/**
-* Initialize signals Scilab Launched
-*/
-void InitializeLaunchScilabSignal(void);
-
-
-/**
-* Release signals Scilab Launched
-*/
-void ReleaseLaunchScilabSignal(void);
-
-#endif /* __LAUNCHSCILABSIGNAL_H__ */
-/*--------------------------------------------------------------------------*/
index ca16f25..6fb4138 100644 (file)
@@ -21,10 +21,13 @@ extern "C"
 {
 #include "Thread_Wrapper.h"
 #include "dynlib_core.h"
+
+    __threadSignal* getAstPendingSignal();
 }
 
 #include "threadId.hxx"
 
+
 class CORE_IMPEXP Runner
 {
 private :
@@ -33,6 +36,7 @@ private :
         m_theProgram = _theProgram;
         m_visitor = _visitor;
     }
+
     ~Runner()
     {
         delete m_theProgram;
@@ -43,7 +47,7 @@ public :
 
     static void init();
 
-    static void execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor);
+    static void execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor, bool _isPriorityThread);
 
     void exec(ast::Exp* _theProgram, ast::ExecVisitor *_visitor);
 
@@ -72,6 +76,11 @@ public :
         return m_threadKey;
     }
 
+    static __threadSignal* getAstPendingSignal(void)
+    {
+        return &m_AstPending;
+    }
+
     void setThreadKey(__threadKey _threadId)
     {
         m_threadKey = _threadId;
@@ -94,5 +103,8 @@ private :
     static __threadSignal m_awakeScilab;
     static __threadSignalLock m_awakeScilabLock;
     static __threadLock m_lock;
+    static __threadLock m_PrioritaryLock;
+    static __threadSignal m_AstPending;
+    static __threadSignalLock m_AstPendingLock;
 };
 #endif /* !__RUNNER_HXX__ */
index cb45a5f..a944079 100644 (file)
@@ -30,7 +30,7 @@ int ismenu(void);
  * @param command the command
  * @return <ReturnValue>
  */
-int StoreCommand (wchar_t *command);
+int StoreCommand (char *command);
 
 /**
  * try to execute a command or add it to the end of command queue
@@ -39,7 +39,8 @@ int StoreCommand (wchar_t *command);
  * @param flag a internal execution flag for sequential execution
  * @return <ReturnValue>
  */
-int StoreCommandWithFlag (wchar_t *command, int flag);
+int StoreConsoleCommandWithFlag (char *command, int flag);
+int StoreCommandWithFlag (char *command, int flag);
 
 /**
  * @TODO add comment
@@ -47,14 +48,12 @@ int StoreCommandWithFlag (wchar_t *command, int flag);
  * @param str
  * @return <ReturnValue>
  */
-int GetCommand (char *str);
+int GetCommand (char** str, int* piConsoleCmd);
 
 /**
 * try to execute a command or add it to the _BEGINNING_ of command queue
-* flag = 0 : the command is not shown in scilab window
-* flag = 1 : the command is shown in scilab window (if at prompt) and executed sequentially
 */
-int StorePrioritaryCommandWithFlag (wchar_t *command, int flag);
+int StorePrioritaryCommandWithFlag (char *command, int flag);
 
 /**
 *
index 64e8d4f..9c96637 100644 (file)
@@ -27,7 +27,7 @@ void parseFileTask(Parser *parser, bool timed, const wchar_t* file_name, const w
 **
 ** Parse the given command and create the AST.
 */
-void parseCommandTask(Parser *parser, bool timed, wchar_t *command);
+void parseCommandTask(Parser *parser, bool timed, char *command);
 
 /*
 ** Dump AST
@@ -48,7 +48,7 @@ void printAstTask(ast::Exp *tree, bool timed);
 **
 ** Execute the stored AST.
 */
-void execAstTask(ast::Exp *tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose);
+void execAstTask(ast::Exp *tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose, bool _isPrioritaryThread);
 
 /*
 ** Exec Tree with original visitor ( without template )
diff --git a/scilab/modules/core/src/c/LaunchScilabSignal.c b/scilab/modules/core/src/c/LaunchScilabSignal.c
deleted file mode 100644 (file)
index 5a0974d..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) DIGITEO - 2010 - Allan CORNET
-*
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution.  The terms
-* are also available at
-* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
-*
-*/
-
-/*--------------------------------------------------------------------------*/
-#include <string.h>
-#include <stdlib.h>
-#include "LaunchScilabSignal.h"
-#include "Thread_Wrapper.h"
-/*--------------------------------------------------------------------------*/
-#ifdef _MSC_VER
-__declspec(dllexport) __threadSignal           LaunchScilab = __StaticInitThreadSignal;
-__declspec(dllexport) __threadSignalLock       *pLaunchScilabLock = NULL;
-
-#include "mmapWindows.h"
-#else
-#include <sys/mman.h>
-#ifndef MAP_ANONYMOUS
-# define MAP_ANONYMOUS MAP_ANON
-#endif
-__threadSignal         LaunchScilab = __StaticInitThreadSignal;
-__threadSignalLock     *pLaunchScilabLock = NULL;
-#endif
-/*--------------------------------------------------------------------------*/
-void ReleaseLaunchScilabSignal(void)
-{
-#ifdef _MSC_VER
-    /* http://msdn.microsoft.com/en-us/magazine/cc164040.aspx */
-    if ((pLaunchScilabLock) && (pLaunchScilabLock->LockCount == -1))
-#else
-    if (pLaunchScilabLock)
-#endif
-    {
-        __UnLockSignal(pLaunchScilabLock);
-        munmap(pLaunchScilabLock, sizeof(__threadSignalLock));
-        pLaunchScilabLock = NULL;
-#ifdef _MSC_VER
-        /* On Windows , we need to force value */
-        LaunchScilab = __StaticInitThreadSignal;
-#endif
-    }
-}
-/*--------------------------------------------------------------------------*/
-void InitializeLaunchScilabSignal(void)
-{
-    if (pLaunchScilabLock == NULL)
-    {
-        pLaunchScilabLock = mmap(0, sizeof(__threadSignalLock), PROT_READ | PROT_WRITE, MAP_SHARED |  MAP_ANONYMOUS, -1, 0);
-        __InitSignal(&LaunchScilab);
-        __InitSignalLock(pLaunchScilabLock);
-        atexit(ReleaseLaunchScilabSignal);
-    }
-}
-/*--------------------------------------------------------------------------*/
index 0262af2..f5e8708 100644 (file)
@@ -291,7 +291,6 @@ cd ..
     <ClCompile Include="InitializePreferences.c" />
     <ClCompile Include="isanan.c" />
     <ClCompile Include="islittleendian.c" />
-    <ClCompile Include="LaunchScilabSignal.c" />
     <ClCompile Include="loadversion.c" />
     <ClCompile Include="md5.c" />
     <ClCompile Include="mode_exec.c" />
@@ -369,7 +368,6 @@ cd ..
     <ClInclude Include="..\..\includes\InitScilab.h" />
     <ClInclude Include="..\..\includes\isanan.h" />
     <ClInclude Include="..\..\includes\islittleendian.h" />
-    <ClInclude Include="..\..\includes\LaunchScilabSignal.h" />
     <ClInclude Include="..\..\includes\loadversion.h" />
     <ClInclude Include="..\..\includes\machine.h" />
     <ClInclude Include="..\..\includes\sci_malloc.h" />
index 888da47..40481d5 100644 (file)
     <ClCompile Include="islittleendian.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="LaunchScilabSignal.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="loadversion.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClInclude Include="..\..\includes\islittleendian.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="..\..\includes\LaunchScilabSignal.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="..\..\includes\loadversion.h">
       <Filter>Header Files</Filter>
     </ClInclude>
index 116f6ed..2087b01 100644 (file)
@@ -35,7 +35,6 @@ extern "C"
 #include "machine.h"
 #include "InitializeLocalization.h"
 #include "elem_common.h"
-#include "LaunchScilabSignal.h"
 #include "InitializeJVM.h"
 #include "TerminateJVM.h"
 #include "InitializeGUI.h"
@@ -76,10 +75,30 @@ extern "C"
 #include "setPrecisionFPU.h"
 #endif
 
+#include "storeCommand.h"
+
+#ifdef _MSC_VER
+    __declspec(dllexport) __threadSignal        LaunchScilab = __StaticInitThreadSignal;
+    __declspec(dllexport) __threadSignalLock    *pLaunchScilabLock = NULL;
+
+#include "mmapWindows.h"
+#else
+#include <sys/mman.h>
+#ifndef MAP_ANONYMOUS
+# define MAP_ANONYMOUS MAP_ANON
+#endif
+    __threadSignal      LaunchScilab        = __StaticInitThreadSignal;
+    __threadSignalLock  *pLaunchScilabLock  = NULL;
+#endif
+
     /* Defined without include to avoid useless header dependency */
     extern BOOL isItTheDisabledLib(void);
 }
 
+__threadLock m_ParseLock;
+__threadSignal ExecDone;
+__threadSignalLock *pExecDoneLock;
+
 static void Add_i(void);
 static void Add_pi(void);
 static void Add_eps(void);
@@ -101,7 +120,7 @@ static void checkForLinkerErrors(void);
 static int batchMain(ScilabEngineInfo* _pSEI);
 static int InitializeEnvironnement(void);
 static int interactiveMain(ScilabEngineInfo* _pSEI);
-static Parser::ControlStatus processCommand(ScilabEngineInfo* _pSEI);
+static void processCommand(ScilabEngineInfo* _pSEI);
 static void stateShow(Parser::ControlStatus status);
 
 using namespace ast;
@@ -115,6 +134,9 @@ ScilabEngineInfo* InitScilabEngineInfo()
     pSEI->iExecAst = 1;
     pSEI->iNoBanner = 1;
 
+    pSEI->iMultiLine = 0;
+    pSEI->isInterruptible = 1; // by default al thread are interruptible
+
     return pSEI;
 }
 
@@ -186,8 +208,6 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
     createInnosetupMutex();
 #endif
 
-    InitializeLaunchScilabSignal();
-
     /* Scilab Startup */
     xmlInitParser();
     InitializeEnvironnement();
@@ -260,19 +280,39 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
         if (_pSEI->pstExec)
         {
             //-e option
+            Parser parser;
+            parseCommandTask(&parser, _pSEI->iTimed != 0, _pSEI->pstExec);
+
+            if (parser.getExitStatus() == Parser::Failed)
+            {
+                scilabWriteW(parser.getErrorMessage());
+            }
+            else if (parser.getControlStatus() !=  Parser::AllControlClosed)
+            {
+                _pSEI->iMultiLine = 1;
+            }
+            else
+            {
+                _pSEI->pExpTree = parser.getTree();
+                processCommand(_pSEI);
+            }
 
-            processCommand(_pSEI);
             iMainRet = ConfigVariable::getExitStatus();
         }
         else if (_pSEI->pstFile)
         {
             //-f option execute exec('%s',-1)
+            Parser parser;
             char *pstCommand = (char *)MALLOC(sizeof(char) * (strlen("exec(\"\",-1)") + strlen(_pSEI->pstFile) + 1));
             sprintf(pstCommand, "exec(\"%s\",-1)", _pSEI->pstFile);
 
             _pSEI->pstExec = pstCommand;
-            processCommand(_pSEI);
+            parseCommandTask(&parser, _pSEI->iTimed != 0, _pSEI->pstExec);
             FREE(pstCommand);
+
+            _pSEI->pExpTree = parser.getTree();
+            processCommand(_pSEI);
+
             iMainRet = ConfigVariable::getExitStatus();
             _pSEI->pstExec = NULL;
             _pSEI->pstFile = NULL;
@@ -412,81 +452,233 @@ void StopScilabEngine(ScilabEngineInfo* _pSEI)
     ConfigVariable::setEndProcessing(false);
 }
 
-static Parser::ControlStatus processCommand(ScilabEngineInfo* _pSEI)
+static void processCommand(ScilabEngineInfo* _pSEI)
 {
-    Parser *parser = new Parser();
+    /*
+     ** -*- DUMPING TREE -*-
+     */
+    if (_pSEI->iDumpAst)
+    {
+        dumpAstTask((ast::Exp*)_pSEI->pExpTree, _pSEI->iTimed != 0);
+    }
 
-    parser->setParseTrace(_pSEI->iParseTrace != 0);
-    if (strcmp(_pSEI->pstExec, "") != 0)
+    /*
+     ** -*- PRETTY PRINT TREE -*-
+     */
+    if (_pSEI->iPrintAst)
     {
-        wchar_t *pwstCommand = to_wide_string(_pSEI->pstExec);
+        printAstTask((ast::Exp*)_pSEI->pExpTree, _pSEI->iTimed != 0);
+    }
 
-        /*
-         ** -*- PARSING -*-
-         */
-        parseCommandTask(parser, _pSEI->iTimed != 0, pwstCommand);
+    /*
+     ** -*- EXECUTING TREE -*-
+     */
+    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);
+    }
 
-        /*
-         ** -*- DUMPING TREE -*-
-         */
-        if (_pSEI->iDumpAst)
+    /*
+     ** -*- DUMPING STACK AFTER EXECUTION -*-
+     */
+    if (_pSEI->iDumpStack)
+    {
+        dumpStackTask(_pSEI->iTimed != 0);
+    }
+}
+
+// Thread used to parse and execute Scilab command setted in storeCommand
+void* scilabReadAndExecCommand(void* param)
+{
+    int iconsoleCmd = 0;
+    char* command = NULL;
+    ScilabEngineInfo* _pSEI = (ScilabEngineInfo*)param;
+
+    while (!ConfigVariable::getForceQuit())
+    {
+        if (isEmptyCommandQueue())
         {
-            dumpAstTask(parser->getTree(), _pSEI->iTimed != 0);
+            __LockSignal(pLaunchScilabLock);
+            __Wait(&LaunchScilab, pLaunchScilabLock);
+            __UnLockSignal(pLaunchScilabLock);
         }
 
-        if (parser->getExitStatus() == Parser::Succeded)
+        _pSEI->isInterruptible = GetCommand(&command, &iconsoleCmd);
+
+        __Lock(&m_ParseLock);
+
+        Parser parser;
+        parser.setParseTrace(_pSEI->iParseTrace != 0);
+        parseCommandTask(&parser, _pSEI->iTimed != 0, command);
+
+        if (parser.getExitStatus() == Parser::Failed)
         {
-            /*
-             ** -*- PRETTY PRINT TREE -*-
-             */
-            if (_pSEI->iPrintAst)
-            {
-                printAstTask(parser->getTree(), _pSEI->iTimed != 0);
-            }
+            scilabWriteW(parser.getErrorMessage());
+            __UnLock(&m_ParseLock);
+            continue;
+        }
+
+        _pSEI->pExpTree = parser.getTree();
+        __UnLock(&m_ParseLock);
+
+        processCommand(_pSEI);
+
+        FREE(command);
+
+        if (iconsoleCmd)
+        {
+            __Signal(&ExecDone);
+        }
+    }
+
+    return NULL;
+}
+
+//Thread used to parse and set console commands in storeCommand
+void* scilabReadAndStore(void* param)
+{
+    Parser::ControlStatus controlStatus = Parser::AllControlClosed;
+
+    char *command = NULL;
+    wchar_t* parserErrorMsg = NULL;
+
+    ScilabEngineInfo* _pSEI = (ScilabEngineInfo*)param;
+
+    if (_pSEI->iMultiLine)
+    {
+        command = _pSEI->pstExec;
+    }
+
+    while (!ConfigVariable::getForceQuit())
+    {
+        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");
+        }
+
+        do
+        {
+            // Show Parser Sate before prompt
+            stateShow(controlStatus);
+
+            int pause = ConfigVariable::getPauseLevel();
 
-            /*
-             ** -*- EXECUTING TREE -*-
-             */
-            if (_pSEI->iExecAst)
+            //set prompt value
+            C2F(setprlev) (&pause);
+
+            char *pstRead = scilabRead();
+
+            if (command == NULL)
             {
-                //before calling YaspReader, try to call %onprompt function
-                callOnPrompt();
-                execAstTask(parser->getTree(), _pSEI->iSerialize != 0, _pSEI->iTimed != 0, _pSEI->iAstTimed != 0, _pSEI->iExecVerbose != 0);
+                command = pstRead;
+                if (strcmp(command, "") == 0)
+                {
+                    FREE(command);
+                    command = NULL;
+                    break;
+                }
             }
-
-            /*
-             ** -*- DUMPING STACK AFTER EXECUTION -*-
-             */
-            if (_pSEI->iDumpStack)
+            else
             {
-                dumpStackTask(_pSEI->iTimed != 0);
+                //+1 for null termination and +1 for '\n'
+                size_t iLen = strlen(command) + strlen(pstRead) + 2;
+                char *pstNewCommand = (char *)MALLOC(iLen * sizeof(char));
+
+#ifdef _MSC_VER
+                sprintf_s(pstNewCommand, iLen, "%s\n%s", command, pstRead);
+#else
+                sprintf(pstNewCommand, "%s\n%s", command, pstRead);
+#endif
+                FREE(pstRead);
+                FREE(command);
+                command = pstNewCommand;
             }
+
+            __Lock(&m_ParseLock);
+            parseCommandTask(&parser, _pSEI->iTimed != 0, command);
+            controlStatus = parser.getControlStatus();
+            exitStatus = parser.getExitStatus();
+            parserErrorMsg = parser.getErrorMessage();
+            __UnLock(&m_ParseLock);
         }
-        else if (parser->getExitStatus() == Parser::Failed && parser->getControlStatus() == Parser::AllControlClosed)
+        while (controlStatus != Parser::AllControlClosed);
+
+        if (exitStatus == Parser::Failed)
         {
-            if (_pSEI->iExecAst)
-            {
-                //before calling YaspReader, try to call %onprompt function
-                callOnPrompt();
-            }
+            FREE(command);
+            command = NULL;
+            scilabForcedWriteW(parserErrorMsg);
+            continue;
+        }
 
-            scilabWriteW(parser->getErrorMessage());
+        if (command == NULL)
+        {
+            continue;
         }
 
-        FREE(pwstCommand);
+        StoreConsoleCommandWithFlag(command, 1);
+
+        FREE(command);
+        command = NULL;
+
+        __LockSignal(pExecDoneLock);
+        __Wait(&ExecDone, pExecDoneLock);
+        __UnLockSignal(pExecDoneLock);
     }
-    else
+
+    return NULL;
+}
+
+void ReleaseScilabSignal(__threadSignal* _Signal, __threadSignalLock* _Lock)
+{
+#ifdef _MSC_VER
+    /* http://msdn.microsoft.com/en-us/magazine/cc164040.aspx */
+    if (_Lock && (_Lock->LockCount == -1))
+#else
+    if (_Lock)
+#endif
     {
-        if (_pSEI->iExecAst)
-        {
-            //before calling YaspReader, try to call %onprompt function
-            callOnPrompt();
-        }
+        __UnLockSignal(_Lock);
+        munmap(_Lock, sizeof(__threadSignalLock));
+        _Lock = NULL;
+#ifdef _MSC_VER
+        /* On Windows , we need to force value */
+        _Signal = __StaticInitThreadSignal;
+#endif
+    }
+}
+
+void InitializeScilabSignal(__threadSignal* _Signal, __threadSignalLock** _Lock, void (*func)(void))
+{
+    if (*_Lock == NULL)
+    {
+        *_Lock = (__threadSignalLock*)mmap(0, sizeof(__threadSignalLock), PROT_READ | PROT_WRITE, MAP_SHARED |  MAP_ANONYMOUS, -1, 0);
+        __InitSignal(_Signal);
+        __InitSignalLock(*_Lock);
+        atexit(func);
     }
+}
 
-    Parser::ControlStatus ret = parser->getControlStatus();
-    delete parser;
-    return ret;
+void ReleaseLaunchScilabSignal(void)
+{
+    ReleaseScilabSignal(&LaunchScilab, pLaunchScilabLock);
+}
+
+void ReleaseDoneScilabSignal(void)
+{
+    ReleaseScilabSignal(&ExecDone, pExecDoneLock);
 }
 
 /*
@@ -494,11 +686,6 @@ static Parser::ControlStatus processCommand(ScilabEngineInfo* _pSEI)
 */
 static int interactiveMain(ScilabEngineInfo* _pSEI)
 {
-    int pause = 0;
-    char *command = NULL;
-
-    Parser::ControlStatus controlStatus = Parser::AllControlClosed;
-
 #ifndef WITH_GUI
 #ifndef _MSC_VER
     if (getScilabMode() != SCILAB_NWNI)
@@ -512,61 +699,27 @@ static int interactiveMain(ScilabEngineInfo* _pSEI)
 
     InitializeHistoryManager();
 
-    //before calling reader, try to call %onprompt function
-    callOnPrompt();
-
-    while (!ConfigVariable::getForceQuit())
-    {
-        // Show Parser Sate before prompt
-        stateShow(controlStatus);
-
-        pause = ConfigVariable::getPauseLevel();
+    __threadId threadIdConsole;
+    __threadKey threadKeyConsole;
+    __threadId threadIdCommand;
+    __threadKey threadKeyCommand;
 
-        //set prompt value
-        C2F(setprlev) (&pause);
+    __InitLock(&m_ParseLock);
+    InitializeScilabSignal(&LaunchScilab, &pLaunchScilabLock, ReleaseLaunchScilabSignal);
+    InitializeScilabSignal(&ExecDone, &pExecDoneLock, ReleaseDoneScilabSignal);
 
-        if (controlStatus == Parser::AllControlClosed)
-        {
-            if (command)
-            {
-                FREE(command);
-                command = NULL;
-            }
+    // thread to manage console command
+    __CreateThreadWithParams(&threadIdConsole, &threadKeyConsole, &scilabReadAndStore, _pSEI);
 
-            if (ConfigVariable::isEmptyLineShow())
-            {
-                scilabWriteW(L"\n");
-            }
+    // thread to manage command stored
+    __CreateThreadWithParams(&threadIdCommand, &threadKeyCommand, &scilabReadAndExecCommand, _pSEI);
 
-            command = scilabRead();
-        }
-        else
-        {
-            char *pstRead = scilabRead();
-
-            //+1 for null termination and +1 for '\n'
-            size_t iLen = strlen(command) + strlen(pstRead) + 2;
-            char *pstNewCommand = (char *)MALLOC(iLen * sizeof(char));
+    __WaitThreadDie(threadIdCommand);
 
-#ifdef _MSC_VER
-            sprintf_s(pstNewCommand, iLen, "%s\n%s", command, pstRead);
-#else
-            sprintf(pstNewCommand, "%s\n%s", command, pstRead);
-#endif
-            FREE(pstRead);
-            FREE(command);
-            command = pstNewCommand;
-        }
-
-        _pSEI->pstExec = command;
-        controlStatus = processCommand(_pSEI);
-        _pSEI->pstExec = NULL;
-    }
 #ifdef DEBUG
     std::cerr << "To end program press [ENTER]" << std::endl;
 #endif
 
-    FREE(command);
     return ConfigVariable::getExitStatus();
 }
 
index 75a87b9..f17511c 100644 (file)
 #include "runner.hxx"
 
 __threadLock Runner::m_lock;
+
 __threadSignal Runner::m_awakeScilab;
 __threadSignalLock Runner::m_awakeScilabLock;
 
+__threadSignal Runner::m_AstPending;
+__threadSignalLock Runner::m_AstPendingLock;
+
+
 using namespace ast;
 
+__threadSignal* getAstPendingSignal(void)
+{
+    return Runner::getAstPendingSignal();
+}
+
+
 void Runner::init()
 {
     __InitSignal(&m_awakeScilab);
     __InitSignalLock(&m_awakeScilabLock);
+
+    __InitSignal(&m_AstPending);
+    __InitSignalLock(&m_AstPendingLock);
 }
 
 void *Runner::launch(void *args)
@@ -34,6 +48,7 @@ void *Runner::launch(void *args)
 
     //exec !
     Runner *me = (Runner *)args;
+
     try
     {
         me->getProgram()->accept(*(me->getVisitor()));
@@ -57,6 +72,15 @@ void *Runner::launch(void *args)
         bdoUnlock = true;
     }
 
+    if (pThread->isInterruptible()) // 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.
+        __Signal(&Runner::m_AstPending);
+    }
+
     //unregister thread
     ConfigVariable::deleteThread(currentThreadKey);
 
@@ -66,6 +90,7 @@ void *Runner::launch(void *args)
     {
         UnlockPrompt();
     }
+
     return NULL;
 }
 
@@ -86,7 +111,7 @@ void Runner::UnlockPrompt()
 }
 
 
-void Runner::execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor)
+void Runner::execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor, bool _isPrioritaryThread)
 {
     try
     {
@@ -98,16 +123,55 @@ void Runner::execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor)
         __InitLock(&m_lock);
         //lock locker
         __Lock(&m_lock);
+
+        types::ThreadId* pInterruptibleThread = ConfigVariable::getLastRunningThread();
+        if (_isPrioritaryThread)
+        {
+            if (pInterruptibleThread)
+            {
+                if (pInterruptibleThread->isInterruptible())
+                {
+                    pInterruptibleThread->setInterrupt(true);
+
+                    __LockSignal(&m_AstPendingLock);
+                    __Wait(&m_AstPending, &m_AstPendingLock);
+                    __UnLockSignal(&m_AstPendingLock);
+                }
+                else
+                {
+                    __WaitThreadDie(pInterruptibleThread->getThreadId());
+                    pInterruptibleThread = NULL;
+                }
+            }
+        }
+        else if (pInterruptibleThread)
+        {
+            __WaitThreadDie(pInterruptibleThread->getThreadId());
+            pInterruptibleThread = NULL;
+        }
+
         //launch thread but is can't really start since locker is locked
         __CreateThreadWithParams(&threadId, &threadKey, &Runner::launch, runMe);
         runMe->setThreadId(threadId);
         runMe->setThreadKey(threadKey);
 
         //register thread
-        ConfigVariable::addThread(new ThreadId(threadId, threadKey));
+        types::ThreadId* pThread = new ThreadId(threadId, threadKey);
+        ConfigVariable::addThread(pThread);
+        if (_isPrioritaryThread)
+        {
+            pThread->setInterruptible(false);
+        }
+
         //free locker to release thread && wait and of thread execution
         LockPrompt();
 
+        if (pInterruptibleThread)
+        {
+            pInterruptibleThread->setInterrupt(false);
+            pInterruptibleThread->resume();
+        }
+
         types::ThreadId* pExecThread = ConfigVariable::getThread(threadKey);
         if (pExecThread == NULL)
         {
index 8209be9..831ef7c 100644 (file)
@@ -15,6 +15,17 @@ extern "C"
 #define NOMINMAX
 #include "storeCommand.h"
 #include "Thread_Wrapper.h"
+
+    // mmap
+#ifdef _MSC_VER
+#include "mmapWindows.h"
+#else
+#include <sys/mman.h>
+#ifndef MAP_ANONYMOUS
+# define MAP_ANONYMOUS MAP_ANON
+#endif
+#endif
+
 }
 
 #include "parser.hxx"
@@ -23,6 +34,7 @@ extern "C"
 #include "scilabWrite.hxx"
 #include "scilabexception.hxx"
 #include "localization.hxx"
+#include "runner.hxx"
 
 using namespace ast;
 /*--------------------------------------------------------------------------*/
@@ -35,120 +47,130 @@ using namespace ast;
  *           int C2F(getmen)(char * btn_cmd,int * lb, int * entry)
  */
 /*--------------------------------------------------------------------------*/
-#define IMPORT_SIGNAL extern
-/*--------------------------------------------------------------------------*/
-typedef struct commandRec
+struct CommandRec
 {
-    char              *command;                /* command info one string two integers */
-    int               flag; /* 1 if the command execution cannot be interrupted */
-    struct commandRec *next;
-} 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) {}
+};
 /*--------------------------------------------------------------------------*/
 /* Extern Signal to say we git a StoreCommand. */
-IMPORT_SIGNAL __threadSignal LaunchScilab;
+extern "C"
+{
+    extern __threadSignal LaunchScilab;
+}
 /*--------------------------------------------------------------------------*/
-static CommandRec *commandQueue = NULL;
-static __threadLock commandQueueSingleAccess = __StaticInitLock;
+static std::list<CommandRec> commandQueue;
+static std::list<CommandRec> commandQueuePrioritary;
+//static __threadLock commandQueueSingleAccess = __StaticInitLock;
+static void release(void);
+static __threadLock* getCommandQueueSingleAccess()
+{
+    static __threadLock* ptr = NULL;
+    if (!ptr)
+    {
+        ptr = (__threadLock*)mmap(0, sizeof(__threadLock), PROT_READ | PROT_WRITE, MAP_SHARED |  MAP_ANONYMOUS, -1, 0);
+#ifdef _MSC_VER
+        *ptr =  __StaticInitLock;
+#else
+        __InitSignalLock(ptr);
+#endif
+        atexit(release);
+    }
+    return ptr;
+}
+
+static void release(void)
+{
+    if (getCommandQueueSingleAccess())
+    {
+        __UnLock(getCommandQueueSingleAccess());
+    }
+}
 /*--------------------------------------------------------------------------*/
-int StoreCommand (wchar_t *command)
+int StoreCommand (char *command)
 {
-    return StoreCommandWithFlag (command, 0);
+    return StoreCommandWithFlag (command, 1);
 }
+
 /*--------------------------------------------------------------------------*/
 /*
  * try to execute a command or add it to the end of command queue
- * flag = 0 : the command is not shown in scilab window
- * flag = 1 : the command is shown in scilab window (if at prompt) and executed sequentially
  */
-int StoreCommandWithFlag (wchar_t *command, int flag)
+int StoreCommandWithFlag (char *command, int isInterruptible)
 {
-    Parser parser;
-    try
-    {
-        parser.parse(command);
-        if (parser.getExitStatus() == Parser::Succeded)
-        {
-            ast::ExecVisitor exec;
-            parser.getTree()->accept(exec);
-        }
-        else
-        {
-            throw ast::ScilabException(parser.getErrorMessage());
-        }
-    }
-    catch (const ast::ScilabException& se)
-    {
-        scilabErrorW(L"\n");
-        scilabErrorW(L"\n");
-        scilabErrorW(command);
-        scilabErrorW(L"\n");
-        scilabErrorW(se.GetErrorMessage().c_str());
-        scilabErrorW(L"\n");
-        scilabErrorW(_W("while executing a callback").c_str());
-    }
+    __Lock(getCommandQueueSingleAccess());
+    commandQueue.emplace_back(os_strdup(command), isInterruptible, 0);
+    __UnLock(getCommandQueueSingleAccess());
+    __Signal(&LaunchScilab);
 
-    delete parser.getTree();
     return 0;
 }
 /*--------------------------------------------------------------------------*/
 /*
  * try to execute a command or add it to the _BEGINNING_ of command queue
- * flag = 0 : the command is not shown in scilab window
- * flag = 1 : the command is shown in scilab window (if at prompt) and executed sequentially
  */
-int StorePrioritaryCommandWithFlag (wchar_t *command, int flag)
+int StoreConsoleCommandWithFlag (char *command, int isInterruptible)
 {
-    Parser parser;
-
-    try
-    {
-        parser.parse(command);
-        if (parser.getExitStatus() == Parser::Succeded)
-        {
-            ast::ExecVisitor exec;
-            parser.getTree()->accept(exec);
-        }
-        else
-        {
-            throw ast::ScilabException(parser.getErrorMessage());
-        }
-    }
-    catch (const ast::ScilabException& se)
-    {
-        scilabErrorW(L"\n");
-        scilabErrorW(L"\n");
-        scilabErrorW(command);
-        scilabErrorW(L"\n");
-        scilabErrorW(se.GetErrorMessage().c_str());
-        scilabErrorW(L"\n");
-        scilabErrorW(_W("while executing a callback").c_str());
-    }
+    __Lock(getCommandQueueSingleAccess());
+    commandQueuePrioritary.emplace_back(os_strdup(command), isInterruptible, 1);
+    __UnLock(getCommandQueueSingleAccess());
+    __Signal(&LaunchScilab);
+    Runner::UnlockPrompt();
+    return 0;
+}
 
-    delete parser.getTree();
-    return (0);
+int StorePrioritaryCommandWithFlag (char *command, int isInterruptible)
+{
+    __Lock(getCommandQueueSingleAccess());
+    commandQueuePrioritary.emplace_back(os_strdup(command), isInterruptible, 0);
+    __UnLock(getCommandQueueSingleAccess());
+    __Signal(&LaunchScilab);
+    Runner::UnlockPrompt();
+    return 0;
 }
 /*--------------------------------------------------------------------------*/
 int isEmptyCommandQueue(void)
 {
-#pragma message("WARNING : isEmptyCommandQueue is deprecated. It will be removed _BEFORE_ Scilab 6.0.")
-    // FIXME : Do not forget to remove me.
-    return 0;
+    return (commandQueuePrioritary.empty() && commandQueue.empty());
 }
 /*--------------------------------------------------------------------------*/
 /*
  * Gets info on the first queue element
  * and remove it from the queue
  */
-int GetCommand ( char *str)
+int GetCommand (char** cmd, int* piConsoleCmd)
 {
-#pragma message("WARNING : GetCommand is deprecated. It will be removed _BEFORE_ Scilab 6.0.")
-    // FIXME : Do not forget to remove me.
-    return 0;
+    int isInterruptible = 0;
+    __Lock(getCommandQueueSingleAccess());
+
+    if (commandQueuePrioritary.empty() == false)
+    {
+        *cmd = os_strdup(commandQueuePrioritary.front().m_command);
+        isInterruptible = commandQueuePrioritary.front().m_isInterruptible;
+        *piConsoleCmd = commandQueuePrioritary.front().m_consoleCmd;
+
+        FREE (commandQueuePrioritary.front().m_command);
+        commandQueuePrioritary.pop_front();
+    }
+    else if (commandQueue.empty() == false)
+    {
+        *cmd = os_strdup(commandQueue.front().m_command);
+        isInterruptible = commandQueue.front().m_isInterruptible;
+        *piConsoleCmd = commandQueue.front().m_consoleCmd;
+
+        FREE (commandQueue.front().m_command);
+        commandQueue.pop_front();
+    }
+    __UnLock(getCommandQueueSingleAccess());
+
+    return isInterruptible;
 }
 /*--------------------------------------------------------------------------*/
 int ismenu(void)
 {
-#pragma message("WARNING : ismenu is deprecated. It will be removed _BEFORE_ Scilab 6.0.")
+    //#pragma message("WARNING : ismenu is deprecated. It will be removed _BEFORE_ Scilab 6.0.")
     // FIXME : Do not forget to remove me.
     return 0;
 }
@@ -156,7 +178,7 @@ int ismenu(void)
 /* menu/button info for Scilab */
 int C2F(getmen)(char * btn_cmd, int * lb, int * entry)
 {
-#pragma message("WARNING : C2F(getmen) is deprecated. It will be removed _BEFORE_ Scilab 6.0.")
+    //#pragma message("WARNING : C2F(getmen) is deprecated. It will be removed _BEFORE_ Scilab 6.0.")
     // FIXME : Do not forget to remove me.
     return 0;
 }
index 21ec687..8ceabf5 100644 (file)
@@ -61,7 +61,7 @@ void parseFileTask(Parser *parser, bool timed, const wchar_t* file_name, const w
 **
 ** Parse the given command and create the AST.
 */
-void parseCommandTask(Parser *parser, bool timed, wchar_t *command)
+void parseCommandTask(Parser *parser, bool timed, char *command)
 {
 #ifdef DEBUG
     std::cerr << "*** Processing [" <<  command << "]..." << std::endl;
@@ -134,7 +134,7 @@ void printAstTask(ast::Exp *tree, bool timed)
 **
 ** Execute the stored AST.
 */
-void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose)
+void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose, bool isPriorityThread)
 {
     if (tree == NULL)
     {
@@ -188,7 +188,7 @@ void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool
         exec = new ast::ExecVisitor();
     }
 
-    Runner::execAndWait(newTree, exec);
+    Runner::execAndWait(newTree, exec, isPriorityThread);
     //DO NOT DELETE tree or newTree, they was deleted by Runner or previously;
 
     if (timed)
@@ -236,7 +236,7 @@ void execScilabStartTask(bool _bSerialize)
         return;
     }
 
-    execAstTask(parse.getTree(), _bSerialize, false, false, false);
+    execAstTask(parse.getTree(), _bSerialize, false, false, false, true);
 }
 
 /*
@@ -258,7 +258,7 @@ void execScilabQuitTask(bool _bSerialize)
         return;
     }
 
-    execAstTask(parse.getTree(), _bSerialize, false, false, false);
+    execAstTask(parse.getTree(), _bSerialize, false, false, false, true);
 }
 
 
index 0fc1721..3a901ab 100644 (file)
@@ -14,5 +14,5 @@
 /*--------------------------------------------------------------------------*/
 void ScilabExit(void)
 {
-    StoreCommand(L"exit(0)");
+    StorePrioritaryCommandWithFlag("exit(0)", 0);
 }
index 8cc2fa4..38916d4 100644 (file)
@@ -4,6 +4,7 @@ LIBRARY    core.dll
 EXPORTS
 ;
 StoreCommand
+StorePrioritaryCommandWithFlag
 freeArrayOfString
 MyHeapAlloc
 MyHeapFree
index ae501f0..a1e5751 100644 (file)
@@ -58,7 +58,7 @@ public abstract class ScilabCloseCallBack extends CommonCallBack {
             public void callBack() {
                 Thread launchMe = new Thread() {
                     public void run() {
-                        InterpreterManagement.putCommandInScilabQueue(getCommand());
+                        InterpreterManagement.requestScilabExec(getCommand());
                     }
                 };
                 launchMe.start();
index 15714db..ca9774b 100644 (file)
@@ -1468,7 +1468,7 @@ static void cossim(double *told)
     int i3 = 0;
 
     //** used for the [stop] button
-    static char CommandToUnstack[1024];
+    char* CommandToUnstack;
     static int CommandLength = 0;
     static int SeqSync = 0;
     static int one = 1;
@@ -1768,9 +1768,11 @@ static void cossim(double *told)
         while (ismenu()) //** if the user has done something, do the actions
         {
             int ierr2 = 0;
-            SeqSync = GetCommand(CommandToUnstack); //** get to the action
+            int iUnused;
+            SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
             CommandLength = (int)strlen(CommandToUnstack);
             //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
+            FREE(CommandToUnstack);
         }
         if (C2F(coshlt).halt != 0)
         {
@@ -2159,7 +2161,7 @@ static void cossimdaskr(double *told)
     /* System generated locals */
     int i3;
     //** used for the [stop] button
-    static char CommandToUnstack[1024];
+    char* CommandToUnstack;
     static int CommandLength = 0;
     static int SeqSync = 0;
     static int one = 1;
@@ -2951,9 +2953,11 @@ static void cossimdaskr(double *told)
         while (ismenu()) //** if the user has done something, do the actions
         {
             int ierr2 = 0;
-            SeqSync = GetCommand(CommandToUnstack); //** get to the action
+            int iUnused;
+            SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
             CommandLength = (int)strlen(CommandToUnstack);
             //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
+            FREE(CommandToUnstack);
         }
         if (C2F(coshlt).halt != 0)
         {
@@ -3137,9 +3141,11 @@ L30:
                         while (ismenu()) //** if the user has done something, do the actions
                         {
                             int ierr2 = 0;
-                            SeqSync = GetCommand(CommandToUnstack); //** get to the action
+                            int iUnused;
+                            SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
                             CommandLength = (int)strlen(CommandToUnstack);
                             //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
+                            FREE(CommandToUnstack);
                         }
                         if (C2F(coshlt).halt != 0)
                         {
@@ -3487,9 +3493,11 @@ L30:
                 while (ismenu()) //** if the user has done something, do the actions
                 {
                     int ierr2 = 0;
-                    SeqSync = GetCommand(CommandToUnstack); //** get to the action
+                    int iUnused;
+                    SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
                     CommandLength = (int)strlen(CommandToUnstack);
                     //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
+                    FREE(CommandToUnstack);
                 }
 
                 if (C2F(coshlt).halt != 0)
@@ -6999,7 +7007,7 @@ int simblkKinsol(N_Vector yy, N_Vector resval, void *rdata)
 static int CallKinsol(double *told)
 {
     //** used for the [stop] button
-    static char CommandToUnstack[1024];
+    char* CommandToUnstack;
     static int CommandLength = 0;
     static int SeqSync = 0;
     static int one = 1;
@@ -7154,9 +7162,11 @@ static int CallKinsol(double *told)
             while (ismenu()) //** if the user has done something, do the actions
             {
                 int ierr2 = 0;
-                SeqSync = GetCommand(CommandToUnstack); //** get at the action
+                int iUnused;
+                SeqSync = GetCommand(&CommandToUnstack, &iUnused); //** get to the action
                 CommandLength = (int)strlen(CommandToUnstack);
                 //syncexec(CommandToUnstack, &CommandLength, &ierr2, &one, CommandLength); //** execute it
+                FREE(CommandToUnstack);
             }
 
             if (C2F(coshlt).halt != 0)
index 44c3cbe..a313ba3 100644 (file)
@@ -125,7 +125,7 @@ int TCL_EvalScilabCmd(ClientData clientData, Tcl_Interp * theinterp, int objc, C
                     FREE(pstCommand);
                     return TCL_ERROR;
                 }
-                seqf[ncomm] = GetCommand (comm[ncomm]);
+                //                seqf[ncomm] = GetCommand (comm[ncomm]);
             }
             if (ismenu())
             {
index 22ab92d..b868734 100644 (file)
@@ -20,7 +20,6 @@
 #include "configvariable_interface.h"
 #include "realmain.h"
 #include "sciprint.h"
-#include "LaunchScilabSignal.h"
 /*--------------------------------------------------------------------------*/
 static void interrupt_setup (void);
 static void interrupt (int an_int);
@@ -29,7 +28,6 @@ jmp_buf env;
 /*--------------------------------------------------------------------------*/
 int sci_windows_main ( int *nos, char *path, InitScriptType pathtype, int *lpath, int memory)
 {
-    InitializeLaunchScilabSignal();
     setbuf (stderr, (char *) NULL);
     if (!setjmp (env))
     {