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.
23 #define MAXTHREADS 256 /* schani */
25 #define THREADCLASS "java/lang/Thread"
26 #define THREADGROUPCLASS "java/lang/ThreadGroup"
27 #define THREADDEATHCLASS "java/lang/ThreadDeath"
29 #define MIN_THREAD_PRIO 1
30 #define NORM_THREAD_PRIO 5
31 #define MAX_THREAD_PRIO 10
33 #define THREAD_SUSPENDED 0
34 #define THREAD_RUNNING 1
38 #define THREAD_FLAGS_GENERAL 0
39 #define THREAD_FLAGS_NOSTACKALLOC 1
40 #define THREAD_FLAGS_USER_SUSPEND 2 /* Flag explicit suspend() call */
41 #define THREAD_FLAGS_KILLED 4
55 struct _thread *thread;
60 u1* stackMem; /* includes guard page */
65 java_objectheader *exceptionptr;
66 struct _thread *nextlive;
75 /* This structure mirrors java.lang.ThreadGroup.h */
77 typedef struct _threadGroup {
78 java_objectheader header;
79 struct _threadGroup* parent;
80 struct java_objectheader* name;
81 struct java_objectheader* threads;
82 struct java_objectheader* groups;
88 /* This structure mirrors java.lang.Thread.h */
89 typedef struct _thread {
90 java_objectheader header;
91 struct _threadGroup* group;
92 struct java_objectheader* toRun;
93 struct java_objectheader* name;
98 struct java_objectheader* contextClassLoader;
101 void initThreads (u1 *stackbottom);
102 void clear_thread_flags (void);
103 void startThread (thread*);
104 void resumeThread (thread*);
105 void iresumeThread (thread*);
106 void suspendThread (thread*);
107 void suspendOnQThread (thread*, thread**);
108 void yieldThread (void);
109 void killThread (thread*);
110 void setPriorityThread (thread*, int);
112 s8 currentTime (void);
113 void sleepThread (s8);
114 bool aliveThread (thread*);
115 long framesThread (thread*);
117 void reschedule (void);
119 void checkEvents (bool block);
121 extern int blockInts;
122 extern bool needReschedule;
123 extern thread *currentThread;
124 extern thread *mainThread;
125 extern ctx contexts[];
126 extern int threadStackSize;
128 extern thread *liveThreads;
129 extern thread *sleepThreads;
131 extern thread *threadQhead[MAX_THREAD_PRIO + 1];
134 #define CONTEXT(_t) (contexts[(_t)->PrivateInfo - 1])
136 #define intsDisable() blockInts++
138 #define intsRestore() if (blockInts == 1 && needReschedule) { \
146 #define THREADSTACKSIZE (32 * 1024)
148 #define THREADSWITCH(to, from) \
150 asm_perform_threadswitch(&(from)->restorePoint,\
151 &(to)->restorePoint, &(from)->usedStackTop); \
155 #define THREADINIT(to, func) \
157 (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), \
162 #define THREADINFO(e) \
164 (e)->restorePoint = 0; \
165 (e)->flags = THREAD_FLAGS_NOSTACKALLOC; \
169 /* function prototypes */
170 void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop);
171 u1* asm_initialize_thread_stack(void *func, u1 *stack);
175 #define intsDisable()
176 #define intsRestore()
178 #endif /* USE_THREADS */
180 #endif /* _THREAD_H */