1 /* threads/native/threads.h - native threads header
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
29 $Id: threads.h 1923 2005-02-10 10:43:41Z twisti $
38 #include <semaphore.h>
40 #include "mm/memory.h"
41 #include "native/jni.h"
42 #include "native/include/java_lang_Object.h" /* required by java/lang/VMThread*/
43 #include "native/include/java_lang_Thread.h"
44 #include "native/include/java_lang_VMThread.h"
46 #if defined(__DARWIN__)
47 #include <mach/mach.h>
49 /* We need to emulate recursive mutexes. */
54 #if defined(HAVE___THREAD)
56 #define THREADSPECIFIC __thread
57 #define THREADOBJECT ((java_lang_VMThread*) threadobj)
58 #define THREADINFO (&threadobj->info)
60 extern __thread threadobject *threadobj;
62 #else /* defined(HAVE___THREAD) */
64 #define THREADSPECIFIC
65 #define THREADOBJECT ((java_lang_VMThread*) pthread_getspecific(tkey_threadinfo))
66 #define THREADINFO (&((threadobject*) pthread_getspecific(tkey_threadinfo))->info)
68 extern pthread_key_t tkey_threadinfo;
70 #endif /* defined(HAVE___THREAD) */
73 /* typedefs *******************************************************************/
75 typedef struct ExecEnvironment ExecEnvironment;
76 typedef struct nativethread nativethread;
77 typedef struct threadobject threadobject;
78 typedef struct monitorLockRecord monitorLockRecord;
79 typedef struct lockRecordPoolHeader lockRecordPoolHeader;
80 typedef struct lockRecordPool lockRecordPool;
81 typedef java_lang_Thread thread;
84 /* ExecEnvironment *************************************************************
86 Monitor lock implementation
88 *******************************************************************************/
90 struct ExecEnvironment {
91 monitorLockRecord *firstLR;
92 lockRecordPool *lrpool;
100 java_objectheader *_exceptionptr;
101 methodinfo *_threadrootmethod;
102 void *_stackframeinfo;
104 #if defined(__DARWIN__)
105 mach_port_t mach_thread;
107 pthread_mutex_t joinMutex;
108 pthread_cond_t joinCond;
112 /* threadobject ****************************************************************
116 *******************************************************************************/
118 struct threadobject {
119 java_lang_VMThread o;
123 pthread_mutex_t waitLock;
124 pthread_cond_t waitCond;
129 dumpinfo dumpinfo; /* dump memory info structure */
133 struct monitorLockRecord {
134 threadobject *ownerThread;
135 java_objectheader *o;
137 monitorLockRecord *nextFree;
139 monitorLockRecord *waiter;
140 monitorLockRecord *incharge;
143 pthread_mutex_t resolveLock;
144 pthread_cond_t resolveWait;
149 struct lockRecordPoolHeader {
150 lockRecordPool *next;
154 struct lockRecordPool {
155 lockRecordPoolHeader header;
156 monitorLockRecord lr[1];
160 monitorLockRecord *monitorEnter(threadobject *, java_objectheader *);
161 bool monitorExit(threadobject *, java_objectheader *);
163 bool threadHoldsLock(threadobject *t, java_objectheader *o);
164 void signal_cond_for_object (java_objectheader *obj);
165 void broadcast_cond_for_object (java_objectheader *obj);
166 void wait_cond_for_object (java_objectheader *obj, s8 time, s4 nanos);
168 void initThreadsEarly();
169 void initThreads(u1 *stackbottom);
170 void initObjectLock(java_objectheader *);
172 void initThread(java_lang_VMThread *);
173 void startThread(thread *t);
174 void joinAllThreads();
176 void sleepThread(s8 millis, s4 nanos);
179 void setPriorityThread(thread *t, s4 priority);
181 void interruptThread(java_lang_VMThread *);
182 bool interruptedThread();
183 bool isInterruptedThread(java_lang_VMThread *);
185 /* This must not be changed, it is used in asm_criticalsections */
192 void thread_registercritical(threadcritnode *);
193 u1 *thread_checkcritical(u1*);
195 extern volatile int stopworldwhere;
197 void cast_stopworld();
198 void cast_startworld();
200 #endif /* _THREADS_H */
204 * These are local overrides for various environment variables in Emacs.
205 * Please do not remove this and leave it at the end of the file, where
206 * Emacs will automagically detect them.
207 * ---------------------------------------------------------------------
210 * indent-tabs-mode: t