Merge remote-tracking branch 'origin/master' into jit
[scilab.git] / scilab / modules / threads / includes / Thread_Wrapper.h
1 /*
2  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  *  Copyright (C) 2008-2008 - INRIA - Bruno JOFRET
4  *  Copyright (C) 2008-2008 - INRIA - Allan CORNET
5  *  Copyright (C) 2011-2011 - DIGITEO - Bruno JOFRET
6  *
7  *  This file must be used under the terms of the CeCILL.
8  *  This source file is licensed as described in the file COPYING, which
9  *  you should have received as part of this distribution.  The terms
10  *  are also available at
11  *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12  *
13  */
14
15 /*
16 ** Thread wrapper to have an easy way to manage
17 ** those features on each platform
18 */
19
20 #ifndef __THREAD_WRAPPER_H__
21 #define __THREAD_WRAPPER_H__
22
23 #include "dynlib_threads.h"
24
25 /*
26 ** WINDOWS
27 */
28 #ifdef _MSC_VER
29 #ifndef _WIN32_WINNT
30 #define _WIN32_WINNT 0x500
31 #endif
32 #define NOMINMAX
33 #include <windows.h>
34 #undef NOMINMAX
35
36 typedef DWORD                           __threadKey;
37 typedef HANDLE                          __threadId;
38 typedef HANDLE                          __threadLock;
39 typedef CRITICAL_SECTION                __threadSignalLock;
40 typedef HANDLE                          __threadSignal;
41 #define __StaticInitLock                NULL
42
43 #define __StaticInitThreadSignal        NULL
44
45 #else
46 /*
47 ** LINUX & Mac
48 */
49 #include <pthread.h>
50 #include <signal.h>
51 #include <stdlib.h> // malloc
52
53 typedef pthread_t                       __threadKey;
54 typedef pthread_t                       __threadId;
55 typedef pthread_mutex_t                 __threadLock;
56 typedef pthread_mutex_t                 __threadSignalLock;
57 typedef pthread_cond_t                  __threadSignal;
58 #define __StaticInitLock                PTHREAD_MUTEX_INITIALIZER
59
60 #define __StaticInitThreadSignal        PTHREAD_COND_INITIALIZER
61 #endif
62
63 THREADS_IMPEXP void __InitLock(__threadLock *lockName);
64
65 THREADS_IMPEXP void __Lock(__threadLock *lockName);
66
67 THREADS_IMPEXP void __UnLock(__threadLock *lockName);
68
69 THREADS_IMPEXP void __InitSignalLock(__threadSignalLock *lockName);
70
71 THREADS_IMPEXP void __LockSignal(__threadSignalLock *lockName);
72
73 THREADS_IMPEXP void __UnLockSignal(__threadSignalLock *lockName);
74
75 THREADS_IMPEXP void __InitSignal(__threadSignal *signalName);
76
77 THREADS_IMPEXP void __Signal(__threadSignal *signalName);
78
79 THREADS_IMPEXP void __Wait(__threadSignal *signalName, __threadSignalLock *lockName);
80
81 THREADS_IMPEXP void __CreateThread(__threadId *threadId, __threadKey *threadKey, void * (*functionName) (void *));
82
83 THREADS_IMPEXP void __CreateThreadWithParams(__threadId *threadId, __threadKey *threadKey, void * (*functionName) (void *), void *params);
84
85 THREADS_IMPEXP void __WaitThreadDie(__threadId threadId);
86
87 THREADS_IMPEXP void __Terminate(__threadId threadId);
88
89 THREADS_IMPEXP __threadId __GetCurrentThreadId();
90
91 THREADS_IMPEXP __threadKey __GetCurrentThreadKey();
92
93 THREADS_IMPEXP void __SuspendThread(__threadId ThreadId);
94
95 THREADS_IMPEXP void __ResumeThread(__threadId ThreadId);
96
97 #endif /* !__THREAD_WRAPPER_H__ */
98