* Written by Tim Wilkinson <tim@tjwassoc.demon.co.uk>, 1996.
*/
-#ifndef __thread_h
-#define __thread_h
+#ifndef _THREAD_H
+#define _THREAD_H
#include "config.h"
+typedef struct {
+ int super_baseval, super_diffval, sub_baseval;
+} castinfo;
+
#ifdef USE_THREADS
#include "global.h"
-#define MAXTHREADS 256 /* schani */
-
-#define THREADCLASS "java/lang/Thread"
-#define THREADGROUPCLASS "java/lang/ThreadGroup"
-#define THREADDEATHCLASS "java/lang/ThreadDeath"
+#define THREADCLASS "java/lang/Thread"
+#define THREADGROUPCLASS "java/lang/ThreadGroup"
+#define THREADDEATHCLASS "java/lang/ThreadDeath"
#define MIN_THREAD_PRIO 1
#define NORM_THREAD_PRIO 5
#define THREAD_FLAGS_USER_SUSPEND 2 /* Flag explicit suspend() call */
#define THREAD_FLAGS_KILLED 4
+#if !defined(NATIVE_THREADS)
+
+#define MAXTHREADS 256 /* schani */
+
+#if 1
+#define DBG(s)
+#define SDBG(s)
+#else
+#define DBG(s) s
+#define SDBG(s) s
+#endif
+
struct _thread;
+#if 0
typedef struct _ctx
{
struct _thread *thread;
u1* stackEnd;
u1* usedStackTop;
s8 time;
- java_objectheader *exceptionptr;
+ java_objectheader *texceptionptr;
struct _thread *nextlive;
u1 flags;
} ctx;
+#endif
/*
struct _stringClass;
/* This structure mirrors java.lang.ThreadGroup.h */
-typedef struct _threadGroup
-{
- java_objectheader header;
- struct _threadGroup* parent;
- java_objectheader* name;
- s4 maxPrio;
- s4 destroyed;
- s4 daemon;
- s4 vmAllowSuspension;
- s4 nthreads;
- java_objectheader* threads;
- s4 ngroups;
- java_objectheader* groups;
+typedef struct _threadGroup {
+ java_objectheader header;
+ struct _threadGroup* parent;
+ struct java_objectheader* name;
+ struct java_objectheader* threads;
+ struct java_objectheader* groups;
+ s4 daemon_flag;
+ s4 maxpri;
} threadGroup;
+
+
+/* This structure mirrors java.lang.VMThread.h */
+typedef struct vmthread {
+ java_objectheader header;
+ struct _thread* thread;
+ s4 running;
+ s4 status;
+ s4 priority;
+ void* restorePoint;
+ void* stackMem;
+ void* stackBase;
+ void* stackEnd;
+ void* usedStackTop;
+ s8 time;
+ java_objectheader *texceptionptr;
+ struct _thread* nextlive;
+ struct _thread* next;
+ s4 flags;
+} vmthread;
+
/* This structure mirrors java.lang.Thread.h */
-typedef struct _thread
-{
- java_objectheader header;
- java_objectheader* name;
- s4 priority;
- struct _thread* next;
- s8 PrivateInfo;
- s4 single_step;
- s4 daemon;
- s4 stillborn;
- java_objectheader* target;
- threadGroup* group;
- java_objectheader* contextClassLoader;
- java_objectheader* inheritedAccessControlContext;
- java_objectheader* values;
+typedef struct _thread {
+ java_objectheader header;
+ vmthread* vmThread;
+ threadGroup* group;
+ struct java_lang_Runnable* runnable;
+ struct java_lang_String* name;
+ s4 daemon;
+ s4 priority;
+ s8 stacksize;
+ struct java_lang_Throwable* stillborn;
+ struct java_lang_ClassLoader* contextClassLoader;
} thread;
void initThreads (u1 *stackbottom);
void setPriorityThread (thread*, int);
s8 currentTime (void);
-void sleepThread (s8);
+void sleepThread(s8 millis, s4 nanos);
bool aliveThread (thread*);
long framesThread (thread*);
extern bool needReschedule;
extern thread *currentThread;
extern thread *mainThread;
-extern ctx contexts[];
+/*extern ctx contexts[];*/
extern int threadStackSize;
extern thread *liveThreads;
extern thread *threadQhead[MAX_THREAD_PRIO + 1];
-#define CONTEXT(_t) \
- (contexts[(_t)->PrivateInfo - 1])
-#if 1
+/*#define CONTEXT(_t) (contexts[(_t)->PrivateInfo - 1])*/
+#define CONTEXT(_t) (*(_t->vmThread))
+
#define intsDisable() blockInts++
-#define intsRestore() if (blockInts == 1 && needReschedule) { \
- reschedule(); \
- } \
- blockInts--
-#else
-#define intsDisable() do { blockInts++; fprintf(stderr, "++: %d (%s:%d)\n", blockInts, __FILE__, __LINE__); } while (0)
-#define intsRestore() do { \
- if (blockInts == 1 && needReschedule) { \
- reschedule(); \
- } \
- blockInts--; \
- fprintf(stderr, "--: %d (%s:%d)\n", blockInts, __FILE__, __LINE__); \
- } while (0)
+
+#define intsRestore() if (blockInts == 1 && needReschedule) { \
+ reschedule(); \
+ } \
+ blockInts--
+
+
+/* access macros */
+
+#define THREADSTACKSIZE (32 * 1024)
+
+#define THREADSWITCH(to, from) \
+ do { \
+ void *from1; \
+ void *from2; \
+ asm_perform_threadswitch((from?&(from)->restorePoint:&from1),\
+ &(to)->restorePoint, (from?&(from)->usedStackTop:&from2)); \
+ } while (0)
+
+
+#define THREADINIT(to, func) \
+ do { \
+ (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), \
+ (to)->stackEnd); \
+ } while (0)
+
+
+#define THREADINFO(e) \
+ do { \
+ (e)->restorePoint = 0; \
+ (e)->flags = THREAD_FLAGS_NOSTACKALLOC; \
+ } while(0)
+
+
+/* function prototypes */
+void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop);
+u1* asm_initialize_thread_stack(void *func, u1 *stack);
+
+#else // defined(NATIVE_THREADS)
+#include "nativethread.h"
#endif
#else
#define intsDisable()
#define intsRestore()
-#endif
+#endif /* USE_THREADS */
+
+#endif /* _THREAD_H */
-#endif