2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2011-2011 - DIGITEO - Bruno JOFRET
4 * Copyright (C) 2013-2013 - LIP6 - Peter Senna Tschudin
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
16 __threadLock Jitter::m_lock;
17 __threadSignal Jitter::m_awakeScilab;
18 __threadSignalLock Jitter::m_awakeScilabLock;
22 __InitSignal(&m_awakeScilab);
23 __InitSignalLock(&m_awakeScilabLock);
26 void *Jitter::launch(void *args)
28 bool bdoUnlock = false;
29 //try to lock locker ( waiting parent thread register me )
35 Jitter *me = (Jitter *)args;
38 me->getProgram()->accept(*(me->getVisitor()));
39 ConfigVariable::clearLastError();
41 catch (ScilabException se)
43 scilabErrorW(se.GetErrorMessage().c_str());
46 __threadKey currentThreadKey = __GetCurrentThreadKey();
48 //change thread status
49 ThreadId* pThread = ConfigVariable::getThread(currentThreadKey);
50 if (pThread->getStatus() != ThreadId::Aborted)
52 pThread->setStatus(ThreadId::Done);
57 ConfigVariable::deleteThread(currentThreadKey);
68 void Jitter::LockPrompt()
70 __LockSignal(&m_awakeScilabLock);
71 //free locker to release thread
73 __Wait(&m_awakeScilab, &m_awakeScilabLock);
74 __UnLockSignal(&m_awakeScilabLock);
77 void Jitter::UnlockPrompt()
79 __LockSignal(&m_awakeScilabLock);
80 __Signal(&m_awakeScilab);
81 __UnLockSignal(&m_awakeScilabLock);
85 void Jitter::execAndWait(ast::Exp* _theProgram, ast::JITVisitor *_visitor)
89 Jitter *runMe = new Jitter(_theProgram, _visitor);
90 __threadKey threadKey;
97 //launch thread but is can't really start since locker is locked
98 __CreateThreadWithParams(&threadId, &threadKey, &Jitter::launch, runMe);
99 runMe->setThreadId(threadId);
100 runMe->setThreadKey(threadKey);
103 ConfigVariable::addThread(new ThreadId(threadId, threadKey));
104 //free locker to release thread && wait and of thread execution
107 types::ThreadId* pExecThread = ConfigVariable::getThread(threadKey);
108 if (pExecThread == NULL)
110 //call pthread_join to clean stack allocation
111 __WaitThreadDie(threadId);
114 catch (ScilabException se)
120 void Jitter::exec(ast::Exp* _theProgram, ast::JITVisitor *_visitor)
122 m_theProgram = _theProgram;
123 m_visitor = _visitor;
124 __CreateThreadWithParams(&m_threadId, &m_threadKey, &Jitter::launch, this);