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.
24 #define MAXTHREADS 256 /* schani */
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
56 struct _thread *thread;
61 u1* stackMem; /* includes guard page */
66 java_objectheader *texceptionptr;
67 struct _thread *nextlive;
76 /* This structure mirrors java.lang.ThreadGroup.h */
78 typedef struct _threadGroup {
79 java_objectheader header;
80 struct _threadGroup* parent;
81 struct java_objectheader* name;
82 struct java_objectheader* threads;
83 struct java_objectheader* groups;
89 /* This structure mirrors java.lang.Thread.h */
90 typedef struct _thread {
91 java_objectheader header;
92 struct _threadGroup* group;
93 struct java_objectheader* toRun;
94 struct java_objectheader* name;
99 struct java_objectheader* contextClassLoader;
102 void initThreads (u1 *stackbottom);
103 void clear_thread_flags (void);
104 void startThread (thread*);
105 void resumeThread (thread*);
106 void iresumeThread (thread*);
107 void suspendThread (thread*);
108 void suspendOnQThread (thread*, thread**);
109 void yieldThread (void);
110 void killThread (thread*);
111 void setPriorityThread (thread*, int);
113 s8 currentTime (void);
114 void sleepThread (s8);
115 bool aliveThread (thread*);
116 long framesThread (thread*);
118 void reschedule (void);
120 void checkEvents (bool block);
122 extern int blockInts;
123 extern bool needReschedule;
124 extern thread *currentThread;
125 extern thread *mainThread;
126 extern ctx contexts[];
127 extern int threadStackSize;
129 extern thread *liveThreads;
130 extern thread *sleepThreads;
132 extern thread *threadQhead[MAX_THREAD_PRIO + 1];
135 #define CONTEXT(_t) (contexts[(_t)->PrivateInfo - 1])
137 #define intsDisable() blockInts++
139 #define intsRestore() if (blockInts == 1 && needReschedule) { \
147 #define THREADSTACKSIZE (32 * 1024)
149 #define THREADSWITCH(to, from) \
151 asm_perform_threadswitch(&(from)->restorePoint,\
152 &(to)->restorePoint, &(from)->usedStackTop); \
156 #define THREADINIT(to, func) \
158 (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), \
163 #define THREADINFO(e) \
165 (e)->restorePoint = 0; \
166 (e)->flags = THREAD_FLAGS_NOSTACKALLOC; \
170 /* function prototypes */
171 void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop);
172 u1* asm_initialize_thread_stack(void *func, u1 *stack);
175 java_objectheader *_exceptionptr;
178 #if defined(NATIVE_THREADS) && !defined(HAVE___THREAD)
179 extern pthread_key_t tkey_threadinfo;
184 #define intsDisable()
185 #define intsRestore()
187 #endif /* USE_THREADS */
189 #endif /* _THREAD_H */