OSDN Git Service

* config/freebsd.h (FBSD_CPP_PREDEFINES): Use #endif/#if pair
[pf3gnuchains/gcc-fork.git] / libjava / posix-threads.cc
index ce70257..286bf83 100644 (file)
@@ -16,11 +16,7 @@ details.  */
 // If we're using the Boehm GC, then we need to override some of the
 // thread primitives.  This is fairly gross.
 #ifdef HAVE_BOEHM_GC
-extern "C"
-{
-#include <gcconfig.h>
 #include <gc.h>
-};
 #endif /* HAVE_BOEHM_GC */
 
 #include <stdlib.h>
@@ -300,7 +296,7 @@ _Jv_InitThreads (void)
 _Jv_Thread_t *
 _Jv_ThreadInitData (java::lang::Thread *obj)
 {
-  _Jv_Thread_t *data = new _Jv_Thread_t;
+  _Jv_Thread_t *data = (_Jv_Thread_t *) _Jv_Malloc (sizeof (_Jv_Thread_t));
   data->flags = 0;
   data->thread_obj = obj;
 
@@ -315,7 +311,7 @@ _Jv_ThreadDestroyData (_Jv_Thread_t *data)
 {
   pthread_mutex_destroy (&data->wait_mutex);
   pthread_cond_destroy (&data->wait_cond);
-  delete data;
+  _Jv_Free ((void *)data);
 }
 
 void
@@ -330,6 +326,25 @@ _Jv_ThreadSetPriority (_Jv_Thread_t *data, jint prio)
     }
 }
 
+void
+_Jv_ThreadRegister (_Jv_Thread_t *data)
+{
+  pthread_setspecific (_Jv_ThreadKey, data->thread_obj);
+  pthread_setspecific (_Jv_ThreadDataKey, data);
+
+  // glibc 2.1.3 doesn't set the value of `thread' until after start_routine
+  // is called. Since it may need to be accessed from the new thread, work 
+  // around the potential race here by explicitly setting it again.
+  data->thread = pthread_self ();
+}
+
+void
+_Jv_ThreadUnRegister ()
+{
+  pthread_setspecific (_Jv_ThreadKey, NULL);
+  pthread_setspecific (_Jv_ThreadDataKey, NULL);
+}
+
 // This function is called when a thread is started.  We don't arrange
 // to call the `run' method directly, because this function must
 // return a value.
@@ -338,13 +353,7 @@ really_start (void *x)
 {
   struct starter *info = (struct starter *) x;
 
-  pthread_setspecific (_Jv_ThreadKey, info->data->thread_obj);
-  pthread_setspecific (_Jv_ThreadDataKey, info->data);
-
-  // glibc 2.1.3 doesn't set the value of `thread' until after start_routine
-  // is called. Since it may need to be accessed from the new thread, work 
-  // around the potential race here by explicitly setting it again.
-  info->data->thread = pthread_self ();
+  _Jv_ThreadRegister (info->data);
 
   info->method (info->data->thread_obj);
   
@@ -378,7 +387,6 @@ _Jv_ThreadStart (java::lang::Thread *thread, _Jv_Thread_t *data,
   pthread_attr_setschedparam (&attr, &param);
   pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
 
-  // FIXME: handle marking the info object for GC.
   info = (struct starter *) _Jv_AllocBytes (sizeof (struct starter));
   info->method = meth;
   info->data = data;