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 6251 2006-12-27 23:15:56Z 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 */
140 #define THREAD_FLAG_DAEMON 0x04 /* daemon thread */
143 struct threadobject {
144 java_lang_Thread o; /* the java.lang.Thread object */
146 lock_execution_env_t ee; /* data for the lock implementation */
148 threadobject *next; /* next thread in list, or self */
149 threadobject *prev; /* prev thread in list, or self */
151 ptrint thinlock; /* pre-computed thin lock value */
153 s4 index; /* thread index, starting with 1 */
154 u4 flags; /* flag field */
156 pthread_t tid; /* pthread id */
158 #if defined(__DARWIN__)
159 mach_port_t mach_thread; /* Darwin thread id */
162 pthread_mutex_t joinmutex;
163 pthread_cond_t joincond;
165 /* these are used for the wait/notify implementation */
166 pthread_mutex_t waitmutex;
167 pthread_cond_t waitcond;
173 u1 *pc; /* current PC (used for profiling) */
175 java_objectheader *_exceptionptr; /* current exception */
176 stackframeinfo *_stackframeinfo; /* current native stackframeinfo */
177 localref_table *_localref_table; /* JNI local references */
179 #if defined(ENABLE_INTRP)
180 Cell *_global_sp; /* stack pointer for interpreter */
183 dumpinfo_t dumpinfo; /* dump memory info structure */
187 /* variables ******************************************************************/
189 extern threadobject *mainthreadobj;
192 /* functions ******************************************************************/
194 void threads_sem_init(sem_t *sem, bool shared, int value);
195 void threads_sem_wait(sem_t *sem);
196 void threads_sem_post(sem_t *sem);
198 threadobject *threads_get_current_threadobject(void);
200 void threads_preinit(void);
201 bool threads_init(void);
203 void threads_start_thread(threadobject *thread, functionptr function);
205 void threads_set_thread_priority(pthread_t tid, int priority);
207 bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
208 bool threads_detach_thread(threadobject *thread);
210 void threads_join_all_threads(void);
212 void threads_sleep(s8 millis, s4 nanos);
213 void threads_yield(void);
215 bool threads_wait_with_timeout_relative(threadobject *t, s8 millis, s4 nanos);
217 void threads_thread_interrupt(threadobject *thread);
218 bool threads_check_if_interrupted_and_reset(void);
219 bool threads_thread_has_been_interrupted(threadobject *thread);
221 void threads_cast_stopworld(void);
222 void threads_cast_startworld(void);
224 void threads_dump(void);
226 #endif /* _THREADS_H */
230 * These are local overrides for various environment variables in Emacs.
231 * Please do not remove this and leave it at the end of the file, where
232 * Emacs will automagically detect them.
233 * ---------------------------------------------------------------------
236 * indent-tabs-mode: t
240 * vim:noexpandtab:sw=4:ts=4: