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 #if defined(ENABLE_THREADS)
32 # include "threads/posix/thread-posix.h"
34 # include "threads/none/threads.h"
39 #include "vm/global.h"
41 #include "native/jni.h"
42 #include "native/llni.h"
44 #include "vmcore/utf8.h"
47 /* only define the following stuff with thread enabled ************************/
49 #if defined(ENABLE_THREADS)
51 /* thread states **************************************************************/
53 #define THREAD_STATE_NEW 0
54 #define THREAD_STATE_RUNNABLE 1
55 #define THREAD_STATE_BLOCKED 2
56 #define THREAD_STATE_WAITING 3
57 #define THREAD_STATE_TIMED_WAITING 4
58 #define THREAD_STATE_TERMINATED 5
61 /* thread priorities **********************************************************/
63 #define MIN_PRIORITY 1
64 #define NORM_PRIORITY 5
65 #define MAX_PRIORITY 10
68 /* debug **********************************************************************/
71 # define DEBUGTHREADS(message, thread) \
73 if (opt_DebugThreads) { \
74 printf("[Thread %-16s: ", message); \
75 threads_thread_print_info(thread); \
80 # define DEBUGTHREADS(message, thread)
84 /* global variables ***********************************************************/
86 #if defined(__LINUX__)
87 /* XXX Remove for exact-GC. */
88 extern bool threads_pthreads_implementation_nptl;
92 /* inline functions ***********************************************************/
94 /* threads_thread_get_object ***************************************************
96 Return the java.lang.Thread object for the given thread.
98 *******************************************************************************/
100 static inline java_handle_t *threads_thread_get_object(threadobject *t)
102 return LLNI_WRAP(t->object);
106 /* threads_thread_set_object ***************************************************
108 Set the java.lang.Thread object for the given thread.
110 *******************************************************************************/
112 static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
114 t->object = LLNI_DIRECT(object);
118 /* threads_get_current_object **************************************************
120 Return the Java object of the current thread.
125 *******************************************************************************/
127 inline static java_handle_t *threads_get_current_object(void)
133 o = threads_thread_get_object(t);
139 /* thread_is_attached **********************************************************
141 Returns if the given thread is attached to the VM.
144 true .... the thread is attached to the VM
145 false ... the thread is not
147 *******************************************************************************/
149 inline static bool thread_is_attached(threadobject *t)
153 o = threads_thread_get_object(t);
162 /* thread_is_daemon ************************************************************
164 Returns if the given thread is a daemon thread.
167 true .... the thread is a daemon thread
168 false ... the thread is not
170 *******************************************************************************/
172 inline static bool thread_is_daemon(threadobject *t)
174 if (t->flags & THREAD_FLAG_DAEMON)
181 /* thread_current_is_attached **************************************************
183 Returns if the current thread is attached to the VM.
186 true .... the thread is attached to the VM
187 false ... the thread is not
189 *******************************************************************************/
191 inline static bool thread_current_is_attached(void)
197 result = thread_is_attached(t);
203 /* function prototypes ********************************************************/
205 void threads_preinit(void);
206 void threads_init(void);
208 void thread_free(threadobject *t);
210 bool threads_thread_start_internal(utf *name, functionptr f);
211 void threads_thread_start(java_handle_t *object);
213 bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
215 void threads_thread_print_info(threadobject *t);
217 intptr_t threads_get_current_tid(void);
219 void threads_thread_state_runnable(threadobject *t);
220 void threads_thread_state_waiting(threadobject *t);
221 void threads_thread_state_timed_waiting(threadobject *t);
222 void threads_thread_state_terminated(threadobject *t);
224 utf *threads_thread_get_state(threadobject *t);
225 threadobject *thread_get_thread(java_handle_t *h);
227 bool threads_thread_is_alive(threadobject *t);
229 void threads_dump(void);
230 void threads_thread_print_stacktrace(threadobject *thread);
231 void threads_print_stacktrace(void);
234 /* implementation specific functions */
236 void threads_impl_preinit(void);
237 void threads_impl_init(void);
239 #if defined(ENABLE_GC_CACAO)
240 void threads_mutex_gc_lock(void);
241 void threads_mutex_gc_unlock(void);
244 void threads_mutex_join_lock(void);
245 void threads_mutex_join_unlock(void);
247 void threads_impl_thread_init(threadobject *t);
248 void threads_impl_thread_clear(threadobject *t);
249 void threads_impl_thread_reuse(threadobject *t);
250 void threads_impl_thread_free(threadobject *t);
251 void threads_impl_thread_start(threadobject *thread, functionptr f);
253 void threads_yield(void);
255 #endif /* ENABLE_THREADS */
257 #endif /* _THREADS_COMMON_H */
261 * These are local overrides for various environment variables in Emacs.
262 * Please do not remove this and leave it at the end of the file, where
263 * Emacs will automagically detect them.
264 * ---------------------------------------------------------------------
267 * indent-tabs-mode: t
271 * vim:noexpandtab:sw=4:ts=4: