Merged to new trunk.
authorStefan Ring <stefan@complang.tuwien.ac.at>
Sun, 15 Jun 2008 09:10:15 +0000 (11:10 +0200)
committerStefan Ring <stefan@complang.tuwien.ac.at>
Sun, 15 Jun 2008 09:10:15 +0000 (11:10 +0200)
1  2 
src/threads/posix/thread-posix.c
src/threads/posix/thread-posix.h
src/threads/thread.h

index 26002bc5b25101bebe986732689d07d85e00b152,03ac51f84839c2ac36deaddd35571ea9cf407bdb..cfa6deca7de49c11052d1257b6355caed1796132
  #if !defined(__DARWIN__)
  # include <semaphore.h>
  #endif
 -# if defined(__LINUX__)
 -#  define GC_LINUX_THREADS
 -# elif defined(__IRIX__)
 -#  define GC_IRIX_THREADS
 -# elif defined(__DARWIN__)
 -#  define GC_DARWIN_THREADS
 -# endif
 -# if defined(ENABLE_GC_BOEHM)
 +
 +#if defined(__LINUX__)
 +# define GC_LINUX_THREADS
 +#elif defined(__IRIX__)
 +# define GC_IRIX_THREADS
 +#elif defined(__DARWIN__)
 +# define GC_DARWIN_THREADS
 +#endif
 +
 +#if defined(ENABLE_GC_BOEHM)
  /* We need to include Boehm's gc.h here because it overrides
     pthread_create and friends. */
 -#  include "mm/boehm-gc/include/gc.h"
 -# endif
 +# include "mm/boehm-gc/include/gc.h"
 +#endif
  
  #if defined(ENABLE_JVMTI)
  #include "native/jvmti/cacaodbg.h"
@@@ -723,7 -721,6 +723,6 @@@ void threads_impl_thread_clear(threadob
  
        t->interrupted = false;
        t->signaled = false;
-       t->sleeping = false;
  
        t->suspended = false;
        t->suspend_reason = 0;
@@@ -975,18 -972,9 +974,18 @@@ static void *threads_startup_thread(voi
        java_handle_t      *o;
        functionptr         function;
  
 +#if defined(ENABLE_GC_BOEHM)
 +# if !defined(__DARWIN__)
 +      struct GC_stack_base sb;
 +      int result;
 +# endif
 +#endif
 +
  #if defined(ENABLE_INTRP)
        u1 *intrp_thread_stack;
 +#endif
  
 +#if defined(ENABLE_INTRP)
        /* create interpreter stack */
  
        if (opt_intrp) {
  
        thread_set_current(t);
  
 +#if defined(ENABLE_GC_BOEHM)
 +# if defined(__DARWIN__)
 +      // This is currently not implemented in Boehm-GC.  Just fail silently.
 +# else
 +      /* Register the thread with Boehm-GC.  This must happen before the
 +         thread allocates any memory from the GC heap.*/
 +
 +      result = GC_get_stack_base(&sb);
 +
 +      if (result != 0)
 +              vm_abort("threads_startup_thread: GC_get_stack_base failed: result=%d", result);
 +
 +      GC_register_my_thread(&sb);
 +# endif
 +#endif
 +
        /* get the java.lang.Thread object for this thread */
  
        object = (java_lang_Thread *) thread_get_object(t);
  
        /* We ignore the return value. */
  
 -      (void) threads_detach_thread(t);
 +      (void) thread_detach_current_thread();
  
        /* set ThreadMXBean variables */
  
@@@ -1253,14 -1225,14 +1252,14 @@@ void threads_set_thread_priority(pthrea
  }
  
  
 -/* threads_detach_thread *******************************************************
 -
 -   Detaches the passed thread from the VM.  Used in JNI.
 -
 -*******************************************************************************/
 -
 -bool threads_detach_thread(threadobject *t)
 +/**
 + * Detaches the current thread from the VM.
 + *
 + * @return true on success, false otherwise
 + */
 +bool thread_detach_current_thread(void)
  {
 +      threadobject          *t;
        bool                   result;
        java_lang_Thread      *object;
        java_handle_t         *o;
        methodinfo            *m;
  #endif
  
 +      t = thread_get_current();
 +
 +      /* Sanity check. */
 +
 +      assert(t != NULL);
 +
      /* If the given thread has already been detached, this operation
           is a no-op. */
  
@@@ -1648,10 -1614,6 +1647,6 @@@ static void threads_wait_with_timeout(t
  
        mutex_lock(&t->waitmutex);
  
-       /* mark us as sleeping */
-       t->sleeping = true;
        /* wait on waitcond */
  
        if (wakeupTime->tv_sec || wakeupTime->tv_nsec) {
                }
        }
  
-       t->sleeping    = false;
        /* release the waitmutex */
  
        mutex_unlock(&t->waitmutex);
@@@ -1770,8 -1730,7 +1763,7 @@@ void threads_thread_interrupt(threadobj
  
        pthread_kill(thread->tid, SIGHUP);
  
-       if (thread->sleeping)
-               pthread_cond_signal(&thread->waitcond);
+       pthread_cond_signal(&thread->waitcond);
  
        thread->interrupted = true;
  
index 40f7fcd02528ad9937190a7d3ca9c67cf8666138,1431bc2ddeb8a6ce93f9f0f190fb3ce8d1393383..45d05eca4407779363f6c553befb969e35141446
@@@ -138,7 -138,6 +138,6 @@@ struct threadobject 
  
        bool                  interrupted;
        bool                  signaled;
-       bool                  sleeping;
  
        bool                  suspended;    /* is this thread suspended?          */
        s4                    suspend_reason; /* reason for suspending            */
@@@ -271,6 -270,8 +270,6 @@@ void threads_start_thread(threadobject 
  
  void threads_set_thread_priority(pthread_t tid, int priority);
  
 -bool threads_detach_thread(threadobject *thread);
 -
  #if defined(ENABLE_GC_CACAO)
  bool threads_suspend_thread(threadobject *thread, s4 reason);
  void threads_suspend_ack(u1* pc, u1* sp);
diff --combined src/threads/thread.h
index 61ddbfd8a4dd6556fa4c6d314026b9ae73e1d32e,0c1197f2b5252fd22325d563aeb48cf3af1ecf92..309de1a9bc9d4d7216b14d154f67355f56a04393
@@@ -206,7 -206,17 +206,17 @@@ inline static bool thread_is_attached(t
  
  inline static bool thread_is_interrupted(threadobject *t)
  {
-       return t->interrupted;
+       bool interrupted;
+       /* We need the mutex because classpath will call this function when
+          a blocking system call is interrupted. The mutex ensures that it will
+          see the correct value for the interrupted flag. */
+       mutex_lock(&t->waitmutex);
+       interrupted = t->interrupted;
+       mutex_unlock(&t->waitmutex);
+       return interrupted;
  }
  
  
@@@ -289,11 -299,7 +299,11 @@@ void          thread_free(threadobject 
  bool          threads_thread_start_internal(utf *name, functionptr f);
  void          threads_thread_start(java_handle_t *object);
  
 -bool          threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
 +bool          thread_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
 +bool          thread_attach_current_external_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
 +bool          thread_detach_current_thread(void);
 +
 +bool          thread_detach_current_external_thread(void);
  
  void          thread_fprint_name(threadobject *t, FILE *stream);
  void          thread_print_info(threadobject *t);