* src/threads/native/threads.c, src/threads/native/threads.c: Further
authoredwin <none@none>
Sat, 13 May 2006 23:10:21 +0000 (23:10 +0000)
committeredwin <none@none>
Sat, 13 May 2006 23:10:21 +0000 (23:10 +0000)
cleanup. Still no functional changes.
Renamed external symbols are listed below.

* src/threads/native/critical.h, src/threads/native/critical.c: Cleanup.

* src/threads/native/lock.h: Cleanup.

* src/vm/jit/profile/profile.c (thread_sleep): Renamed to threads_sleep.

* src/vm/vm.c (joinAllThreads): Renamed to threads_join_all_threads.

* src/native/jni.c (thread_getself): Renamed to
threads_get_current_threadobject.

* src/native/vm/VMThread.c (thread): Typedef `thread` has been removed.
(interruptThread): Renamed to threads_interrupt_thread.
(isInterruptedThread): Renamed to threads_thread_has_been_interrupted.
(setPriorityThread): Renamed to threads_java_lang_Thread_set_priority.
(yieldThread): Renamed to threads_yield.
(interruptedThread): Renamed to threads_check_if_interrupted_and_reset.

* src/native/jvmti/cacaodbg.c (thread_getself): Renamed to
threads_get_current_threadobject.
(setthreadobject): Renamed to threads_set_current_threadobject.

* src/native/jvmti/jvmti.c (setthreadobject): Renamed to
threads_set_current_threadobject.

* src/threads/green/threads.h (yieldThread): Renamed to threads_yield.
(setPriorityThread): Renamed to threads_java_lang_Thread_set_priority.

* src/threads/green/threads.c (yieldThread): Renamed to threads_yield.
(setPriorityThread): Renamed to threads_java_lang_Thread_set_priority.

13 files changed:
src/native/jni.c
src/native/jvmti/cacaodbg.c
src/native/jvmti/jvmti.c
src/native/vm/VMThread.c
src/threads/green/threads.c
src/threads/green/threads.h
src/threads/native/critical.c
src/threads/native/critical.h
src/threads/native/lock.h
src/threads/native/threads.c
src/threads/native/threads.h
src/vm/jit/profile/profile.c
src/vm/vm.c

index 1e1100652c996aa5b9614b29712d2a8a8ec2e69d..dc8d6bfaf83a1ba8152af511b25e13fc6ce0590b 100644 (file)
@@ -32,7 +32,7 @@
             Christian Thalinger
                        Edwin Steiner
 
-   $Id: jni.c 4901 2006-05-11 12:18:55Z twisti $
+   $Id: jni.c 4909 2006-05-13 23:10:21Z edwin $
 
 */
 
@@ -5436,7 +5436,7 @@ jint GetEnv(JavaVM *vm, void **env, jint version)
        STATISTICS(jniinvokation());
 
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       if (thread_getself() == NULL) {
+       if (threads_get_current_threadobject() == NULL) {
                *env = NULL;
 
                return JNI_EDETACHED;
index bcd2c888edef35a9fb4c525f20398a65edf7ac59..aaddbcf0b9f57e52413a98c1f55dafc428770bcd 100644 (file)
@@ -102,7 +102,7 @@ jvmtiError allthreads (jint * threads_count_ptr, threadobject*** threads_ptr) {
 
 *******************************************************************************/
 jthread getcurrentthread() {
-       return (jthread)((threadobject*)thread_getself())->o.thread;
+       return (jthread)(threads_get_current_threadobject())->o.thread;
 }
 
 
@@ -281,8 +281,8 @@ void cacaobreakpointhandler() {
                
                switch (i) {
                case SETTHREADOBJECTBRK:
-                       /* setthreadobject */
-                       fprintf(stderr,"IP %X == setthreadobject\n",ev.ip);
+                       /* threads_set_current_threadobject */
+                       fprintf(stderr,"IP %X == threads_set_current_threadobject\n",ev.ip);
                        data.ev=JVMTI_EVENT_THREAD_START;
                        fireEvent(&data);
                        break;
index 1d56715008e9620d37d5065ab226d70dc75032cd..5aa90332296ef9dc17534f4c24a8412866ec17f7 100644 (file)
@@ -31,7 +31,7 @@
             Samuel Vinson
 
    
-   $Id: jvmti.c 4908 2006-05-12 16:49:50Z edwin $
+   $Id: jvmti.c 4909 2006-05-13 23:10:21Z edwin $
 
 */
 
@@ -4315,7 +4315,7 @@ void set_jvmti_phase(jvmtiPhase p) {
                d.ev = JVMTI_EVENT_VM_START;
                /* this event is sent during start or live phase */
                log_text("set sysbrk in setthreadobj");
-               setsysbrkpt(SETTHREADOBJECTBRK,(void*)&setthreadobject);
+               setsysbrkpt(SETTHREADOBJECTBRK,(void*)&threads_set_current_threadobject);
         break;
     case JVMTI_PHASE_LIVE: 
                phase = p; 
index 00c70c3072e742c8c18301fee20ae14a7488b422..359aaf6510c381399c2339c82bddc0780dc4c0c2 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Joseph Wenninger
             Christian Thalinger
 
-   $Id: VMThread.c 4908 2006-05-12 16:49:50Z edwin $
+   $Id: VMThread.c 4909 2006-05-13 23:10:21Z edwin $
 
 */
 
@@ -83,7 +83,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMTh
 
        /* don't pass a function pointer (NULL) since we want Thread.run()V here */
 
-       threads_start_thread((thread *) this->thread, NULL);
+       threads_start_thread((java_lang_Thread *) this->thread, NULL);
 #endif
 }
 
@@ -96,7 +96,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMTh
 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
 {
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       interruptThread(this);
+       threads_interrupt_thread(this);
 #else
        log_text("Java_java_lang_VMThread_interrupt called");
 #endif
@@ -111,7 +111,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_
 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
 {
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       return isInterruptedThread(this);
+       return threads_thread_has_been_interrupted(this);
 #else
        log_text("Java_java_lang_VMThread_isInterrupted called");
        return 0;
@@ -127,7 +127,7 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lan
 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
 {
 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
-       suspendThread((thread *) this->thread);
+       suspendThread((java_lang_Thread *) this->thread);
 #endif
 }
 
@@ -140,7 +140,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VM
 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
 {
 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
-       resumeThread((thread *) this->thread);
+       resumeThread((java_lang_Thread *) this->thread);
 #endif
 }
 
@@ -153,7 +153,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMT
 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 priority)
 {
 #if defined(USE_THREADS)
-       setPriorityThread((thread *) this->thread, priority);
+       threads_java_lang_Thread_set_priority((java_lang_Thread *) this->thread, priority);
 #endif
 }
 
@@ -166,7 +166,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, ja
 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *t)
 {
 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
-       if (currentThread == (thread *) this->thread) {
+       if (currentThread == (java_lang_Thread *) this->thread) {
                log_text("killing");
                killThread(0);
                /*
@@ -175,8 +175,8 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang
                */
 
        } else {
-               /*CONTEXT((thread*)this)*/ this->flags |= THREAD_FLAGS_KILLED;
-               resumeThread((thread *) this->thread);
+               /*CONTEXT((java_lang_Thread*)this)*/ this->flags |= THREAD_FLAGS_KILLED;
+               resumeThread((java_lang_Thread *) this->thread);
        }
 #endif
 }
@@ -229,7 +229,7 @@ JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv
 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
 {
 #if defined(USE_THREADS)
-       yieldThread();
+       threads_yield();
 #endif
 }
 
@@ -242,7 +242,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
 {
 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       return interruptedThread();
+       return threads_check_if_interrupted_and_reset();
 #else
        log_text("Java_java_lang_VMThread_interrupted");
        return 0;
index 139184c973748c06bcfb3da92b27a9223a91aa2e..f9e5cf9cd10d65b611eb678935dd7405a63392a3 100644 (file)
@@ -459,7 +459,7 @@ iresumeThread(thread* tid)
  * Yield process to another thread of equal priority.
  */
 void
-yieldThread()
+threads_yield()
 {
     intsDisable();
 
@@ -709,7 +709,7 @@ killThread(thread* tid)
  * Change thread priority.
  */
 void
-setPriorityThread(thread* tid, int prio)
+threads_java_lang_Thread_set_priority(thread* tid, int prio)
 {
     thread** ntid;
 
index 55a657bd5a2114f29cc2282eabeb6e93f7f5f76e..5465d6af4eef2f44119cdab7e95b9f571ce072e9 100644 (file)
@@ -196,9 +196,9 @@ void resumeThread (thread*);
 void iresumeThread (thread*);
 void suspendThread (thread*);
 void suspendOnQThread (thread*, thread**);
-void yieldThread (void);
+void threads_yield (void);
 void killThread (thread*);
-void setPriorityThread (thread*, int);
+void threads_java_lang_Thread_set_priority (thread*, int);
 
 s8 currentTime (void);
 void sleepThread(s8 millis, s4 nanos);
index dc63e8113d9f80ee21065bc931388d60f2b48477..77b695040408d42198063a55ef402aad8aea5e8b 100644 (file)
 #include "vm/jit/asmpart.h"
 #include "toolbox/avl.h"
 
+
 /* the AVL tree containing the critical sections */
 
 static avl_tree *criticaltree;
 
+
 /* prototypes *****************************************************************/
 
 static s4 critical_compare(const void *pa, const void *pb);
@@ -53,7 +55,7 @@ static void critical_register_asm_critical_sections(void);
 
 
 /* critical_init ***************************************************************
+
    Init global data structures.
 
 *******************************************************************************/
@@ -66,7 +68,7 @@ void critical_init(void)
 }
 
 /* critical_compare ************************************************************
+
    Comparison function for AVL tree of critical section.
 
    IN:
@@ -74,8 +76,8 @@ void critical_init(void)
           pb...............second node
 
    RETURN VALUE:
-       -1, 0, or +1
-   
+       -1, 0, +1 for (pa <, ==, > pb)
+
 *******************************************************************************/
 
 static s4 critical_compare(const void *pa, const void *pb)
@@ -158,7 +160,7 @@ void critical_register_critical_section(critical_section_node_t *n)
 
 
 /* critical_find_restart_point *************************************************
+
    Find a restart point for the given PC, in case it is in a critical section.
 
    IN:
@@ -180,7 +182,7 @@ u1 *critical_find_restart_point(u1 *mcodeptr)
 
 
 /* critical_register_asm_critical_sections *************************************
+
    Register critical sections defined in the array asm_criticalsections.
 
 *******************************************************************************/
index 93bf24287cfb8260fb700abe69e2d6a8fcfeaef0..3c51eed58e8f96167cab6f17ce99cf7ec1c0a757 100644 (file)
 
 #include <ucontext.h>
 
-/* This must not be changed, it is used in asm_criticalsections! */
+/* forward typedefs ***********************************************************/
 
-typedef struct {
+typedef struct critical_section_node_t critical_section_node_t;
+
+
+/* critical_section_node_t *****************************************************
+
+   A node representing a restartable critical section.
+
+*******************************************************************************/
+
+/* CAUTION: This must not be changed, it is used in asm_criticalsections!     */
+struct critical_section_node_t {
        u1 *mcodebegin;
        u1 *mcodeend;
        u1 *mcoderestart;
-} critical_section_node_t;
+};
+
+
+/* functions ******************************************************************/
 
 void critical_init(void);
 
@@ -55,7 +68,8 @@ void critical_register_critical_section(critical_section_node_t *);
 
 u1 *critical_find_restart_point(u1*);
 
-/* this is a machine dependent functions (src/vm/jit/$(ARCH_DIR)/md.c) */
+/* this is a machine dependent function (see src/vm/jit/$(ARCH_DIR)/md.c) */
+/* XXX should be renamed to md_restart_critical_section                   */
 void thread_restartcriticalsection(ucontext_t *);
 
 #endif /* _CRITICAL_H */
index c9c79bb91cbee904a53aef9f907d527f2651e141..378a6b9b40ee6465333070cd4828919399df68f5 100644 (file)
@@ -75,16 +75,16 @@ struct lock_execution_env_t {
 
 struct lock_record_t {
        struct threadobject *owner;
-       java_objectheader *o;
-       s4                 lockCount;
-       lock_record_t *nextFree;
-       s4                 queuers;
-       lock_record_t *waiter;
-       lock_record_t *incharge;
-       java_objectheader *waiting;
-       sem_t              queueSem;
-       pthread_mutex_t    resolveLock;
-       pthread_cond_t     resolveWait;
+       java_objectheader   *o;
+       s4                   lockCount;
+       lock_record_t       *nextFree;
+       s4                   queuers;
+       lock_record_t       *waiter;
+       lock_record_t       *incharge;
+       java_objectheader   *waiting;
+       sem_t                queueSem;
+       pthread_mutex_t      resolveLock;
+       pthread_cond_t       resolveWait;
 };
 
 
@@ -94,7 +94,7 @@ struct lock_record_t {
 
 struct lock_record_pool_header_t {
        lock_record_pool_t *next;
-       int             size;
+       int                 size;
 }; 
 
 
@@ -104,9 +104,12 @@ struct lock_record_pool_header_t {
 
 struct lock_record_pool_t {
        lock_record_pool_header_t header;
-       lock_record_t    lr[1];
+       lock_record_t             lr[1];
 };
 
+
+/* functions ******************************************************************/
+
 void lock_init(void);
 
 lock_record_t *lock_get_initial_lock_word(void);
index fecb4b7e7ad89aa995b28c5473be73c6985a95b1..094099a5ccdd9f7e9009bfc6ccd4f412db3b46d9 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Christian Thalinger
                        Edwin Steiner
 
-   $Id: threads.c 4908 2006-05-12 16:49:50Z edwin $
+   $Id: threads.c 4909 2006-05-13 23:10:21Z edwin $
 
 */
 
 #endif
 
 
+/* internally used constants **************************************************/
+
+/* CAUTION: Do not change these values. Boehm GC code depends on them.        */
+#define STOPWORLD_FROM_GC               1
+#define STOPWORLD_FROM_CLASS_NUMBERING  2
+
+
+/* startupinfo *****************************************************************
+
+   Struct used to pass info from threads_start_thread to 
+   threads_startup_thread.
+
+******************************************************************************/
+
+typedef struct {
+       threadobject *thread;      /* threadobject for this thread             */
+       functionptr   function;    /* function to run in the new thread        */
+       sem_t        *psem;        /* signals when thread has been entered     */
+                                  /* in the thread list                       */
+       sem_t        *psem_first;  /* signals when pthread_create has returned */
+} startupinfo;
+
+
 /* prototypes *****************************************************************/
 
 static void threads_calc_absolute_time(struct timespec *tm, s8 millis, s4 nanos);
-       
+
+
 /******************************************************************************/
 /* GLOBAL VARIABLES                                                           */
 /******************************************************************************/
 
-/* the main thread */
+/* the main thread                                                            */
 threadobject *mainthreadobj;
 
-#ifndef HAVE___THREAD
-pthread_key_t tkey_threadinfo;
+/* the thread object of the current thread                                    */
+/* This is either a thread-local variable defined with __thread, or           */
+/* a thread-specific value stored with key threads_current_threadobject_key.  */
+#if defined(HAVE___THREAD)
+__thread threadobject *threads_current_threadobject;
 #else
-__thread threadobject *threadobj;
+pthread_key_t threads_current_threadobject_key;
 #endif
 
+/* global compiler mutex                                                      */
 static pthread_mutex_rec_t compiler_mutex;
 
+/* global mutex for changing the thread list                                  */
 static pthread_mutex_t threadlistlock;
 
+/* global mutex for stop-the-world                                            */
 static pthread_mutex_t stopworldlock;
+
+/* this is one of the STOPWORLD_FROM_ constants, telling why the world is     */
+/* being stopped                                                              */
 static volatile int stopworldwhere;
 
+/* semaphore used for acknowleding thread suspension                          */
 static sem_t suspend_ack;
 #if defined(__MIPS__)
 static pthread_mutex_t suspend_ack_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -123,6 +157,7 @@ static pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;
 
 static pthread_attr_t threadattr;
 
+/* mutexes used by the fake atomic instructions                               */
 #if defined(USE_MD_THREAD_STUFF)
 pthread_mutex_t _atomic_add_lock = PTHREAD_MUTEX_INITIALIZER;
 pthread_mutex_t _cas_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -293,7 +328,7 @@ static void threads_set_thread_priority(pthread_t tid, int priority)
 
 ******************************************************************************/
 
-void compiler_lock()
+void compiler_lock(void)
 {
        pthread_mutex_lock_rec(&compiler_mutex);
 }
@@ -305,7 +340,7 @@ void compiler_lock()
 
 ******************************************************************************/
 
-void compiler_unlock()
+void compiler_unlock(void)
 {
        pthread_mutex_unlock_rec(&compiler_mutex);
 }
@@ -316,8 +351,8 @@ void compiler_unlock()
    Enter the stopworld lock, specifying why the world shall be stopped.
 
    IN:
-      where........ 1 from within GC
-                    2 class numbering
+      where........ STOPWORLD_FROM_GC              (1) from within GC
+                    STOPWORLD_FROM_CLASS_NUMBERING (2) class numbering
 
 ******************************************************************************/
 
@@ -334,7 +369,7 @@ void lock_stopworld(int where)
 
 ******************************************************************************/
 
-void unlock_stopworld()
+void unlock_stopworld(void)
 {
        stopworldwhere = 0;
        pthread_mutex_unlock(&stopworldlock);
@@ -342,7 +377,7 @@ void unlock_stopworld()
 
 #if !defined(__DARWIN__)
 /* Caller must hold threadlistlock */
-static int cast_sendsignals(int sig, int count)
+static int threads_cast_sendsignals(int sig, int count)
 {
        /* Count threads */
        threadobject *tobj = mainthreadobj;
@@ -367,7 +402,7 @@ static int cast_sendsignals(int sig, int count)
 
 #else
 
-static void cast_darwinstop()
+static void threads_cast_darwinstop(void)
 {
        threadobject *tobj = mainthreadobj;
        nativethread *infoself = THREADINFO;
@@ -408,7 +443,7 @@ static void cast_darwinstop()
        } while (tobj != mainthreadobj);
 }
 
-static void cast_darwinresume()
+static void threads_cast_darwinresume(void)
 {
        threadobject *tobj = mainthreadobj;
        nativethread *infoself = THREADINFO;
@@ -433,7 +468,7 @@ static void cast_darwinresume()
 #endif
 
 #if defined(__MIPS__)
-static void cast_irixresume()
+static void threads_cast_irixresume(void)
 {
        pthread_mutex_lock(&suspend_ack_lock);
        pthread_cond_broadcast(&suspend_cond);
@@ -441,37 +476,37 @@ static void cast_irixresume()
 }
 #endif
 
-void cast_stopworld()
+void threads_cast_stopworld(void)
 {
        int count, i;
-       lock_stopworld(2);
+       lock_stopworld(STOPWORLD_FROM_CLASS_NUMBERING);
        pthread_mutex_lock(&threadlistlock);
 #if defined(__DARWIN__)
-       cast_darwinstop();
+       threads_cast_darwinstop();
 #else
-       count = cast_sendsignals(GC_signum1(), 0);
+       count = threads_cast_sendsignals(GC_signum1(), 0);
        for (i=0; i<count; i++)
                threads_sem_wait(&suspend_ack);
 #endif
        pthread_mutex_unlock(&threadlistlock);
 }
 
-void cast_startworld()
+void threads_cast_startworld(void)
 {
        pthread_mutex_lock(&threadlistlock);
 #if defined(__DARWIN__)
-       cast_darwinresume();
+       threads_cast_darwinresume();
 #elif defined(__MIPS__)
-       cast_irixresume();
+       threads_cast_irixresume();
 #else
-       cast_sendsignals(GC_signum2(), -1);
+       threads_cast_sendsignals(GC_signum2(), -1);
 #endif
        pthread_mutex_unlock(&threadlistlock);
        unlock_stopworld();
 }
 
 #if !defined(__DARWIN__)
-static void sigsuspend_handler(ucontext_t *ctx)
+static void threads_sigsuspend_handler(ucontext_t *ctx)
 {
        int sig;
        sigset_t sigs;
@@ -498,18 +533,20 @@ static void sigsuspend_handler(ucontext_t *ctx)
 #endif
 }
 
+/* This function is called from Boehm GC code. */
+
 int cacao_suspendhandler(ucontext_t *ctx)
 {
-       if (stopworldwhere != 2)
+       if (stopworldwhere != STOPWORLD_FROM_CLASS_NUMBERING)
                return 0;
 
-       sigsuspend_handler(ctx);
+       threads_sigsuspend_handler(ctx);
        return 1;
 }
 #endif
 
 
-/* setthreadobject *************************************************************
+/* threads_set_current_threadobject ********************************************
 
    Set the current thread object.
    
@@ -519,34 +556,35 @@ int cacao_suspendhandler(ucontext_t *ctx)
 *******************************************************************************/
 
 #if !defined(ENABLE_JVMTI)
-static void setthreadobject(threadobject *thread)
+static void threads_set_current_threadobject(threadobject *thread)
 #else
-void setthreadobject(threadobject *thread)
+void threads_set_current_threadobject(threadobject *thread)
 #endif
 {
 #if !defined(HAVE___THREAD)
-       pthread_setspecific(tkey_threadinfo, thread);
+       pthread_setspecific(threads_current_threadobject_key, thread);
 #else
-       threadobj = thread;
+       threads_current_threadobject = thread;
 #endif
 }
 
 
-/* thread_setself **************************************************************
+/* threads_get_current_threadobject ********************************************
 
    Return the threadobject of the current thread.
    
-   XXX The return value type should be changed to a typed pointer.
+   RETURN VALUE:
+       the current threadobject * (an instance of java.lang.VMThread)
 
 *******************************************************************************/
 
-void *thread_getself(void)
+threadobject *threads_get_current_threadobject(void)
 {
        return THREADOBJECT;
 }
 
 
-/* thread_preinit **************************************************************
+/* threads_preinit *************************************************************
 
    Do some early initialization of stuff required.
 
@@ -574,9 +612,9 @@ void threads_preinit(void)
        mainthreadobj = NEW(threadobject);
        mainthreadobj->info.tid = pthread_self();
 #if !defined(HAVE___THREAD)
-       pthread_key_create(&tkey_threadinfo, NULL);
+       pthread_key_create(&threads_current_threadobject_key, NULL);
 #endif
-       setthreadobject(mainthreadobj);
+       threads_set_current_threadobject(mainthreadobj);
 
        /* we need a working dummyLR before initializing the critical
           section tree */
@@ -622,9 +660,9 @@ bool threads_init(u1 *stackbottom)
 
        FREE(tempthread, threadobject);
 
-       initThread(&mainthreadobj->o);
+       threads_init_threadobject(&mainthreadobj->o);
 
-       setthreadobject(mainthreadobj);
+       threads_set_current_threadobject(mainthreadobj);
 
        lock_init_thread_lock_record_pool(mainthreadobj);
 
@@ -706,7 +744,7 @@ bool threads_init(u1 *stackbottom)
 }
 
 
-/* initThread ******************************************************************
+/* threads_init_threadobject **************************************************
 
    Initialize implementation fields of a java.lang.VMThread.
 
@@ -715,7 +753,7 @@ bool threads_init(u1 *stackbottom)
 
 ******************************************************************************/
 
-void initThread(java_lang_VMThread *t)
+void threads_init_threadobject(java_lang_VMThread *t)
 {
        threadobject *thread = (threadobject*) t;
        nativethread *info = &thread->info;
@@ -732,22 +770,6 @@ void initThread(java_lang_VMThread *t)
 }
 
 
-/* startupinfo *****************************************************************
-
-   Struct used to pass info from threads_start_thread to 
-   threads_startup_thread.
-
-******************************************************************************/
-
-typedef struct {
-       threadobject *thread;      /* threadobject for this thread             */
-       functionptr   function;    /* function to run in the new thread        */
-       sem_t        *psem;        /* signals when thread has been entered     */
-                                  /* in the thread list                       */
-       sem_t        *psem_first;  /* signals when pthread_create has returned */
-} startupinfo;
-
-
 /* threads_startup_thread ******************************************************
 
    Thread startup function called by pthread_create.
@@ -808,7 +830,7 @@ static void *threads_startup_thread(void *t)
 #if defined(__DARWIN__)
        info->mach_thread = mach_thread_self();
 #endif
-       setthreadobject(thread);
+       threads_set_current_threadobject(thread);
 
        /* insert the thread into the threadlist */
 
@@ -900,7 +922,7 @@ static void *threads_startup_thread(void *t)
 
 ******************************************************************************/
 
-void threads_start_thread(thread *t, functionptr function)
+void threads_start_thread(java_lang_Thread *t, functionptr function)
 {
        nativethread *info;
        sem_t         sem;
@@ -943,9 +965,9 @@ void threads_start_thread(thread *t, functionptr function)
 }
 
 
-/* findNonDaemon ***************************************************************
+/* threads_find_non_daemon_thread **********************************************
 
-   Helper function used by joinAllThreads for finding non-daemon threads
+   Helper function used by threads_join_all_threads for finding non-daemon threads
    that are still running.
 
 *******************************************************************************/
@@ -953,7 +975,7 @@ void threads_start_thread(thread *t, functionptr function)
 /* At the end of the program, we wait for all running non-daemon threads to die
  */
 
-static threadobject *findNonDaemon(threadobject *thread)
+static threadobject *threads_find_non_daemon_thread(threadobject *thread)
 {
        while (thread != mainthreadobj) {
                if (!thread->o.thread->daemon)
@@ -965,17 +987,17 @@ static threadobject *findNonDaemon(threadobject *thread)
 }
 
 
-/* joinAllThreads **************************************************************
+/* threads_join_all_threads ****************************************************
 
    Join all non-daemon threads.
 
 *******************************************************************************/
 
-void joinAllThreads()
+void threads_join_all_threads(void)
 {
        threadobject *thread;
        pthread_mutex_lock(&threadlistlock);
-       while ((thread = findNonDaemon(mainthreadobj->info.prev)) != NULL) {
+       while ((thread = threads_find_non_daemon_thread(mainthreadobj->info.prev)) != NULL) {
                nativethread *info = &thread->info;
                pthread_mutex_lock(&info->joinMutex);
                pthread_mutex_unlock(&threadlistlock);
@@ -1127,7 +1149,7 @@ static bool threads_wait_with_timeout(threadobject *t,
 *******************************************************************************/
 
 bool threads_wait_with_timeout_relative(threadobject *t,
-                                                                               s8 millis,
+                                                                               s8 millis,
                                                                                s4 nanos)
 {
        struct timespec wakeupTime;
@@ -1174,7 +1196,7 @@ static void threads_calc_absolute_time(struct timespec *tm, s8 millis, s4 nanos)
 }
 
 
-/* interruptThread *************************************************************
+/* threads_interrupt_thread ****************************************************
 
    Interrupt the given thread.
 
@@ -1186,7 +1208,7 @@ static void threads_calc_absolute_time(struct timespec *tm, s8 millis, s4 nanos)
 
 *******************************************************************************/
 
-void interruptThread(java_lang_VMThread *thread)
+void threads_interrupt_thread(java_lang_VMThread *thread)
 {
        threadobject *t = (threadobject*) thread;
 
@@ -1201,7 +1223,7 @@ void interruptThread(java_lang_VMThread *thread)
 }
 
 
-/* interruptedThread ***********************************************************
+/* threads_check_if_interrupted_and_reset **************************************
 
    Check if the current thread has been interrupted and reset the
    interruption flag.
@@ -1211,7 +1233,7 @@ void interruptThread(java_lang_VMThread *thread)
 
 *******************************************************************************/
 
-bool interruptedThread()
+bool threads_check_if_interrupted_and_reset(void)
 {
        threadobject *t;
        bool intr;
@@ -1226,7 +1248,7 @@ bool interruptedThread()
 }
 
 
-/* isInterruptedThread *********************************************************
+/* threads_thread_has_been_interrupted *********************************************************
 
    Check if the given thread has been interrupted
 
@@ -1238,7 +1260,7 @@ bool interruptedThread()
 
 *******************************************************************************/
 
-bool isInterruptedThread(java_lang_VMThread *thread)
+bool threads_thread_has_been_interrupted(java_lang_VMThread *thread)
 {
        threadobject *t;
 
@@ -1248,13 +1270,13 @@ bool isInterruptedThread(java_lang_VMThread *thread)
 }
 
 
-/* thread_sleep ****************************************************************
+/* threads_sleep ***************************************************************
 
    Sleep the current thread for the specified amount of time.
 
 *******************************************************************************/
 
-void thread_sleep(s8 millis, s4 nanos)
+void threads_sleep(s8 millis, s4 nanos)
 {
        threadobject       *t;
        struct timespec    wakeupTime;
@@ -1271,19 +1293,19 @@ void thread_sleep(s8 millis, s4 nanos)
 }
 
 
-/* yieldThread *****************************************************************
+/* threads_yield *****************************************************************
 
    Yield to the scheduler.
 
 *******************************************************************************/
 
-void yieldThread()
+void threads_yield(void)
 {
        sched_yield();
 }
 
 
-/* setPriorityThread ***********************************************************
+/* threads_java_lang_Thread_set_priority ***********************************************************
 
    Set the priority for the given java.lang.Thread.
 
@@ -1293,7 +1315,7 @@ void yieldThread()
 
 *******************************************************************************/
 
-void setPriorityThread(thread *t, s4 priority)
+void threads_java_lang_Thread_set_priority(java_lang_Thread *t, s4 priority)
 {
        nativethread *info = &((threadobject*) t->vmThread)->info;
        threads_set_thread_priority(info->tid, priority);
@@ -1354,7 +1376,7 @@ void threads_dump(void)
 
                        /* sleep this thread a bit, so the signal can reach the thread */
 
-                       thread_sleep(10, 0);
+                       threads_sleep(10, 0);
                }
 
                tobj = tobj->info.next;
index 7a7f592d6e0e82771f4618ddabd5ac0c7076c0a8..b66e1be2a0dd53757ef624546d76ed8eabc0f181 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Christian Thalinger
                        Edwin Steiner
 
-   $Id: threads.h 4908 2006-05-12 16:49:50Z edwin $
+   $Id: threads.h 4909 2006-05-13 23:10:21Z edwin $
 
 */
 
 #endif
 
 
+/* forward typedefs ***********************************************************/
+
+typedef struct nativethread nativethread;
+typedef struct threadobject threadobject;
+
+
+/* current threadobject *******************************************************/
+
 #if defined(HAVE___THREAD)
 
 #define THREADSPECIFIC    __thread
-#define THREADOBJECT      threadobj
-#define THREADINFO        (&threadobj->info)
+#define THREADOBJECT      threads_current_threadobject
+#define THREADINFO        (&threads_current_threadobject->info)
 
-extern __thread threadobject *threadobj;
+extern __thread threadobject *threads_current_threadobject;
 
 #else /* defined(HAVE___THREAD) */
 
 #define THREADSPECIFIC
-#define THREADOBJECT      pthread_getspecific(tkey_threadinfo)
-#define THREADINFO        (&((threadobject*) pthread_getspecific(tkey_threadinfo))->info)
+#define THREADOBJECT      pthread_getspecific(threads_current_threadobject_key)
+#define THREADINFO        (&((threadobject*) pthread_getspecific(threads_current_threadobject_key))->info)
 
-extern pthread_key_t tkey_threadinfo;
+extern pthread_key_t threads_current_threadobject_key;
 
 #endif /* defined(HAVE___THREAD) */
 
 
-/* typedefs *******************************************************************/
+/* nativethread ****************************************************************
 
-typedef struct nativethread nativethread;
-typedef struct threadobject threadobject;
-typedef java_lang_Thread thread;
+   XXX
+
+*******************************************************************************/
 
 struct nativethread {
        threadobject      *next;
@@ -116,58 +124,61 @@ struct nativethread {
 *******************************************************************************/
 
 struct threadobject {
-       java_lang_VMThread  o;
-       nativethread        info;           /* some general pthreads stuff        */
-       lock_execution_env_t     ee;             /* contains our lock record pool      */
+       java_lang_VMThread    o;
+       nativethread          info;         /* some general pthreads stuff        */
+       lock_execution_env_t  ee;           /* contains our lock record pool      */
 
        /* these are used for the wait/notify implementation                      */
-       pthread_mutex_t     waitLock;
-       pthread_cond_t      waitCond;
-       bool                interrupted;
-       bool                signaled;
-       bool                isSleeping;
+       pthread_mutex_t       waitLock;
+       pthread_cond_t        waitCond;
+       bool                  interrupted;
+       bool                  signaled;
+       bool                  isSleeping;
 
-       dumpinfo            dumpinfo;       /* dump memory info structure         */
+       dumpinfo              dumpinfo;     /* dump memory info structure         */
 };
 
+
+/* variables ******************************************************************/
+
+extern threadobject *mainthreadobj;
+
+
+/* functions ******************************************************************/
+
 void threads_sem_init(sem_t *sem, bool shared, int value);
 void threads_sem_wait(sem_t *sem);
 void threads_sem_post(sem_t *sem);
 
-void *thread_getself(void);
+threadobject *threads_get_current_threadobject(void);
 
 void threads_preinit(void);
 bool threads_init(u1 *stackbottom);
 
-void lock_init();
-void initThread(java_lang_VMThread *);
+void threads_init_threadobject(java_lang_VMThread *);
 
-/* start a thread */
-void threads_start_thread(thread *t, functionptr function);
+void threads_start_thread(java_lang_Thread *t, functionptr function);
 
-void joinAllThreads();
+void threads_join_all_threads(void);
 
-void thread_sleep(s8 millis, s4 nanos);
-void yieldThread();
+void threads_sleep(s8 millis, s4 nanos);
+void threads_yield(void);
 
 bool threads_wait_with_timeout_relative(threadobject *t, s8 millis, s4 nanos);
 
-void setPriorityThread(thread *t, s4 priority);
-
-void interruptThread(java_lang_VMThread *);
-bool interruptedThread();
-bool isInterruptedThread(java_lang_VMThread *);
+void threads_interrupt_thread(java_lang_VMThread *);
+bool threads_check_if_interrupted_and_reset(void);
+bool threads_thread_has_been_interrupted(java_lang_VMThread *);
 
 #if defined(ENABLE_JVMTI)
-void setthreadobject(threadobject *thread);
+void threads_set_current_threadobject(threadobject *thread);
 #endif
 
-extern threadobject *mainthreadobj;
+void threads_java_lang_Thread_set_priority(java_lang_Thread *t, s4 priority);
 
-void cast_stopworld();
-void cast_startworld();
+void threads_cast_stopworld(void);
+void threads_cast_startworld(void);
 
-/* dumps all threads */
 void threads_dump(void);
 
 
index d50a2c5a76b501ff2f6105d6cccf94720798a679..c73bbb50be9512e9b874add13f4ee231194de18d 100644 (file)
@@ -105,7 +105,7 @@ static void profile_thread(void)
        while (true) {
                /* sleep thread for 100 nanos */
 
-               thread_sleep(0, 100);
+               threads_sleep(0, 100);
 
 #if 0
                /* get the lock on the finalizer lock object, so we can call wait */
index 8f11af6f601f7a074441aee582780a2264256554..644c8cd0d53bb7bc4606724cb09702c0c5b0ab0f 100644 (file)
@@ -1245,7 +1245,7 @@ s4 vm_destroy(JavaVM *vm)
 {
 #if defined(USE_THREADS)
 #if defined(NATIVE_THREADS)
-       joinAllThreads();
+       threads_join_all_threads();
 #else
        killThread(currentThread);
 #endif