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
30 Changes: Christian Thalinger
32 $Id: threads.h 4944 2006-05-23 15:31:19Z motse $
50 #include "mm/memory.h"
51 #include "native/jni.h"
52 #include "native/include/java_lang_Object.h" /* required by java/lang/VMThread*/
53 #include "native/include/java_lang_Thread.h"
54 #include "native/include/java_lang_VMThread.h"
55 #include "vm/global.h"
57 #include "threads/native/lock.h"
59 #if defined(__DARWIN__)
60 # include <mach/mach.h>
62 /* We need to emulate recursive mutexes. */
66 pthread_mutex_t mutex;
72 # include <semaphore.h>
76 /* forward typedefs ***********************************************************/
78 typedef struct threadobject threadobject;
79 typedef union threads_table_entry_t threads_table_entry_t;
80 typedef struct threads_table_t threads_table_t;
83 /* current threadobject *******************************************************/
85 #if defined(HAVE___THREAD)
87 #define THREADSPECIFIC __thread
88 #define THREADOBJECT threads_current_threadobject
90 extern __thread threadobject *threads_current_threadobject;
92 #else /* defined(HAVE___THREAD) */
94 #define THREADSPECIFIC
95 #define THREADOBJECT \
96 ((threadobject *)pthread_getspecific(threads_current_threadobject_key))
98 extern pthread_key_t threads_current_threadobject_key;
100 #endif /* defined(HAVE___THREAD) */
103 /* threads_table_entry_t *******************************************************
105 An entry in the global threads table.
107 *******************************************************************************/
109 union threads_table_entry_t {
110 threadobject *thread; /* an existing thread */
111 ptrint nextfree; /* next free index */
115 /* threads_table_t *************************************************************
117 Struct for the global threads table.
119 *******************************************************************************/
121 struct threads_table_t {
122 threads_table_entry_t *table; /* the table, threads[0] is the head */
123 /* of the free list. Real entries */
124 /* start at threads[1]. */
125 s4 size; /* current size of the table */
129 /* threadobject ****************************************************************
131 Every java.lang.VMThread object is actually an instance of this
134 *******************************************************************************/
136 struct threadobject {
137 java_lang_VMThread o; /* the java.lang.VMThread object */
139 lock_execution_env_t ee; /* data for the lock implementation */
141 threadobject *next; /* next thread in list, or self */
142 threadobject *prev; /* prev thread in list, or self */
144 ptrint thinlock; /* pre-computed thin lock value */
146 s4 index; /* thread index, startin with 1 */
148 pthread_t tid; /* pthread id */
150 #if defined(__DARWIN__)
151 mach_port_t mach_thread; /* Darwin thread id */
154 pthread_mutex_t joinmutex;
155 pthread_cond_t joincond;
157 /* these are used for the wait/notify implementation */
158 pthread_mutex_t waitmutex;
159 pthread_cond_t waitcond;
165 java_objectheader *_exceptionptr; /* current exception */
166 stackframeinfo *_stackframeinfo; /* current native stackframeinfo */
167 localref_table *_localref_table; /* JNI local references */
169 #if defined(ENABLE_INTRP)
170 void *_global_sp; /* stack pointer for interpreter */
173 dumpinfo dumpinfo; /* dump memory info structure */
177 /* variables ******************************************************************/
179 extern threadobject *mainthreadobj;
182 /* functions ******************************************************************/
184 void threads_sem_init(sem_t *sem, bool shared, int value);
185 void threads_sem_wait(sem_t *sem);
186 void threads_sem_post(sem_t *sem);
188 threadobject *threads_get_current_threadobject(void);
190 void threads_preinit(void);
191 bool threads_init(void);
193 void threads_init_threadobject(java_lang_VMThread *);
195 void threads_start_thread(java_lang_Thread *t, functionptr function);
197 void threads_join_all_threads(void);
199 void threads_sleep(s8 millis, s4 nanos);
200 void threads_yield(void);
202 bool threads_wait_with_timeout_relative(threadobject *t, s8 millis, s4 nanos);
204 void threads_interrupt_thread(java_lang_VMThread *);
205 bool threads_check_if_interrupted_and_reset(void);
206 bool threads_thread_has_been_interrupted(java_lang_VMThread *);
208 void threads_java_lang_Thread_set_priority(java_lang_Thread *t, s4 priority);
210 void threads_cast_stopworld(void);
211 void threads_cast_startworld(void);
213 void threads_dump(void);
215 #if defined(ENABLE_JVMTI)
216 void jvmti_get_threads_breakpoints(void **brks);
218 /******************************************************************************/
219 /* Recursive Mutex Implementation for Darwin */
220 /******************************************************************************/
222 #if defined(MUTEXSIM)
224 /* We need this for older MacOSX (10.1.x) */
227 pthread_mutex_t mutex;
230 } pthread_mutex_rec_t;
232 void pthread_mutex_init_rec(pthread_mutex_rec_t *m);
233 void pthread_mutex_destroy_rec(pthread_mutex_rec_t *m);
234 void pthread_mutex_lock_rec(pthread_mutex_rec_t *m);
235 void pthread_mutex_unlock_rec(pthread_mutex_rec_t *m);
237 #else /* !defined(MUTEXSIM) */
239 #define pthread_mutex_lock_rec pthread_mutex_lock
240 #define pthread_mutex_unlock_rec pthread_mutex_unlock
241 #define pthread_mutex_rec_t pthread_mutex_t
243 #endif /* defined(MUTEXSIM) */
245 #endif /* _THREADS_H */
249 * These are local overrides for various environment variables in Emacs.
250 * Please do not remove this and leave it at the end of the file, where
251 * Emacs will automagically detect them.
252 * ---------------------------------------------------------------------
255 * indent-tabs-mode: t
259 * vim:noexpandtab:sw=4:ts=4: