1 /* src/threads/thread.h - machine independent thread functions
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
26 #ifndef _THREADS_COMMON_H
27 #define _THREADS_COMMON_H
31 #include "vmcore/system.h"
33 #if defined(ENABLE_THREADS)
34 # include "threads/posix/thread-posix.h"
36 # include "threads/none/threads.h"
41 #include "vm/global.h"
43 #include "native/jni.h"
44 #include "native/llni.h"
46 #include "vmcore/utf8.h"
49 /* only define the following stuff with thread enabled ************************/
51 #if defined(ENABLE_THREADS)
53 /* thread states **************************************************************/
55 #define THREAD_STATE_NEW 0
56 #define THREAD_STATE_RUNNABLE 1
57 #define THREAD_STATE_BLOCKED 2
58 #define THREAD_STATE_WAITING 3
59 #define THREAD_STATE_TIMED_WAITING 4
60 #define THREAD_STATE_TERMINATED 5
63 /* thread priorities **********************************************************/
65 #define MIN_PRIORITY 1
66 #define NORM_PRIORITY 5
67 #define MAX_PRIORITY 10
70 /* debug **********************************************************************/
73 # define DEBUGTHREADS(message, thread) \
75 if (opt_DebugThreads) { \
76 printf("[Thread %-16s: ", message); \
77 threads_thread_print_info(thread); \
82 # define DEBUGTHREADS(message, thread)
86 /* global variables ***********************************************************/
88 #if defined(__LINUX__)
89 /* XXX Remove for exact-GC. */
90 extern bool threads_pthreads_implementation_nptl;
94 /* inline functions ***********************************************************/
96 /* thread_get_object ***********************************************************
98 Return the Java for the given thread.
106 *******************************************************************************/
108 inline static java_handle_t *thread_get_object(threadobject *t)
110 return LLNI_WRAP(t->object);
114 /* threads_thread_set_object ***************************************************
116 Set the Java object for the given thread.
122 *******************************************************************************/
124 inline static void thread_set_object(threadobject *t, java_handle_t *o)
126 t->object = LLNI_DIRECT(o);
130 /* thread_get_current_object **************************************************
132 Return the Java object of the current thread.
137 *******************************************************************************/
139 inline static java_handle_t *thread_get_current_object(void)
145 o = thread_get_object(t);
151 /* thread_is_attached **********************************************************
153 Returns if the given thread is attached to the VM.
156 true .... the thread is attached to the VM
157 false ... the thread is not
159 *******************************************************************************/
161 inline static bool thread_is_attached(threadobject *t)
165 o = thread_get_object(t);
174 /* thread_is_daemon ************************************************************
176 Returns if the given thread is a daemon thread.
179 true .... the thread is a daemon thread
180 false ... the thread is not
182 *******************************************************************************/
184 inline static bool thread_is_daemon(threadobject *t)
186 if (t->flags & THREAD_FLAG_DAEMON)
193 /* thread_current_is_attached **************************************************
195 Returns if the current thread is attached to the VM.
198 true .... the thread is attached to the VM
199 false ... the thread is not
201 *******************************************************************************/
203 inline static bool thread_current_is_attached(void)
209 result = thread_is_attached(t);
215 /* function prototypes ********************************************************/
217 void threads_preinit(void);
218 void threads_init(void);
220 void thread_free(threadobject *t);
222 bool threads_thread_start_internal(utf *name, functionptr f);
223 void threads_thread_start(java_handle_t *object);
225 bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
227 void thread_fprint_name(threadobject *t, FILE *stream);
228 void threads_thread_print_info(threadobject *t);
230 intptr_t threads_get_current_tid(void);
232 void threads_thread_state_runnable(threadobject *t);
233 void threads_thread_state_waiting(threadobject *t);
234 void threads_thread_state_timed_waiting(threadobject *t);
235 void threads_thread_state_terminated(threadobject *t);
237 utf *threads_thread_get_state(threadobject *t);
238 threadobject *thread_get_thread(java_handle_t *h);
240 bool threads_thread_is_alive(threadobject *t);
242 void threads_dump(void);
243 void threads_thread_print_stacktrace(threadobject *thread);
244 void threads_print_stacktrace(void);
247 /* implementation specific functions */
249 void threads_impl_preinit(void);
250 void threads_impl_init(void);
252 #if defined(ENABLE_GC_CACAO)
253 void threads_mutex_gc_lock(void);
254 void threads_mutex_gc_unlock(void);
257 void threads_mutex_join_lock(void);
258 void threads_mutex_join_unlock(void);
260 void threads_impl_thread_init(threadobject *t);
261 void threads_impl_thread_clear(threadobject *t);
262 void threads_impl_thread_reuse(threadobject *t);
263 void threads_impl_thread_free(threadobject *t);
264 void threads_impl_thread_start(threadobject *thread, functionptr f);
266 void threads_yield(void);
268 #endif /* ENABLE_THREADS */
270 #endif /* _THREADS_COMMON_H */
274 * These are local overrides for various environment variables in Emacs.
275 * Please do not remove this and leave it at the end of the file, where
276 * Emacs will automagically detect them.
277 * ---------------------------------------------------------------------
280 * indent-tabs-mode: t
284 * vim:noexpandtab:sw=4:ts=4: