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.
20 int super_baseval, super_diffval, sub_baseval;
27 #define THREADCLASS "java/lang/Thread"
28 #define THREADGROUPCLASS "java/lang/ThreadGroup"
29 #define THREADDEATHCLASS "java/lang/ThreadDeath"
31 #define MIN_THREAD_PRIO 1
32 #define NORM_THREAD_PRIO 5
33 #define MAX_THREAD_PRIO 10
35 #define THREAD_SUSPENDED 0
36 #define THREAD_RUNNING 1
40 #define THREAD_FLAGS_GENERAL 0
41 #define THREAD_FLAGS_NOSTACKALLOC 1
42 #define THREAD_FLAGS_USER_SUSPEND 2 /* Flag explicit suspend() call */
43 #define THREAD_FLAGS_KILLED 4
45 #if !defined(NATIVE_THREADS)
47 #define MAXTHREADS 256 /* schani */
62 struct _thread *thread;
67 u1* stackMem; /* includes guard page */
72 java_objectheader *texceptionptr;
73 struct _thread *nextlive;
83 /* This structure mirrors java.lang.ThreadGroup.h */
85 typedef struct _threadGroup {
86 java_objectheader header;
87 struct _threadGroup* parent;
88 struct java_objectheader* name;
89 struct java_objectheader* threads;
90 struct java_objectheader* groups;
97 /* This structure mirrors java.lang.VMThread.h */
98 typedef struct vmthread {
99 java_objectheader header;
100 struct _thread* thread;
110 java_objectheader *texceptionptr;
111 struct _thread* nextlive;
112 struct _thread* next;
116 /* This structure mirrors java.lang.Thread.h */
117 typedef struct _thread {
118 java_objectheader header;
121 struct java_lang_Runnable* runnable;
122 struct java_lang_String* name;
126 struct java_lang_Throwable* stillborn;
127 struct java_lang_ClassLoader* contextClassLoader;
130 void initThreads (u1 *stackbottom);
131 void clear_thread_flags (void);
132 void startThread (thread*);
133 void resumeThread (thread*);
134 void iresumeThread (thread*);
135 void suspendThread (thread*);
136 void suspendOnQThread (thread*, thread**);
137 void yieldThread (void);
138 void killThread (thread*);
139 void setPriorityThread (thread*, int);
141 s8 currentTime (void);
142 void sleepThread(s8 millis, s4 nanos);
143 bool aliveThread (thread*);
144 long framesThread (thread*);
146 void reschedule (void);
148 void checkEvents (bool block);
150 extern int blockInts;
151 extern bool needReschedule;
152 extern thread *currentThread;
153 extern thread *mainThread;
154 /*extern ctx contexts[];*/
155 extern int threadStackSize;
157 extern thread *liveThreads;
158 extern thread *sleepThreads;
160 extern thread *threadQhead[MAX_THREAD_PRIO + 1];
163 /*#define CONTEXT(_t) (contexts[(_t)->PrivateInfo - 1])*/
164 #define CONTEXT(_t) (*(_t->vmThread))
166 #define intsDisable() blockInts++
168 #define intsRestore() if (blockInts == 1 && needReschedule) { \
176 #define THREADSTACKSIZE (32 * 1024)
178 #define THREADSWITCH(to, from) \
182 asm_perform_threadswitch((from?&(from)->restorePoint:&from1),\
183 &(to)->restorePoint, (from?&(from)->usedStackTop:&from2)); \
187 #define THREADINIT(to, func) \
189 (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), \
194 #define THREADINFO(e) \
196 (e)->restorePoint = 0; \
197 (e)->flags = THREAD_FLAGS_NOSTACKALLOC; \
201 /* function prototypes */
202 void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop);
203 u1* asm_initialize_thread_stack(void *func, u1 *stack);
205 #else /* NATIVE_THREADS */
206 #include "nativethread.h"
211 #define intsDisable()
212 #define intsRestore()
214 #endif /* USE_THREADS */
216 #endif /* _THREAD_H */