* src/vm/jit/i386/darwin/md-os.c (md_replace_executionstate_read):
[cacao.git] / src / threads / threads-common.h
1 /* src/threads/threads-common.h - machine independent thread functions
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _THREADS_COMMON_H
27 #define _THREADS_COMMON_H
28
29 #include "config.h"
30 #include "vm/types.h"
31
32 #include "vm/global.h"
33
34 #include "native/llni.h"
35
36 #if defined(ENABLE_THREADS)
37 # include "threads/native/threads.h"
38 #else
39 # include "threads/none/threads.h"
40 #endif
41
42 #include "vmcore/utf8.h"
43
44
45 /* only define the following stuff with thread enabled ************************/
46
47 #if defined(ENABLE_THREADS)
48
49 /* thread states **************************************************************/
50
51 #define THREAD_STATE_NEW              0
52 #define THREAD_STATE_RUNNABLE         1
53 #define THREAD_STATE_BLOCKED          2
54 #define THREAD_STATE_WAITING          3
55 #define THREAD_STATE_TIMED_WAITING    4
56 #define THREAD_STATE_TERMINATED       5
57
58
59 /* thread priorities **********************************************************/
60
61 #define MIN_PRIORITY     1
62 #define NORM_PRIORITY    5
63 #define MAX_PRIORITY     10
64
65
66 /* debug **********************************************************************/
67
68 #if !defined(NDEBUG)
69 # define DEBUGTHREADS(message, thread) \
70         do { \
71                 if (opt_DebugThreads) { \
72                         printf("[Thread %-16s: ", message); \
73                         threads_thread_print_info(thread); \
74                         printf("]\n"); \
75                 } \
76         } while (0)
77 #else
78 # define DEBUGTHREADS(message, thread)
79 #endif
80
81
82 /* global variables ***********************************************************/
83
84 extern methodinfo *thread_method_init;
85
86 #if defined(__LINUX__)
87 /* XXX Remove for exact-GC. */
88 extern bool threads_pthreads_implementation_nptl;
89 #endif
90
91
92 /* inline functions ***********************************************************/
93
94 /* threads_thread_get_object ***************************************************
95
96    Return the java.lang.Thread object for the given thread.
97
98 *******************************************************************************/
99
100 static inline java_handle_t *threads_thread_get_object(threadobject *t)
101 {
102         return LLNI_WRAP(t->object);
103 }
104
105
106 /* threads_thread_set_object ***************************************************
107
108    Set the java.lang.Thread object for the given thread.
109
110 *******************************************************************************/
111
112 static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
113 {
114         t->object = LLNI_DIRECT(object);
115 }
116
117
118 /* threads_get_current_object **************************************************
119
120    Return the Java object of the current thread.
121    
122    RETURN VALUE:
123        the Java object
124
125 *******************************************************************************/
126
127 inline static java_handle_t *threads_get_current_object(void)
128 {
129         threadobject  *t;
130         java_handle_t *o;
131
132         t = THREADOBJECT;
133         o = threads_thread_get_object(t);
134
135         return o;
136 }
137
138
139 /* function prototypes ********************************************************/
140
141 void          threads_preinit(void);
142 void          threads_init(void);
143
144 threadobject *threads_thread_new(void);
145 void          threads_thread_free(threadobject *t);
146
147 bool          threads_thread_start_internal(utf *name, functionptr f);
148 void          threads_thread_start(java_handle_t *object);
149
150 void          threads_thread_print_info(threadobject *t);
151
152 ptrint        threads_get_current_tid(void);
153
154 void          threads_thread_state_runnable(threadobject *t);
155 void          threads_thread_state_waiting(threadobject *t);
156 void          threads_thread_state_timed_waiting(threadobject *t);
157 void          threads_thread_state_terminated(threadobject *t);
158 utf          *threads_thread_get_state(threadobject *t);
159
160 bool          threads_thread_is_alive(threadobject *t);
161
162 void          threads_dump(void);
163 void          threads_thread_print_stacktrace(threadobject *thread);
164 void          threads_print_stacktrace(void);
165
166
167 /* implementation specific functions */
168
169 void          threads_impl_preinit(void);
170 void          threads_impl_init(void);
171
172 #if defined(ENABLE_GC_CACAO)
173 void          threads_mutex_gc_lock(void);
174 void          threads_mutex_gc_unlock(void);
175 #endif
176
177 void          threads_mutex_join_lock(void);
178 void          threads_mutex_join_unlock(void);
179
180 void          threads_set_current_threadobject(threadobject *thread);
181 void          threads_impl_thread_init(threadobject *t);
182 void          threads_impl_thread_clear(threadobject *t);
183 void          threads_impl_thread_reuse(threadobject *t);
184 void          threads_impl_thread_free(threadobject *t);
185 void          threads_impl_thread_start(threadobject *thread, functionptr f);
186
187 void          threads_yield(void);
188
189 #endif /* ENABLE_THREADS */
190
191 #endif /* _THREADS_COMMON_H */
192
193
194 /*
195  * These are local overrides for various environment variables in Emacs.
196  * Please do not remove this and leave it at the end of the file, where
197  * Emacs will automagically detect them.
198  * ---------------------------------------------------------------------
199  * Local variables:
200  * mode: c
201  * indent-tabs-mode: t
202  * c-basic-offset: 4
203  * tab-width: 4
204  * End:
205  * vim:noexpandtab:sw=4:ts=4:
206  */