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
29 Changes: Christian Thalinger
32 $Id: threads.h 4908 2006-05-12 16:49:50Z edwin $
43 #include <semaphore.h>
51 #include "mm/memory.h"
52 #include "native/jni.h"
53 #include "native/include/java_lang_Object.h" /* required by java/lang/VMThread*/
54 #include "native/include/java_lang_Thread.h"
55 #include "native/include/java_lang_VMThread.h"
56 #include "vm/global.h"
58 #include "threads/native/lock.h"
60 #if defined(__DARWIN__)
61 #include <mach/mach.h>
63 /* We need to emulate recursive mutexes. */
68 #if defined(HAVE___THREAD)
70 #define THREADSPECIFIC __thread
71 #define THREADOBJECT threadobj
72 #define THREADINFO (&threadobj->info)
74 extern __thread threadobject *threadobj;
76 #else /* defined(HAVE___THREAD) */
78 #define THREADSPECIFIC
79 #define THREADOBJECT pthread_getspecific(tkey_threadinfo)
80 #define THREADINFO (&((threadobject*) pthread_getspecific(tkey_threadinfo))->info)
82 extern pthread_key_t tkey_threadinfo;
84 #endif /* defined(HAVE___THREAD) */
87 /* typedefs *******************************************************************/
89 typedef struct nativethread nativethread;
90 typedef struct threadobject threadobject;
91 typedef java_lang_Thread thread;
96 java_objectheader *_exceptionptr;
97 stackframeinfo *_stackframeinfo;
98 localref_table *_localref_table; /* JNI local references */
99 #if defined(ENABLE_INTRP)
103 #if defined(__DARWIN__)
104 mach_port_t mach_thread;
106 pthread_mutex_t joinMutex;
107 pthread_cond_t joinCond;
111 /* threadobject ****************************************************************
113 Every java.lang.VMThread object is actually an instance of this
116 *******************************************************************************/
118 struct threadobject {
119 java_lang_VMThread o;
120 nativethread info; /* some general pthreads stuff */
121 lock_execution_env_t ee; /* contains our lock record pool */
123 /* these are used for the wait/notify implementation */
124 pthread_mutex_t waitLock;
125 pthread_cond_t waitCond;
130 dumpinfo dumpinfo; /* dump memory info structure */
133 void threads_sem_init(sem_t *sem, bool shared, int value);
134 void threads_sem_wait(sem_t *sem);
135 void threads_sem_post(sem_t *sem);
137 void *thread_getself(void);
139 void threads_preinit(void);
140 bool threads_init(u1 *stackbottom);
143 void initThread(java_lang_VMThread *);
146 void threads_start_thread(thread *t, functionptr function);
148 void joinAllThreads();
150 void thread_sleep(s8 millis, s4 nanos);
153 bool threads_wait_with_timeout_relative(threadobject *t, s8 millis, s4 nanos);
155 void setPriorityThread(thread *t, s4 priority);
157 void interruptThread(java_lang_VMThread *);
158 bool interruptedThread();
159 bool isInterruptedThread(java_lang_VMThread *);
161 #if defined(ENABLE_JVMTI)
162 void setthreadobject(threadobject *thread);
165 extern threadobject *mainthreadobj;
167 void cast_stopworld();
168 void cast_startworld();
170 /* dumps all threads */
171 void threads_dump(void);
174 /******************************************************************************/
175 /* Recursive Mutex Implementation for Darwin */
176 /******************************************************************************/
178 #if defined(MUTEXSIM)
180 /* We need this for older MacOSX (10.1.x) */
183 pthread_mutex_t mutex;
186 } pthread_mutex_rec_t;
188 void pthread_mutex_init_rec(pthread_mutex_rec_t *m);
189 void pthread_mutex_destroy_rec(pthread_mutex_rec_t *m);
190 void pthread_mutex_lock_rec(pthread_mutex_rec_t *m);
191 void pthread_mutex_unlock_rec(pthread_mutex_rec_t *m);
193 #else /* !defined(MUTEXSIM) */
195 #define pthread_mutex_lock_rec pthread_mutex_lock
196 #define pthread_mutex_unlock_rec pthread_mutex_unlock
197 #define pthread_mutex_rec_t pthread_mutex_t
199 #endif /* defined(MUTEXSIM) */
201 #endif /* _THREADS_H */
205 * These are local overrides for various environment variables in Emacs.
206 * Please do not remove this and leave it at the end of the file, where
207 * Emacs will automagically detect them.
208 * ---------------------------------------------------------------------
211 * indent-tabs-mode: t
215 * vim:noexpandtab:sw=4:ts=4: