1 /* src/threads/threads-common.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/threads.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 extern methodinfo *thread_method_init;
88 #if defined(__LINUX__)
89 /* XXX Remove for exact-GC. */
90 extern bool threads_pthreads_implementation_nptl;
94 /* inline functions ***********************************************************/
96 /* threads_thread_get_object ***************************************************
98 Return the java.lang.Thread object for the given thread.
100 *******************************************************************************/
102 static inline java_handle_t *threads_thread_get_object(threadobject *t)
104 return LLNI_WRAP(t->object);
108 /* threads_thread_set_object ***************************************************
110 Set the java.lang.Thread object for the given thread.
112 *******************************************************************************/
114 static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
116 t->object = LLNI_DIRECT(object);
120 /* threads_get_current_object **************************************************
122 Return the Java object of the current thread.
127 *******************************************************************************/
129 inline static java_handle_t *threads_get_current_object(void)
135 o = threads_thread_get_object(t);
140 /* thread_is_attached **********************************************************
142 Returns if the given thread is attached to the VM.
145 true .... the thread is attached to the VM
146 false ... the thread is not
148 *******************************************************************************/
150 inline static bool thread_is_attached(threadobject *t)
154 o = threads_thread_get_object(t);
163 /* thread_current_is_attached **************************************************
165 Returns if the current thread is attached to the VM.
168 true .... the thread is attached to the VM
169 false ... the thread is not
171 *******************************************************************************/
173 inline static bool thread_current_is_attached(void)
179 result = thread_is_attached(t);
185 /* function prototypes ********************************************************/
187 void threads_preinit(void);
188 void threads_init(void);
190 threadobject *threads_thread_new(void);
191 void threads_thread_free(threadobject *t);
193 bool threads_thread_start_internal(utf *name, functionptr f);
194 void threads_thread_start(java_handle_t *object);
196 bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
198 void threads_thread_print_info(threadobject *t);
200 intptr_t threads_get_current_tid(void);
202 void threads_thread_state_runnable(threadobject *t);
203 void threads_thread_state_waiting(threadobject *t);
204 void threads_thread_state_timed_waiting(threadobject *t);
205 void threads_thread_state_terminated(threadobject *t);
207 utf *threads_thread_get_state(threadobject *t);
208 threadobject *thread_get_thread(java_handle_t *h);
210 bool threads_thread_is_alive(threadobject *t);
212 void threads_dump(void);
213 void threads_thread_print_stacktrace(threadobject *thread);
214 void threads_print_stacktrace(void);
217 /* implementation specific functions */
219 void threads_impl_preinit(void);
220 void threads_impl_init(void);
222 #if defined(ENABLE_GC_CACAO)
223 void threads_mutex_gc_lock(void);
224 void threads_mutex_gc_unlock(void);
227 void threads_mutex_join_lock(void);
228 void threads_mutex_join_unlock(void);
230 void threads_impl_thread_init(threadobject *t);
231 void threads_impl_thread_clear(threadobject *t);
232 void threads_impl_thread_reuse(threadobject *t);
233 void threads_impl_thread_free(threadobject *t);
234 void threads_impl_thread_start(threadobject *thread, functionptr f);
236 void threads_yield(void);
238 #endif /* ENABLE_THREADS */
240 #endif /* _THREADS_COMMON_H */
244 * These are local overrides for various environment variables in Emacs.
245 * Please do not remove this and leave it at the end of the file, where
246 * Emacs will automagically detect them.
247 * ---------------------------------------------------------------------
250 * indent-tabs-mode: t
254 * vim:noexpandtab:sw=4:ts=4: