1 /* -*- mode: c; tab-width: 4; c-basic-offset: 4 -*- */
6 * Copyright (c) 1996 T. J. Wilkinson & Associates, London, UK.
8 * See the file "license.terms" for information on usage and redistribution
9 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * Written by Tim Wilkinson <tim@tjwassoc.demon.co.uk>, 1996.
19 #include "mm/memory.h"
20 #include "vm/global.h" /* for native includes */
21 #include "native/include/java_lang_ClassLoader.h"
22 #include "native/include/java_lang_String.h"
23 #include "native/include/java_lang_Throwable.h"
26 #define THREADCLASS "java/lang/Thread"
27 #define THREADGROUPCLASS "java/lang/ThreadGroup"
28 #define THREADDEATHCLASS "java/lang/ThreadDeath"
30 #define MIN_THREAD_PRIO 1
31 #define NORM_THREAD_PRIO 5
32 #define MAX_THREAD_PRIO 10
34 #define THREAD_SUSPENDED 0
35 #define THREAD_RUNNING 1
39 #define THREAD_FLAGS_GENERAL 0
40 #define THREAD_FLAGS_NOSTACKALLOC 1
41 #define THREAD_FLAGS_USER_SUSPEND 2 /* Flag explicit suspend() call */
42 #define THREAD_FLAGS_KILLED 4
44 #define THREADSPECIFIC
46 #define MAXTHREADS 256 /* schani */
61 struct _thread *thread;
66 u1* stackMem; /* includes guard page */
71 java_objectheader *texceptionptr;
72 struct _thread *nextlive;
82 /* This structure mirrors java.lang.ThreadGroup.h */
84 typedef struct _threadGroup {
85 java_objectheader header;
86 struct _threadGroup* parent;
87 struct java_objectheader* name;
88 struct java_objectheader* threads;
89 struct java_objectheader* groups;
95 typedef struct thread thread;
96 typedef struct vmthread vmthread;
98 /* This structure mirrors java.lang.Thread.h */
101 java_objectheader header;
104 struct java_lang_Runnable* runnable;
105 java_lang_String *name;
109 java_lang_Throwable *stillborn;
110 java_lang_ClassLoader *contextClassLoader;
114 /* This structure mirrors java.lang.VMThread.h */
117 java_objectheader header;
128 java_objectheader *texceptionptr;
129 struct _thread *nextlive;
130 struct _thread *next;
134 dumpinfo *dumpinfo; /* dump memory info structure */
139 extern int blockInts;
140 extern bool needReschedule;
141 extern thread *currentThread;
142 extern thread *mainThread;
143 /*extern ctx contexts[];*/
144 extern int threadStackSize;
146 extern thread *liveThreads;
147 extern thread *sleepThreads;
149 extern thread *threadQhead[MAX_THREAD_PRIO + 1];
152 /*#define CONTEXT(_t) (contexts[(_t)->PrivateInfo - 1])*/
153 #define CONTEXT(_t) (*(_t->vmThread))
155 #define intsDisable() blockInts++
157 #define intsRestore() if (blockInts == 1 && needReschedule) { \
165 #define THREADSTACKSIZE (32 * 1024)
167 #define THREADSWITCH(to, from) \
171 asm_perform_threadswitch((from?&(from)->restorePoint:&from1),\
172 &(to)->restorePoint, (from?&(from)->usedStackTop:&from2)); \
176 #define THREADINIT(to, func) \
178 (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), \
183 #define THREADINFO(e) \
185 (e)->restorePoint = 0; \
186 (e)->flags = THREAD_FLAGS_NOSTACKALLOC; \
190 /* function prototypes ********************************************************/
192 void initThreads (u1 *stackbottom);
193 void clear_thread_flags (void);
194 void startThread (thread*);
195 void resumeThread (thread*);
196 void iresumeThread (thread*);
197 void suspendThread (thread*);
198 void suspendOnQThread (thread*, thread**);
199 void yieldThread (void);
200 void killThread (thread*);
201 void setPriorityThread (thread*, int);
203 s8 currentTime (void);
204 void sleepThread(s8 millis, s4 nanos);
205 bool aliveThread (thread*);
206 long framesThread (thread*);
208 void reschedule (void);
210 void checkEvents (bool block);
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