1 /* src/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 Changes: Christian Thalinger
31 $Id: threads.h 3087 2005-07-20 19:16:17Z motse $
40 #include <semaphore.h>
42 #include "mm/memory.h"
43 #include "native/jni.h"
44 #include "native/include/java_lang_Object.h" /* required by java/lang/VMThread*/
45 #include "native/include/java_lang_Thread.h"
46 #include "native/include/java_lang_VMThread.h"
48 #if defined(__DARWIN__)
49 #include <mach/mach.h>
51 /* We need to emulate recursive mutexes. */
56 #if defined(HAVE___THREAD)
58 #define THREADSPECIFIC __thread
59 #define THREADOBJECT ((java_lang_VMThread*) threadobj)
60 #define THREADINFO (&threadobj->info)
62 extern __thread threadobject *threadobj;
64 #else /* defined(HAVE___THREAD) */
66 #define THREADSPECIFIC
67 #define THREADOBJECT ((java_lang_VMThread*) pthread_getspecific(tkey_threadinfo))
68 #define THREADINFO (&((threadobject*) pthread_getspecific(tkey_threadinfo))->info)
70 extern pthread_key_t tkey_threadinfo;
72 #endif /* defined(HAVE___THREAD) */
75 /* typedefs *******************************************************************/
77 typedef struct ExecEnvironment ExecEnvironment;
78 typedef struct nativethread nativethread;
79 typedef struct threadobject threadobject;
80 typedef struct monitorLockRecord monitorLockRecord;
81 typedef struct lockRecordPoolHeader lockRecordPoolHeader;
82 typedef struct lockRecordPool lockRecordPool;
83 typedef java_lang_Thread thread;
86 /* ExecEnvironment *************************************************************
88 Monitor lock implementation
90 *******************************************************************************/
92 struct ExecEnvironment {
93 monitorLockRecord *firstLR;
94 lockRecordPool *lrpool;
102 java_objectheader *_exceptionptr;
103 u1 _dontfillinexceptionstacktrace;
104 methodinfo *_threadrootmethod;
105 void *_stackframeinfo;
107 #if defined(__DARWIN__)
108 mach_port_t mach_thread;
110 pthread_mutex_t joinMutex;
111 pthread_cond_t joinCond;
115 /* threadobject ****************************************************************
117 Every java.lang.VMThread object is actually an instance of this structure.
119 *******************************************************************************/
121 struct threadobject {
122 java_lang_VMThread o;
123 nativethread info; /* some general pthreads stuff */
124 ExecEnvironment ee; /* contains our lock record pool */
126 /* these are used for the wait/notify implementation */
127 pthread_mutex_t waitLock;
128 pthread_cond_t waitCond;
133 dumpinfo dumpinfo; /* dump memory info structure */
136 /* monitorLockRecord ***********************************************************
138 This is the really interesting stuff.
139 See handbook for a detailed description.
141 *******************************************************************************/
143 struct monitorLockRecord {
144 threadobject *ownerThread;
145 java_objectheader *o;
147 monitorLockRecord *nextFree;
149 monitorLockRecord *waiter;
150 monitorLockRecord *incharge;
153 pthread_mutex_t resolveLock;
154 pthread_cond_t resolveWait;
158 struct lockRecordPoolHeader {
159 lockRecordPool *next;
163 struct lockRecordPool {
164 lockRecordPoolHeader header;
165 monitorLockRecord lr[1];
169 monitorLockRecord *monitorEnter(threadobject *, java_objectheader *);
170 bool monitorExit(threadobject *, java_objectheader *);
172 bool threadHoldsLock(threadobject *t, java_objectheader *o);
173 void signal_cond_for_object (java_objectheader *obj);
174 void broadcast_cond_for_object (java_objectheader *obj);
175 void wait_cond_for_object (java_objectheader *obj, s8 time, s4 nanos);
177 void *thread_getself(void);
179 void initThreadsEarly();
180 void initThreads(u1 *stackbottom);
181 void initObjectLock(java_objectheader *);
182 monitorLockRecord *get_dummyLR(void);
184 void initThread(java_lang_VMThread *);
185 void startThread(thread *t);
186 void joinAllThreads();
188 void sleepThread(s8 millis, s4 nanos);
191 void setPriorityThread(thread *t, s4 priority);
193 void interruptThread(java_lang_VMThread *);
194 bool interruptedThread();
195 bool isInterruptedThread(java_lang_VMThread *);
197 /* This must not be changed, it is used in asm_criticalsections */
204 void thread_registercritical(threadcritnode *);
205 u1 *thread_checkcritical(u1*);
207 extern volatile int stopworldwhere;
208 static threadobject *mainthreadobj;
211 void cast_stopworld();
212 void cast_startworld();
214 /* dumps all threads */
215 void thread_dump(void);
217 #endif /* _THREADS_H */
221 * These are local overrides for various environment variables in Emacs.
222 * Please do not remove this and leave it at the end of the file, where
223 * Emacs will automagically detect them.
224 * ---------------------------------------------------------------------
227 * indent-tabs-mode: t