1 /* src/threads/native/threads.h - native threads header
3 Copyright (C) 1996-2005, 2006, 2007 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 $Id: threads.h 7761 2007-04-19 09:18:20Z twisti $
33 /* forward typedefs ***********************************************************/
35 typedef struct threadobject threadobject;
36 typedef union threads_table_entry_t threads_table_entry_t;
37 typedef struct threads_table_t threads_table_t;
47 #include "mm/memory.h"
48 #include "native/jni.h"
49 #include "native/include/java_lang_Thread.h"
51 #include "threads/native/lock.h"
53 #include "vm/global.h"
55 #include "vm/jit/stacktrace.h"
57 #if defined(ENABLE_INTRP)
58 #include "vm/jit/intrp/intrp.h"
61 #if defined(__DARWIN__)
62 # include <mach/mach.h>
65 pthread_mutex_t mutex;
71 # include <semaphore.h>
75 /* current threadobject *******************************************************/
77 #if defined(HAVE___THREAD)
79 #define THREADSPECIFIC __thread
80 #define THREADOBJECT threads_current_threadobject
82 extern __thread threadobject *threads_current_threadobject;
84 #else /* defined(HAVE___THREAD) */
86 #define THREADSPECIFIC
87 #define THREADOBJECT \
88 ((threadobject *) pthread_getspecific(threads_current_threadobject_key))
90 extern pthread_key_t threads_current_threadobject_key;
92 #endif /* defined(HAVE___THREAD) */
95 /* threads_table_entry_t *******************************************************
97 An entry in the global threads table.
99 *******************************************************************************/
101 union threads_table_entry_t {
102 threadobject *thread; /* an existing thread */
103 ptrint nextfree; /* next free index */
107 /* threads_table_t *************************************************************
109 Struct for the global threads table.
111 *******************************************************************************/
113 struct threads_table_t {
114 threads_table_entry_t *table; /* the table, threads[0] is the head */
115 /* of the free list. Real entries */
116 /* start at threads[1]. */
117 s4 size; /* current size of the table */
121 /* threadobject ****************************************************************
123 Struct holding thread local variables.
125 *******************************************************************************/
127 #define THREAD_FLAG_JAVA 0x01 /* a normal Java thread */
128 #define THREAD_FLAG_INTERNAL 0x02 /* CACAO internal thread */
129 #define THREAD_FLAG_DAEMON 0x04 /* daemon thread */
132 struct threadobject {
133 java_lang_Thread *object; /* link to java.lang.Thread object */
135 lock_execution_env_t ee; /* data for the lock implementation */
137 threadobject *next; /* next thread in list, or self */
138 threadobject *prev; /* prev thread in list, or self */
140 ptrint thinlock; /* pre-computed thin lock value */
142 s4 index; /* thread index, starting with 1 */
143 u4 flags; /* flag field */
144 u4 state; /* state field */
146 pthread_t tid; /* pthread id */
148 #if defined(__DARWIN__)
149 mach_port_t mach_thread; /* Darwin thread id */
152 /* these are used for the wait/notify implementation */
153 pthread_mutex_t waitmutex;
154 pthread_cond_t waitcond;
160 u1 *pc; /* current PC (used for profiling) */
162 java_objectheader *_exceptionptr; /* current exception */
163 stackframeinfo *_stackframeinfo; /* current native stackframeinfo */
164 localref_table *_localref_table; /* JNI local references */
166 #if defined(ENABLE_INTRP)
167 Cell *_global_sp; /* stack pointer for interpreter */
170 dumpinfo_t dumpinfo; /* dump memory info structure */
174 /* exception pointer **********************************************************/
176 #define exceptionptr (&(THREADOBJECT->_exceptionptr))
179 /* stackframeinfo *************************************************************/
181 #define STACKFRAMEINFO (THREADOBJECT->_stackframeinfo)
184 /* variables ******************************************************************/
186 extern threadobject *mainthreadobj;
189 /* functions ******************************************************************/
191 void threads_sem_init(sem_t *sem, bool shared, int value);
192 void threads_sem_wait(sem_t *sem);
193 void threads_sem_post(sem_t *sem);
195 threadobject *threads_get_current_threadobject(void);
197 void threads_preinit(void);
198 bool threads_init(void);
200 void threads_start_thread(threadobject *thread, functionptr function);
202 void threads_set_thread_priority(pthread_t tid, int priority);
204 bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
205 bool threads_detach_thread(threadobject *thread);
207 void threads_join_all_threads(void);
209 void threads_sleep(s8 millis, s4 nanos);
210 void threads_yield(void);
212 bool threads_wait_with_timeout_relative(threadobject *t, s8 millis, s4 nanos);
214 void threads_thread_interrupt(threadobject *thread);
215 bool threads_check_if_interrupted_and_reset(void);
216 bool threads_thread_has_been_interrupted(threadobject *thread);
218 void threads_cast_stopworld(void);
219 void threads_cast_startworld(void);
221 #endif /* _THREADS_H */
225 * These are local overrides for various environment variables in Emacs.
226 * Please do not remove this and leave it at the end of the file, where
227 * Emacs will automagically detect them.
228 * ---------------------------------------------------------------------
231 * indent-tabs-mode: t
235 * vim:noexpandtab:sw=4:ts=4: