Threads management modified to execute all scilab script in the main thread.
[scilab.git] / scilab / modules / ast / includes / system_env / threadmanagement.hxx
1 /*
2 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 *  Copyright (C) 2015 - Scilab-Enterprises - Cedric Delamarre
4 *
5 *  This file must be used under the terms of the CeCILL.
6 *  This source file is licensed as described in the file COPYING, which
7 *  you should have received as part of this distribution.  The terms
8 *  are also available at
9 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
13 #ifndef __THREADMANAGEMENT_HXX__
14 #define __THREADMANAGEMENT_HXX__
15
16 extern "C"
17 {
18 #include "Thread_Wrapper.h"
19 #include "dynamiclibrary.h"
20 #include "dynlib_ast.h"
21 }
22
23 //#define DEBUG_THREAD
24
25 class EXTERN_AST ThreadManagement
26 {
27 private :
28     static __threadLock m_RunnerLock;
29     static __threadLock m_StartLock;
30     static __threadLock m_ParseLock;
31     static __threadLock m_StoreCommandLock;
32
33     static __threadSignal m_ConsoleExecDone;
34     static __threadSignalLock m_ConsoleExecDoneLock;
35
36     static __threadSignal m_AwakeRunner;
37     static __threadSignalLock m_AwakeRunnerLock;
38
39     static __threadSignal m_AvailableRunner;
40     static __threadSignalLock m_AvailableRunnerLock;
41
42     static __threadSignal m_StartPending;
43     static __threadSignalLock m_StartPendingLock;
44
45     static __threadSignal m_CommandStored;
46     static __threadSignalLock m_CommandStoredLock;
47
48     static __threadSignal m_RunMe;
49     static __threadSignalLock m_RunMeLock;
50
51     // used to avoid "Spurious Wakeups"
52     static bool m_AvailableRunnerWasSignalled;
53     static bool m_ConsoleExecDoneWasSignalled;
54     static bool m_AwakeRunnerWasSignalled;
55     static bool m_StartPendingWasSignalled;
56     static bool m_CommandStoredWasSignalled;
57     static bool m_RunMeWasSignalled;
58
59 public :
60     static void initialize(void);
61
62     static void LockStart(void);
63     static void UnlockStart(void);
64     static void LockParser(void);
65     static void UnlockParser(void);
66     static void LockStoreCommand(void);
67     static void UnlockStoreCommand(void);
68     static void LockRunner(void);
69     static void UnlockRunner(void);
70
71     static void SendAvailableRunnerSignal(void);
72     static void WaitForAvailableRunnerSignal(void);
73     static void SendConsoleExecDoneSignal(void);
74     static void WaitForConsoleExecDoneSignal(void);
75     static void SendAwakeRunnerSignal(void);
76     static void WaitForAwakeRunnerSignal(void);
77     static void SendStartPendingSignal(void);
78     static void WaitForStartPendingSignal(void);
79     static void SendCommandStoredSignal(void);
80     static void WaitForCommandStoredSignal(void);
81     static void SendRunMeSignal(void);
82     static void WaitForRunMeSignal(void);
83
84 };
85
86 #endif /* !__THREADMANAGEMENT_HXX__ */