1 /* src/threads/native/threads.h - native threads header
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
31 $Id: threads.h 6228 2006-12-26 19:56:58Z twisti $
39 /* forward typedefs ***********************************************************/
41 typedef struct threadobject threadobject;
42 typedef union threads_table_entry_t threads_table_entry_t;
43 typedef struct threads_table_t threads_table_t;
53 #include "mm/memory.h"
54 #include "native/jni.h"
55 #include "native/include/java_lang_Thread.h"
56 #include "vm/global.h"
58 #include "threads/native/lock.h"
60 #if defined(ENABLE_INTRP)
61 #include "vm/jit/intrp/intrp.h"
64 #if defined(__DARWIN__)
65 # include <mach/mach.h>
68 pthread_mutex_t mutex;
74 # include <semaphore.h>
78 /* thread priorities **********************************************************/
80 #define MIN_PRIORITY 1
81 #define NORM_PRIORITY 5
82 #define MAX_PRIORITY 10
85 /* current threadobject *******************************************************/
87 #if defined(HAVE___THREAD)
89 #define THREADSPECIFIC __thread
90 #define THREADOBJECT threads_current_threadobject
92 extern __thread threadobject *threads_current_threadobject;
94 #else /* defined(HAVE___THREAD) */
96 #define THREADSPECIFIC
97 #define THREADOBJECT \
98 ((threadobject *) pthread_getspecific(threads_current_threadobject_key))
100 extern pthread_key_t threads_current_threadobject_key;
102 #endif /* defined(HAVE___THREAD) */
105 /* threads_table_entry_t *******************************************************
107 An entry in the global threads table.
109 *******************************************************************************/
111 union threads_table_entry_t {
112 threadobject *thread; /* an existing thread */
113 ptrint nextfree; /* next free index */
117 /* threads_table_t *************************************************************
119 Struct for the global threads table.
121 *******************************************************************************/
123 struct threads_table_t {
124 threads_table_entry_t *table; /* the table, threads[0] is the head */
125 /* of the free list. Real entries */
126 /* start at threads[1]. */
127 s4 size; /* current size of the table */
131 /* threadobject ****************************************************************
133 Every java.lang.Thread object is actually an instance of this
136 *******************************************************************************/
138 #define THREAD_FLAG_JAVA 0x01 /* a normal Java thread */
139 #define THREAD_FLAG_INTERNAL 0x02 /* CACAO internal thread */
142 struct threadobject {
143 java_lang_Thread o; /* the java.lang.Thread object */
145 lock_execution_env_t ee; /* data for the lock implementation */
147 threadobject *next; /* next thread in list, or self */
148 threadobject *prev; /* prev thread in list, or self */
150 ptrint thinlock; /* pre-computed thin lock value */
152 s4 index; /* thread index, starting with 1 */
153 u1 flags; /* flag field */
155 pthread_t tid; /* pthread id */
157 #if defined(__DARWIN__)
158 mach_port_t mach_thread; /* Darwin thread id */
161 pthread_mutex_t joinmutex;
162 pthread_cond_t joincond;
164 /* these are used for the wait/notify implementation */
165 pthread_mutex_t waitmutex;
166 pthread_cond_t waitcond;
172 u1 *pc; /* current PC (used for profiling) */
174 java_objectheader *_exceptionptr; /* current exception */
175 stackframeinfo *_stackframeinfo; /* current native stackframeinfo */
176 localref_table *_localref_table; /* JNI local references */
178 #if defined(ENABLE_INTRP)
179 Cell *_global_sp; /* stack pointer for interpreter */
182 dumpinfo_t dumpinfo; /* dump memory info structure */
186 /* variables ******************************************************************/
188 extern threadobject *mainthreadobj;
191 /* functions ******************************************************************/
193 void threads_sem_init(sem_t *sem, bool shared, int value);
194 void threads_sem_wait(sem_t *sem);
195 void threads_sem_post(sem_t *sem);
197 threadobject *threads_get_current_threadobject(void);
199 void threads_preinit(void);
200 bool threads_init(void);
202 void threads_start_thread(threadobject *thread, functionptr function);
204 void threads_set_thread_priority(pthread_t tid, int priority);
206 bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
207 bool threads_detach_thread(threadobject *thread);
209 void threads_join_all_threads(void);
211 void threads_sleep(s8 millis, s4 nanos);
212 void threads_yield(void);
214 bool threads_wait_with_timeout_relative(threadobject *t, s8 millis, s4 nanos);
216 void threads_thread_interrupt(threadobject *thread);
217 bool threads_check_if_interrupted_and_reset(void);
218 bool threads_thread_has_been_interrupted(threadobject *thread);
220 void threads_cast_stopworld(void);
221 void threads_cast_startworld(void);
223 void threads_dump(void);
225 #endif /* _THREADS_H */
229 * These are local overrides for various environment variables in Emacs.
230 * Please do not remove this and leave it at the end of the file, where
231 * Emacs will automagically detect them.
232 * ---------------------------------------------------------------------
235 * indent-tabs-mode: t
239 * vim:noexpandtab:sw=4:ts=4: