GNU header update.
[cacao.git] / src / threads / native / threads.h
index b95b1bf4aca395e16119da5e55904cd049030d16..0020d806fc94530d76037b7b71d898227f30e22b 100644 (file)
-#ifndef _NATIVETHREAD_H
-#define _NATIVETHREAD_H
+/* threads/native/threads.h - native threads header
 
-#include "jni.h"
-#include "nat/java_lang_Object.h"
-#include "nat/java_lang_Throwable.h"
-#include "nat/java_lang_Thread.h"
+   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+   Institut f. Computersprachen - TU Wien
 
-struct _threadobject;
+   This file is part of CACAO.
 
-typedef struct monitorLockRecord {
-       struct _threadobject *owner;
-       int lockCount;
-       long storedBits;
-       struct monitorLockRecord *queue;
-       struct monitorLockRecord *nextFree;
-} monitorLockRecord;
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
 
-struct _lockRecordPool;
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
 
-typedef struct {
-       struct _lockRecordPool *next;
-       int size;
-} lockRecordPoolHeader; 
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.
 
-typedef struct _lockRecordPool {
-       lockRecordPoolHeader header;
-       monitorLockRecord lr[1];
-} lockRecordPool;
+   Contact: cacao@complang.tuwien.ac.at
 
-#define INITIALLOCKRECORDS 8
+   Authors: Stefan Ring
 
-/* Monitor lock implementation */
-typedef struct {
-       pthread_mutex_t metaLockMutex;
-       pthread_cond_t metaLockCond;
-       bool gotMetaLockSlow;
-       bool bitsForGrab;
-       long metaLockBits;
-       struct _threadobject *succ;
-       pthread_mutex_t monitorLockMutex;
-       pthread_cond_t monitorLockCond;
-       bool isWaitingForNotify;
+   $Id: threads.h 1735 2004-12-07 14:33:27Z twisti $
+
+*/
+
+
+#ifndef _THREADS_H
+#define _THREADS_H
+
+#include <semaphore.h>
+
+#include "mm/memory.h"
+#include "native/jni.h"
+#include "native/include/java_lang_Object.h" /* required by java/lang/VMThread*/
+#include "native/include/java_lang_Thread.h"
+#include "native/include/java_lang_VMThread.h"
+
+#if defined(__DARWIN__)
+#include <mach/mach.h>
+
+/* We need to emulate recursive mutexes. */
+#define MUTEXSIM
+#endif
 
+
+/* typedefs *******************************************************************/
+
+typedef struct ExecEnvironment ExecEnvironment;
+typedef struct nativethread nativethread;
+typedef struct threadobject threadobject;
+typedef struct monitorLockRecord monitorLockRecord;
+typedef struct lockRecordPoolHeader lockRecordPoolHeader;
+typedef struct lockRecordPool lockRecordPool;
+typedef java_lang_Thread thread;
+
+
+/* ExecEnvironment *************************************************************
+
+   Monitor lock implementation
+
+*******************************************************************************/
+
+struct ExecEnvironment {
        monitorLockRecord *firstLR;
-       monitorLockRecord lr[INITIALLOCKRECORDS];
-       lockRecordPool *lrpool;
-} ExecEnvironment;
+       lockRecordPool    *lrpool;
+       int                numlr;
+};
 
-typedef struct {
-       struct _threadobject *next, *prev;
+
+struct nativethread {
+       threadobject      *next;
+       threadobject      *prev;
        java_objectheader *_exceptionptr;
-       methodinfo *_threadrootmethod;
-       void *_stackframeinfo;
-       pthread_t tid;
-       pthread_mutex_t joinMutex;
-       pthread_cond_t joinCond;
-} nativethread;
-
-typedef struct _threadobject {
-       java_lang_Thread o;
-       nativethread info;
-       ExecEnvironment ee;
-} threadobject, thread;
-
-void monitorEnter(threadobject *, java_objectheader *);
-void monitorExit(threadobject *, java_objectheader *);
+       methodinfo        *_threadrootmethod;
+       void              *_stackframeinfo;
+       pthread_t          tid;
+#if defined(__DARWIN__)
+       mach_port_t        mach_thread;
+#endif
+       pthread_mutex_t    joinMutex;
+       pthread_cond_t     joinCond;
+};
 
+
+/* threadobject ****************************************************************
+
+   DOCUMENT ME!
+
+*******************************************************************************/
+
+struct threadobject {
+       java_lang_VMThread  o;
+       nativethread        info;
+       ExecEnvironment     ee;
+
+       pthread_mutex_t     waitLock;
+       pthread_cond_t      waitCond;
+       bool                interrupted;
+       bool                signaled;
+       bool                isSleeping;
+
+       dumpinfo            dumpinfo;       /* dump memory info structure         */
+};
+
+
+struct monitorLockRecord {
+       threadobject      *ownerThread;
+       java_objectheader *o;
+       int                lockCount;
+       monitorLockRecord *nextFree;
+       int                queuers;
+       monitorLockRecord *waiter;
+       monitorLockRecord *incharge;
+       bool               waiting;
+       sem_t              queueSem;
+       pthread_mutex_t    resolveLock;
+       pthread_cond_t     resolveWait;
+};
+
+
+
+struct lockRecordPoolHeader {
+       lockRecordPool *next;
+       int             size;
+}; 
+
+struct lockRecordPool {
+       lockRecordPoolHeader header;
+       monitorLockRecord    lr[1];
+};
+
+
+monitorLockRecord *monitorEnter(threadobject *, java_objectheader *);
+bool monitorExit(threadobject *, java_objectheader *);
+
+bool threadHoldsLock(threadobject *t, java_objectheader *o);
 void signal_cond_for_object (java_objectheader *obj);
 void broadcast_cond_for_object (java_objectheader *obj);
-void wait_cond_for_object (java_objectheader *obj, s8 time);
+void wait_cond_for_object (java_objectheader *obj, s8 time, s4 nanos);
 
 void initThreadsEarly();
 void initThreads(u1 *stackbottom);
+void initObjectLock(java_objectheader *);
 void initLocks();
-void initThread(java_lang_Thread *);
+void initThread(java_lang_VMThread *);
+void startThread(thread *t);
 void joinAllThreads();
 
-bool aliveThread(java_lang_Thread *);
-void sleepThread (s8);
+void sleepThread(s8 millis, s4 nanos);
 void yieldThread();
 
+void setPriorityThread(thread *t, s4 priority);
+
+void interruptThread(java_lang_VMThread *);
+bool interruptedThread();
+bool isInterruptedThread(java_lang_VMThread *);
+
 #if !defined(HAVE___THREAD)
 extern pthread_key_t tkey_threadinfo;
-#define THREADOBJECT ((java_lang_Thread*) pthread_getspecific(tkey_threadinfo))
+#define THREADOBJECT ((java_lang_VMThread*) pthread_getspecific(tkey_threadinfo))
 #define THREADINFO (&((threadobject*) pthread_getspecific(tkey_threadinfo))->info)
 #else
 extern __thread threadobject *threadobj;
-#define THREADOBJECT ((java_lang_Thread*) threadobj)
+#define THREADOBJECT ((java_lang_VMThread*) threadobj)
 #define THREADINFO (&threadobj->info)
 #endif
 
-#include "builtin.h"
 
+/* This must not be changed, it is used in asm_criticalsections */
 typedef struct {
-       u1 *mcodebegin, *mcodeend;
+       u1 *mcodebegin;
+       u1 *mcodeend;
+       u1 *mcoderestart;
 } threadcritnode;
 
 void thread_registercritical(threadcritnode *);
+u1 *thread_checkcritical(u1*);
 
 extern volatile int stopworldwhere;
 
-#endif /* _NATIVETHREAD_H */
+void cast_stopworld();
+void cast_startworld();
+
+#endif /* _THREADS_H */
+
 
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */