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 4909 2006-05-13 23:10:21Z 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 /* forward typedefs ***********************************************************/
70 typedef struct nativethread nativethread;
71 typedef struct threadobject threadobject;
74 /* current threadobject *******************************************************/
76 #if defined(HAVE___THREAD)
78 #define THREADSPECIFIC __thread
79 #define THREADOBJECT threads_current_threadobject
80 #define THREADINFO (&threads_current_threadobject->info)
82 extern __thread threadobject *threads_current_threadobject;
84 #else /* defined(HAVE___THREAD) */
86 #define THREADSPECIFIC
87 #define THREADOBJECT pthread_getspecific(threads_current_threadobject_key)
88 #define THREADINFO (&((threadobject*) pthread_getspecific(threads_current_threadobject_key))->info)
90 extern pthread_key_t threads_current_threadobject_key;
92 #endif /* defined(HAVE___THREAD) */
95 /* nativethread ****************************************************************
99 *******************************************************************************/
101 struct nativethread {
104 java_objectheader *_exceptionptr;
105 stackframeinfo *_stackframeinfo;
106 localref_table *_localref_table; /* JNI local references */
107 #if defined(ENABLE_INTRP)
111 #if defined(__DARWIN__)
112 mach_port_t mach_thread;
114 pthread_mutex_t joinMutex;
115 pthread_cond_t joinCond;
119 /* threadobject ****************************************************************
121 Every java.lang.VMThread object is actually an instance of this
124 *******************************************************************************/
126 struct threadobject {
127 java_lang_VMThread o;
128 nativethread info; /* some general pthreads stuff */
129 lock_execution_env_t ee; /* contains our lock record pool */
131 /* these are used for the wait/notify implementation */
132 pthread_mutex_t waitLock;
133 pthread_cond_t waitCond;
138 dumpinfo dumpinfo; /* dump memory info structure */
142 /* variables ******************************************************************/
144 extern threadobject *mainthreadobj;
147 /* functions ******************************************************************/
149 void threads_sem_init(sem_t *sem, bool shared, int value);
150 void threads_sem_wait(sem_t *sem);
151 void threads_sem_post(sem_t *sem);
153 threadobject *threads_get_current_threadobject(void);
155 void threads_preinit(void);
156 bool threads_init(u1 *stackbottom);
158 void threads_init_threadobject(java_lang_VMThread *);
160 void threads_start_thread(java_lang_Thread *t, functionptr function);
162 void threads_join_all_threads(void);
164 void threads_sleep(s8 millis, s4 nanos);
165 void threads_yield(void);
167 bool threads_wait_with_timeout_relative(threadobject *t, s8 millis, s4 nanos);
169 void threads_interrupt_thread(java_lang_VMThread *);
170 bool threads_check_if_interrupted_and_reset(void);
171 bool threads_thread_has_been_interrupted(java_lang_VMThread *);
173 #if defined(ENABLE_JVMTI)
174 void threads_set_current_threadobject(threadobject *thread);
177 void threads_java_lang_Thread_set_priority(java_lang_Thread *t, s4 priority);
179 void threads_cast_stopworld(void);
180 void threads_cast_startworld(void);
182 void threads_dump(void);
185 /******************************************************************************/
186 /* Recursive Mutex Implementation for Darwin */
187 /******************************************************************************/
189 #if defined(MUTEXSIM)
191 /* We need this for older MacOSX (10.1.x) */
194 pthread_mutex_t mutex;
197 } pthread_mutex_rec_t;
199 void pthread_mutex_init_rec(pthread_mutex_rec_t *m);
200 void pthread_mutex_destroy_rec(pthread_mutex_rec_t *m);
201 void pthread_mutex_lock_rec(pthread_mutex_rec_t *m);
202 void pthread_mutex_unlock_rec(pthread_mutex_rec_t *m);
204 #else /* !defined(MUTEXSIM) */
206 #define pthread_mutex_lock_rec pthread_mutex_lock
207 #define pthread_mutex_unlock_rec pthread_mutex_unlock
208 #define pthread_mutex_rec_t pthread_mutex_t
210 #endif /* defined(MUTEXSIM) */
212 #endif /* _THREADS_H */
216 * These are local overrides for various environment variables in Emacs.
217 * Please do not remove this and leave it at the end of the file, where
218 * Emacs will automagically detect them.
219 * ---------------------------------------------------------------------
222 * indent-tabs-mode: t
226 * vim:noexpandtab:sw=4:ts=4: