The patch for libobjc 3

H.J. Lu hjl@varesearch.com
Fri Jul 16 08:10:00 GMT 1999


I fixed a few typos in Solaris threads. It works on Solaris 7/x86 and
Solaris 7/Sparc.

Thanks.


-- 
H.J. Lu (hjl@gnu.org)
--
--- /dev/null	Tue May  5 13:32:27 1998
+++ libobjc/ChangeLog.libobjc	Fri Jul  2 11:53:54 1999
@@ -0,0 +1,5 @@
+Fri Jul  2 11:53:39 1999  H.J. Lu  (hjl@gnu.org)
+
+	* Makefile.in (OBJC_THREAD_FILE): Changed to thr-objc.
+
+	* thr-objc.c: New.
--- /dev/null	Tue May  5 13:32:27 1998
+++ libobjc/thr-objc.c	Fri Jul  2 11:33:31 1999
@@ -0,0 +1,182 @@
+/* GNU Objective C Runtime Thread Interface.
+   Copyright (C) 1999 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC 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.
+
+GNU CC 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.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/* As a special exception, if you link this library with files compiled with
+   GCC to produce an executable, this does not cause the resulting executable
+   to be covered by the GNU General Public License. This exception does not
+   however invalidate any other reasons why the executable file might be
+   covered by the GNU General Public License.  */
+
+#define _LIBOBJC
+#define HAVE_GTHR_DEFAULT
+#include "tconfig.h"
+#include "defaults.h"
+#include <objc/thr.h>
+#include "runtime.h"
+#include <gthr.h>
+
+/* Backend initialization functions */
+
+/* Initialize the threads subsystem. */
+int
+__objc_init_thread_system(void)
+{
+  return __gthread_objc_init_thread_system ();
+}
+
+/* Close the threads subsystem. */
+int
+__objc_close_thread_system(void)
+{
+  return __gthread_objc_close_thread_system ();
+}
+
+/* Backend thread functions */
+
+/* Create a new thread of execution. */
+objc_thread_t
+__objc_thread_detach(void (*func)(void *), void *arg)
+{
+  return __gthread_objc_thread_detach (func, arg);
+}
+
+/* Set the current thread's priority. */
+int
+__objc_thread_set_priority(int priority)
+{
+  return __gthread_objc_thread_set_priority (priority);
+}
+
+/* Return the current thread's priority. */
+int
+__objc_thread_get_priority(void)
+{
+  return __gthread_objc_thread_get_priority ();
+}
+
+/* Yield our process time to another thread. */
+void
+__objc_thread_yield(void)
+{
+  __gthread_objc_thread_yield ();
+}
+
+/* Terminate the current thread. */
+int
+__objc_thread_exit(void)
+{
+  return __gthread_objc_thread_exit ();
+}
+
+/* Returns an integer value which uniquely describes a thread. */
+objc_thread_t
+__objc_thread_id(void)
+{
+  return __gthread_objc_thread_id ();
+}
+
+/* Sets the thread's local storage pointer. */
+int
+__objc_thread_set_data(void *value)
+{
+  return __gthread_objc_thread_set_data (value);
+}
+
+/* Returns the thread's local storage pointer. */
+void *
+__objc_thread_get_data(void)
+{
+  return __gthread_objc_thread_get_data ();
+}
+
+/* Backend mutex functions */
+
+/* Allocate a mutex. */
+int
+__objc_mutex_allocate(objc_mutex_t mutex)
+{
+  return __gthread_objc_mutex_allocate (mutex);
+}
+
+/* Deallocate a mutex. */
+int
+__objc_mutex_deallocate(objc_mutex_t mutex)
+{
+  return __gthread_objc_mutex_deallocate (mutex);
+}
+
+/* Grab a lock on a mutex. */
+int
+__objc_mutex_lock(objc_mutex_t mutex)
+{
+  return __gthread_objc_mutex_lock (mutex);
+}
+
+/* Try to grab a lock on a mutex. */
+int
+__objc_mutex_trylock(objc_mutex_t mutex)
+{
+  return __gthread_objc_mutex_trylock (mutex);
+}
+
+/* Unlock the mutex */
+int
+__objc_mutex_unlock(objc_mutex_t mutex)
+{
+  return __gthread_objc_mutex_unlock (mutex);
+}
+
+/* Backend condition mutex functions */
+
+/* Allocate a condition. */
+int
+__objc_condition_allocate(objc_condition_t condition)
+{
+  return __gthread_objc_condition_allocate (condition);
+}
+
+/* Deallocate a condition. */
+int
+__objc_condition_deallocate(objc_condition_t condition)
+{
+  return __gthread_objc_condition_deallocate (condition);
+}
+
+/* Wait on the condition */
+int
+__objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
+{
+  return __gthread_objc_condition_wait (condition, mutex);
+}
+
+/* Wake up all threads waiting on this condition. */
+int
+__objc_condition_broadcast(objc_condition_t condition)
+{
+  return __gthread_objc_condition_broadcast (condition);
+}
+
+/* Wake up one thread waiting on this condition. */
+int
+__objc_condition_signal(objc_condition_t condition)
+{
+  return __gthread_objc_condition_signal (condition);
+}
+
+/* End of File */
Index: libobjc/Makefile.in
===================================================================
RCS file: /work/cvs/gnu/egcs/libobjc/Makefile.in,v
retrieving revision 1.1.1.8
diff -u -p -r1.1.1.8 Makefile.in
--- libobjc/Makefile.in	1999/05/13 01:11:24	1.1.1.8
+++ libobjc/Makefile.in	1999/07/02 18:52:38
@@ -75,7 +75,7 @@ INCLUDES = -I$(srcdir)/objc  -I$(srcdir)
   -I$(srcdir)/$(MULTISRCTOP)../include
 
 OBJC_GCFLAGS=-DOBJC_WITH_GC=1
-OBJC_THREAD_FILE=thr-@OBJC_THREAD_FILE@
+OBJC_THREAD_FILE=thr-objc
 
 .SUFFIXES:
 .SUFFIXES: .c .m .o
--- /dev/null	Tue May  5 13:32:27 1998
+++ gcc/ChangeLog.libobjc	Sun Jul 11 12:18:10 1999
@@ -0,0 +1,7 @@
+Sun Jul 11 12:14:43 1999  H.J. Lu  (hjl@gnu.org)
+
+	* gthr-dce.h: Add support for libobjc.
+	* gthr-posix.h: Likewise.
+	* gthr-solaris.h: Likewise.
+	* gthr-vxworks.h: Likewise.
+
Index: gcc/gthr-dce.h
===================================================================
RCS file: /work/cvs/gnu/egcs/gcc/gthr-dce.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 gthr-dce.h
--- gcc/gthr-dce.h	1998/01/09 17:37:17	1.1.1.1
+++ gcc/gthr-dce.h	1999/07/11 18:31:40
@@ -1,6 +1,6 @@
 
 /* Compile this one with gcc.  */
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -48,7 +48,7 @@ typedef pthread_mutex_t __gthread_mutex_
 
 #pragma weak pthread_once
 #pragma weak pthread_once_init
-#pragma weak pthread_key_create
+#pragma weak pthread_keycreate
 #pragma weak pthread_key_delete
 #pragma weak pthread_getspecific
 #pragma weak pthread_setspecific
@@ -58,6 +58,21 @@ typedef pthread_mutex_t __gthread_mutex_
 #pragma weak pthread_mutex_trylock
 #pragma weak pthread_mutex_unlock
 
+#ifdef _LIBOBJC
+/* Objective C. */
+#pragma weak pthread_cond_broadcast
+#pragma weak pthread_cond_destroy
+#pragma weak pthread_cond_init
+#pragma weak pthread_cond_signal
+#pragma weak pthread_cond_wait
+#pragma weak pthread_exit
+#pragma weak pthread_getunique_np
+#pragma weak pthread_mutex_init
+#pragma weak pthread_mutex_destroy
+#pragma weak pthread_self
+#pragma weak pthread_yield
+#endif
+
 static void *__gthread_active_ptr = &pthread_create;
 
 static inline int
@@ -76,7 +91,299 @@ __gthread_active_p ()
 
 #endif /* SUPPORTS_WEAK */
 
+#ifdef _LIBOBJC
+
+/* Key structure for maintaining thread specific storage */
+static pthread_key_t _objc_thread_storage;
+
+/* Thread local storage for a single thread */
+static void *thread_local_storage = NULL;
+
+/* Backend initialization functions */
+
+/* Initialize the threads subsystem. */
+static inline int
+__gthread_objc_init_thread_system(void)
+{
+  if (__gthread_active_p ())
+    /* Initialize the thread storage key */
+    return pthread_keycreate (&_objc_thread_storage, NULL);
+  else
+    return -1;
+}
+
+/* Close the threads subsystem. */
+static inline int
+__gthread_objc_close_thread_system(void)
+{
+  if (__gthread_active_p ())
+    return 0;
+  else
+    return -1;
+}
+
+/* Backend thread functions */
+
+/* Create a new thread of execution. */
+static inline objc_thread_t
+__gthread_objc_thread_detach(void (*func)(void *), void *arg)
+{
+  objc_thread_t thread_id;
+  pthread_t new_thread_handle;
+
+  if (!__gthread_active_p ())
+    return NULL;
+ 
+  if ( !(pthread_create(&new_thread_handle, pthread_attr_default,
+  			(void *)func, arg)) )
+    {
+      /* ??? May not work! (64bit) */
+      thread_id = *(objc_thread_t *)&new_thread_handle;
+      pthread_detach(&new_thread_handle); /* Fully detach thread. */
+    }
+  else
+    thread_id = NULL;
+  
+  return thread_id;
+}
+
+/* Set the current thread's priority. */
 static inline int
+__gthread_objc_thread_set_priority(int priority)
+{
+  int sys_priority = 0;
+
+  if (!__gthread_active_p ())
+    return -1;
+
+  switch (priority)
+    {
+    case OBJC_THREAD_INTERACTIVE_PRIORITY:
+      sys_priority = (PRI_FG_MIN_NP + PRI_FG_MAX_NP) / 2;
+      break;
+    default:
+    case OBJC_THREAD_BACKGROUND_PRIORITY:
+      sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
+      break;
+    case OBJC_THREAD_LOW_PRIORITY:
+      sys_priority = (PRI_BG_MIN_NP + PRI_BG_MAX_NP) / 2;
+      break;
+    }
+    
+  /* Change the priority. */
+  if (pthread_setprio(pthread_self(), sys_priority) >= 0)
+    return 0;
+  else
+    /* Failed */
+    return -1;
+}
+
+/* Return the current thread's priority. */
+static inline int
+__gthread_objc_thread_get_priority(void)
+{
+  int sys_priority;
+
+  if (__gthread_active_p ())
+    {
+      if ((sys_priority = pthread_getprio(pthread_self())) >= 0)
+        {
+	  if (sys_priority >= PRI_FG_MIN_NP
+	      && sys_priority <= PRI_FG_MAX_NP)
+	    return OBJC_THREAD_INTERACTIVE_PRIORITY;
+	  if (sys_priority >= PRI_BG_MIN_NP
+	      && sys_priority <= PRI_BG_MAX_NP)
+	    return OBJC_THREAD_BACKGROUND_PRIORITY;
+	  return OBJC_THREAD_LOW_PRIORITY;
+	}
+
+      /* Failed */
+      return -1;
+    }
+  else
+    return OBJC_THREAD_INTERACTIVE_PRIORITY;
+}
+
+/* Yield our process time to another thread. */
+static inline void
+__gthread_objc_thread_yield(void)
+{
+  if (__gthread_active_p ())
+    pthread_yield();
+}
+
+/* Terminate the current thread. */
+static inline int
+__gthread_objc_thread_exit(void)
+{
+  if (__gthread_active_p ())
+    /* exit the thread */
+    pthread_exit(&__objc_thread_exit_status);
+
+  /* Failed if we reached here */
+  return -1;
+}
+
+/* Returns an integer value which uniquely describes a thread. */
+static inline objc_thread_t
+__gthread_objc_thread_id(void)
+{
+  if (__gthread_active_p ())
+    {
+      pthread_t self = pthread_self();
+
+      return (objc_thread_t) pthread_getunique_np (&self);
+    }
+  else
+    return (objc_thread_t)1;
+}
+
+/* Sets the thread's local storage pointer. */
+static inline int
+__gthread_objc_thread_set_data(void *value)
+{
+  if (__gthread_active_p ())
+    return pthread_setspecific(_objc_thread_storage, value);
+  else
+    {
+      thread_local_storage = value;
+      return 0;
+    }
+}
+
+/* Returns the thread's local storage pointer. */
+static inline void *
+__gthread_objc_thread_get_data(void)
+{
+  void *value = NULL;
+
+  if (__gthread_active_p ())
+    {
+      if ( !(pthread_getspecific(_objc_thread_storage, &value)) )
+	return value;
+
+      return NULL;
+    }
+  else
+    return thread_local_storage;
+}
+
+/* Backend mutex functions */
+
+/* Allocate a mutex. */
+static inline int
+__gthread_objc_mutex_allocate(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ()
+      && pthread_mutex_init((pthread_mutex_t *)mutex->backend,
+      			    pthread_mutexattr_default))
+    return -1;
+
+  return 0;
+}
+
+/* Deallocate a mutex. */
+static inline int
+__gthread_objc_mutex_deallocate(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ()
+      && pthread_mutex_destroy((pthread_mutex_t *)mutex->backend))
+    return -1;
+
+  return 0;
+}
+
+/* Grab a lock on a mutex. */
+static inline int
+__gthread_objc_mutex_lock(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    return pthread_mutex_lock((pthread_mutex_t *)mutex->backend);
+  else
+    return 0;
+}
+
+/* Try to grab a lock on a mutex. */
+static inline int
+__gthread_objc_mutex_trylock(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ()
+      && pthread_mutex_trylock((pthread_mutex_t *)mutex->backend) != 1)
+    return -1;
+
+  return 0;
+}
+
+/* Unlock the mutex */
+static inline int
+__gthread_objc_mutex_unlock(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    return pthread_mutex_unlock((pthread_mutex_t *)mutex->backend);
+  else
+    return 0;
+}
+
+/* Backend condition mutex functions */
+
+/* Allocate a condition. */
+static inline int
+__gthread_objc_condition_allocate(objc_condition_t condition)
+{
+  if (__gthread_active_p ()
+    /* Unimplemented. */
+    return -1;
+  else
+    return 0;
+}
+
+/* Deallocate a condition. */
+static inline int
+__gthread_objc_condition_deallocate(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    /* Unimplemented. */
+    return -1;
+  else
+    return 0;
+}
+
+/* Wait on the condition */
+static inline int
+__gthread_objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    /* Unimplemented. */
+    return -1;
+  else
+    return 0;
+}
+
+/* Wake up all threads waiting on this condition. */
+static inline int
+__gthread_objc_condition_broadcast(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    /* Unimplemented. */
+    return -1;
+  else
+    return 0;
+}
+
+/* Wake up one thread waiting on this condition. */
+static inline int
+__gthread_objc_condition_signal(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    /* Unimplemented. */
+    return -1;
+  else
+    return 0;
+}
+
+#else /* _LIBOBJC */
+
+static inline int
 __gthread_once (__gthread_once_t *once, void (*func) ())
 {
   if (__gthread_active_p ())
@@ -146,5 +453,7 @@ __gthread_mutex_unlock (__gthread_mutex_
   else
     return 0;
 }
+
+#endif /* _LIBOBJC */
 
 #endif /* not __gthr_dce_h */
Index: gcc/gthr-posix.h
===================================================================
RCS file: /work/cvs/gnu/egcs/gcc/gthr-posix.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 gthr-posix.h
--- gcc/gthr-posix.h	1998/01/09 17:37:17	1.1.1.1
+++ gcc/gthr-posix.h	1999/07/11 18:18:31
@@ -1,6 +1,6 @@
-/* Threads compatibily routines for libgcc2.  */
+/* Threads compatibily routines for libgcc2 and libobjc.  */
 /* Compile this one with gcc.  */
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -56,6 +56,20 @@ typedef pthread_mutex_t __gthread_mutex_
 #pragma weak pthread_mutex_trylock 
 #pragma weak pthread_mutex_unlock 
 
+#ifdef _LIBOBJC
+/* Objective C. */
+#pragma weak pthread_cond_broadcast
+#pragma weak pthread_cond_destroy
+#pragma weak pthread_cond_init
+#pragma weak pthread_cond_signal
+#pragma weak pthread_cond_wait
+#pragma weak pthread_exit
+#pragma weak pthread_mutex_init
+#pragma weak pthread_mutex_destroy
+#pragma weak pthread_self
+#pragma weak sched_yield
+#endif
+
 static void *__gthread_active_ptr = &pthread_create;
 
 static inline int
@@ -74,7 +88,269 @@ __gthread_active_p ()
 
 #endif /* SUPPORTS_WEAK */
 
+#ifdef _LIBOBJC
+
+/* Key structure for maintaining thread specific storage */
+static pthread_key_t _objc_thread_storage;
+
+/* Thread local storage for a single thread */
+static void *thread_local_storage = NULL;
+
+/* Backend initialization functions */
+
+/* Initialize the threads subsystem. */
+static inline int
+__gthread_objc_init_thread_system(void)
+{
+  if (__gthread_active_p ())
+    /* Initialize the thread storage key */
+    return pthread_key_create(&_objc_thread_storage, NULL);
+  else
+    return -1;
+}
+
+/* Close the threads subsystem. */
+static inline int
+__gthread_objc_close_thread_system(void)
+{
+  if (__gthread_active_p ())
+    return 0;
+  else
+    return -1;
+}
+
+/* Backend thread functions */
+
+/* Create a new thread of execution. */
+static inline objc_thread_t
+__gthread_objc_thread_detach(void (*func)(void *), void *arg)
+{
+  objc_thread_t thread_id;
+  pthread_t new_thread_handle;
+
+  if (!__gthread_active_p ())
+    return NULL;
+ 
+  if ( !(pthread_create(&new_thread_handle, NULL, (void *)func, arg)) )
+    thread_id = *(objc_thread_t *)&new_thread_handle;
+  else
+    thread_id = NULL;
+  
+  return thread_id;
+}
+
+/* Set the current thread's priority. */
+static inline int
+__gthread_objc_thread_set_priority(int priority)
+{
+  /* Not implemented yet */
+  return -1;
+}
+
+/* Return the current thread's priority. */
+static inline int
+__gthread_objc_thread_get_priority(void)
+{
+  if (__gthread_active_p ())
+    /* Not implemented yet */
+    return -1;
+  else
+    return OBJC_THREAD_INTERACTIVE_PRIORITY;
+}
+
+/* Yield our process time to another thread. */
+static inline void
+__gthread_objc_thread_yield(void)
+{
+  if (__gthread_active_p ())
+    sched_yield();
+}
+
+/* Terminate the current thread. */
+static inline int
+__gthread_objc_thread_exit(void)
+{
+  if (__gthread_active_p ())
+    /* exit the thread */
+    pthread_exit(&__objc_thread_exit_status);
+
+  /* Failed if we reached here */
+  return -1;
+}
+
+/* Returns an integer value which uniquely describes a thread. */
+static inline objc_thread_t
+__gthread_objc_thread_id(void)
+{
+  if (__gthread_active_p ())
+    {
+      pthread_t self = pthread_self();
+
+      return *(objc_thread_t *)&self;
+    }
+  else
+    return (objc_thread_t)1;
+}
+
+/* Sets the thread's local storage pointer. */
 static inline int
+__gthread_objc_thread_set_data(void *value)
+{
+  if (__gthread_active_p ())
+    return pthread_setspecific(_objc_thread_storage, value);
+  else
+    {
+      thread_local_storage = value;
+      return 0;
+    }
+}
+
+/* Returns the thread's local storage pointer. */
+static inline void *
+__gthread_objc_thread_get_data(void)
+{
+  if (__gthread_active_p ())
+    return pthread_getspecific(_objc_thread_storage);
+  else
+    return thread_local_storage;
+}
+
+/* Backend mutex functions */
+
+/* Allocate a mutex. */
+static inline int
+__gthread_objc_mutex_allocate(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    {
+      mutex->backend = objc_malloc(sizeof(pthread_mutex_t));
+
+      if (pthread_mutex_init((pthread_mutex_t *)mutex->backend, NULL))
+	{
+	  objc_free(mutex->backend);
+	  mutex->backend = NULL;
+	  return -1;
+	}
+    }
+
+  return 0;
+}
+
+/* Deallocate a mutex. */
+static inline int
+__gthread_objc_mutex_deallocate(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    {
+      if (pthread_mutex_destroy((pthread_mutex_t *)mutex->backend))
+	return -1;
+
+      objc_free(mutex->backend);
+      mutex->backend = NULL;
+    }
+  return 0;
+}
+
+/* Grab a lock on a mutex. */
+static inline int
+__gthread_objc_mutex_lock(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    return pthread_mutex_lock((pthread_mutex_t *)mutex->backend);
+  else
+    return 0;
+}
+
+/* Try to grab a lock on a mutex. */
+static inline int
+__gthread_objc_mutex_trylock(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    return pthread_mutex_trylock((pthread_mutex_t *)mutex->backend);
+  else
+    return 0;
+}
+
+/* Unlock the mutex */
+static inline int
+__gthread_objc_mutex_unlock(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    return pthread_mutex_unlock((pthread_mutex_t *)mutex->backend);
+  else
+    return 0;
+}
+
+/* Backend condition mutex functions */
+
+/* Allocate a condition. */
+static inline int
+__gthread_objc_condition_allocate(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    {
+      condition->backend = objc_malloc(sizeof(pthread_cond_t));
+
+      if (pthread_cond_init((pthread_cond_t *)condition->backend, NULL))
+	{
+	  objc_free(condition->backend);
+	  condition->backend = NULL;
+	  return -1;
+	}
+    }
+
+  return 0;
+}
+
+/* Deallocate a condition. */
+static inline int
+__gthread_objc_condition_deallocate(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    {
+      if (pthread_cond_destroy((pthread_cond_t *)condition->backend))
+	return -1;
+
+      objc_free(condition->backend);
+      condition->backend = NULL;
+    }
+  return 0;
+}
+
+/* Wait on the condition */
+static inline int
+__gthread_objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    return pthread_cond_wait((pthread_cond_t *)condition->backend,
+			   (pthread_mutex_t *)mutex->backend);
+  else
+    return 0;
+}
+
+/* Wake up all threads waiting on this condition. */
+static inline int
+__gthread_objc_condition_broadcast(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    return pthread_cond_broadcast((pthread_cond_t *)condition->backend);
+  else
+    return 0;
+}
+
+/* Wake up one thread waiting on this condition. */
+static inline int
+__gthread_objc_condition_signal(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    return pthread_cond_signal((pthread_cond_t *)condition->backend);
+  else
+    return 0;
+}
+
+#else /* _LIBOBJC */
+
+static inline int
 __gthread_once (__gthread_once_t *once, void (*func) ())
 {
   if (__gthread_active_p ())
@@ -143,5 +419,7 @@ __gthread_mutex_unlock (__gthread_mutex_
   else
     return 0;
 }
+
+#endif /* _LIBOBJC */
 
 #endif /* not __gthr_posix_h */
Index: gcc/gthr-solaris.h
===================================================================
RCS file: /work/cvs/gnu/egcs/gcc/gthr-solaris.h,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 gthr-solaris.h
--- gcc/gthr-solaris.h	1998/03/12 17:18:36	1.1.1.2
+++ gcc/gthr-solaris.h	1999/07/11 18:56:35
@@ -1,6 +1,6 @@
-/* Threads compatibily routines for libgcc2.  */
+/* Threads compatibily routines for libgcc2 and libobjc.  */
 /* Compile this one with gcc.  */
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -60,6 +60,24 @@ typedef mutex_t __gthread_mutex_t;
 #pragma weak mutex_trylock
 #pragma weak mutex_unlock
 
+#ifdef _LIBOBJC
+#pragma weak thr_exit
+#pragma weak thr_keycreate
+#pragma weak thr_getprio
+#pragma weak thr_self
+#pragma weak thr_setprio
+#pragma weak thr_yield
+
+#pragma weak cond_init
+#pragma weak cond_destroy
+#pragma weak cond_wait
+#pragma weak cond_broadcast
+#pragma weak cond_signal
+
+#pragma weak mutex_init
+#pragma weak mutex_destroy
+#endif
+
 /* This will not actually work in Solaris 2.5, since libc contains
    dummy symbols of all thr_* routines. */
 
@@ -81,6 +99,289 @@ __gthread_active_p ()
 
 #endif /* SUPPORTS_WEAK */
 
+#ifdef _LIBOBJC
+
+/* Key structure for maintaining thread specific storage */
+static thread_key_t _objc_thread_storage;
+
+/* Thread local storage for a single thread */
+static void *thread_local_storage = NULL;
+
+/* Backend initialization functions */
+
+/* Initialize the threads subsystem. */
+static inline int
+__gthread_objc_init_thread_system(void)
+{
+  /* Initialize the thread storage key */
+  if (__gthread_active_p ()
+      && thr_keycreate(&_objc_thread_storage, NULL) == 0)
+    return 0;
+
+  return -1;
+}
+
+/* Close the threads subsystem. */
+static inline int
+__gthread_objc_close_thread_system(void)
+{
+  if (__gthread_active_p ())
+    return 0;
+  else
+    return -1;
+}
+
+/* Backend thread functions */
+
+/* Create a new thread of execution. */
+static inline objc_thread_t
+__gthread_objc_thread_detach(void (*func)(void *), void *arg)
+{
+  objc_thread_t thread_id;
+  thread_t new_thread_id = 0;
+
+  if (!__gthread_active_p ())
+    return NULL;
+ 
+  if (thr_create(NULL, 0, (void *)func, arg,
+  		 THR_DETACHED | THR_NEW_LWP,
+		 &new_thread_id) == 0)
+    thread_id = *(objc_thread_t *)&new_thread_id;
+  else
+    thread_id = NULL;
+  
+  return thread_id;
+}
+
+/* Set the current thread's priority. */
+static inline int
+__gthread_objc_thread_set_priority(int priority)
+{
+  int sys_priority = 0;
+
+  if (!__gthread_active_p ())
+    return -1;
+
+  switch (priority)
+    {
+    case OBJC_THREAD_INTERACTIVE_PRIORITY:
+      sys_priority = 300;
+      break;
+    default:
+    case OBJC_THREAD_BACKGROUND_PRIORITY:
+      sys_priority = 200;
+      break;
+    case OBJC_THREAD_LOW_PRIORITY:
+      sys_priority = 1000;
+      break;
+    }
+
+  /* Change priority */
+  if (thr_setprio(thr_self(), sys_priority) == 0)
+    return 0;
+  else
+    return -1;
+}
+
+/* Return the current thread's priority. */
+static inline int
+__gthread_objc_thread_get_priority(void)
+{
+  int sys_priority;
+
+  if (!__gthread_active_p ())
+    return OBJC_THREAD_INTERACTIVE_PRIORITY;
+                                                   
+  if (thr_getprio(thr_self(), &sys_priority) == 0)
+    {
+      if (sys_priority >= 250)
+	return OBJC_THREAD_INTERACTIVE_PRIORITY;
+      else if (sys_priority >= 150)
+	return OBJC_THREAD_BACKGROUND_PRIORITY;
+      return OBJC_THREAD_LOW_PRIORITY;
+    }
+
+  /* Couldn't get priority. */
+  return -1;
+}
+
+/* Yield our process time to another thread. */
+static inline void
+__gthread_objc_thread_yield(void)
+{
+  if (__gthread_active_p ())
+    thr_yield();
+}
+
+/* Terminate the current thread. */
+static inline int
+__gthread_objc_thread_exit(void)
+{
+  if (__gthread_active_p ())
+    /* exit the thread */
+    thr_exit(&__objc_thread_exit_status);
+
+  /* Failed if we reached here */
+  return -1;
+}
+
+/* Returns an integer value which uniquely describes a thread. */
+static inline objc_thread_t
+__gthread_objc_thread_id(void)
+{
+  if (__gthread_active_p ())
+    return (objc_thread_t)thr_self();
+  else
+    return (objc_thread_t)1;
+}
+
+/* Sets the thread's local storage pointer. */
+static inline int
+__gthread_objc_thread_set_data(void *value)
+{
+  if (__gthread_active_p ())
+    {
+      if (thr_setspecific(_objc_thread_storage, value) == 0)
+	return 0;
+      else
+	return -1;
+    }
+  else
+    {
+      thread_local_storage = value;
+      return 0;
+    }
+}
+
+/* Returns the thread's local storage pointer. */
+static inline void *
+__gthread_objc_thread_get_data(void)
+{
+  void *value = NULL;
+
+  if (__gthread_active_p ())
+    {
+      if (thr_getspecific(_objc_thread_storage, &value) == 0)
+	return value;
+      else
+	return NULL;
+    }
+  else
+    return thread_local_storage;
+}
+
+/* Backend mutex functions */
+
+/* Allocate a mutex. */
+static inline int
+__gthread_objc_mutex_allocate(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ()
+      && mutex_init( (mutex_t *)(&(mutex->backend)), USYNC_THREAD, 0))
+    return -1;
+
+  return 0;
+}
+
+/* Deallocate a mutex. */
+static inline int
+__gthread_objc_mutex_deallocate(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    mutex_destroy((mutex_t *)(&(mutex->backend)));
+
+  return 0;
+}
+
+/* Grab a lock on a mutex. */
+static inline int
+__gthread_objc_mutex_lock(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ()
+      && mutex_lock((mutex_t *)(&(mutex->backend))) != 0)
+    return -1;
+
+  return 0;
+}
+
+/* Try to grab a lock on a mutex. */
+static inline int
+__gthread_objc_mutex_trylock(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ()
+      && mutex_trylock((mutex_t *)(&(mutex->backend))) != 0)
+    return -1;
+
+  return 0;
+}
+
+/* Unlock the mutex */
+static inline int
+__gthread_objc_mutex_unlock(objc_mutex_t mutex)
+{
+  if (__gthread_active_p ()
+      && mutex_unlock((mutex_t *)(&(mutex->backend))) != 0)
+    return -1;
+
+  return 0;
+}
+
+/* Backend condition mutex functions */
+
+/* Allocate a condition. */
+static inline int
+__gthread_objc_condition_allocate(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    return cond_init((cond_t *)(&(condition->backend)), USYNC_THREAD,
+    		     NULL);
+  else
+    return 0;
+}
+
+/* Deallocate a condition. */
+static inline int
+__gthread_objc_condition_deallocate(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    return cond_destroy((cond_t *)(&(condition->backend)));
+  else
+    return 0;
+}
+
+/* Wait on the condition */
+static inline int
+__gthread_objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
+{
+  if (__gthread_active_p ())
+    return cond_wait((cond_t *)(&(condition->backend)),
+    		     (mutex_t *)(&(mutex->backend)));
+  else
+    return 0;
+}
+
+/* Wake up all threads waiting on this condition. */
+static inline int
+__gthread_objc_condition_broadcast(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    return cond_broadcast((cond_t *)(&(condition->backend)));
+  else
+    return 0;
+}
+
+/* Wake up one thread waiting on this condition. */
+static inline int
+__gthread_objc_condition_signal(objc_condition_t condition)
+{
+  if (__gthread_active_p ())
+    return cond_signal((cond_t *)(&(condition->backend)));
+  else
+    return 0;
+}
+
+#else /* _LIBOBJC */
+
 static inline int
 __gthread_once (__gthread_once_t *once, void (*func) ())
 {
@@ -173,5 +474,7 @@ __gthread_mutex_unlock (__gthread_mutex_
   else
     return 0;
 }
+
+#endif /* _LIBOBJC */
 
 #endif /* not __gthr_solaris_h */
Index: gcc/gthr-vxworks.h
===================================================================
RCS file: /work/cvs/gnu/egcs/gcc/gthr-vxworks.h,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 gthr-vxworks.h
--- gcc/gthr-vxworks.h	1998/12/04 20:03:45	1.1.1.2
+++ gcc/gthr-vxworks.h	1999/07/11 19:10:24
@@ -1,6 +1,6 @@
-/* Threads compatibily routines for libgcc2 for VxWorks.  */
+/* Threads compatibily routines for libgcc2 and libobjc for VxWorks.  */
 /* Compile this one with gcc.  */
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
    Contributed by Mike Stump <mrs@wrs.com>.
 
 This file is part of GNU CC.
@@ -30,6 +30,172 @@ Boston, MA 02111-1307, USA.  */
 #ifndef __gthr_vxworks_h
 #define __gthr_vxworks_h
 
+#ifdef _LIBOBJC
+
+/* Thread local storage for a single thread */
+static void *thread_local_storage = NULL;
+
+/* Backend initialization functions */
+
+/* Initialize the threads subsystem. */
+int
+__gthread_objc_init_thread_system(void)
+{
+  /* No thread support available */
+  return -1;
+}
+
+/* Close the threads subsystem. */
+int
+__gthread_objc_close_thread_system(void)
+{
+  /* No thread support available */
+  return -1;
+}
+
+/* Backend thread functions */
+
+/* Create a new thread of execution. */
+objc_thread_t
+__gthread_objc_thread_detach(void (*func)(void *arg), void *arg)
+{
+  /* No thread support available */
+  return NULL;
+}
+
+/* Set the current thread's priority. */
+int
+__gthread_objc_thread_set_priority(int priority)
+{
+  /* No thread support available */
+  return -1;
+}
+
+/* Return the current thread's priority. */
+int
+__gthread_objc_thread_get_priority(void)
+{
+  return OBJC_THREAD_INTERACTIVE_PRIORITY;
+}
+
+/* Yield our process time to another thread. */
+void
+__gthread_objc_thread_yield(void)
+{
+  return;
+}
+
+/* Terminate the current thread. */
+int
+__gthread_objc_thread_exit(void)
+{
+  /* No thread support available */
+  /* Should we really exit the program */
+  /* exit(&__objc_thread_exit_status); */
+  return -1;
+}
+
+/* Returns an integer value which uniquely describes a thread. */
+objc_thread_t
+__gthread_objc_thread_id(void)
+{
+  /* No thread support, use 1. */
+  return (objc_thread_t)1;
+}
+
+/* Sets the thread's local storage pointer. */
+int
+__gthread_objc_thread_set_data(void *value)
+{
+  thread_local_storage = value;
+  return 0;
+}
+
+/* Returns the thread's local storage pointer. */
+void *
+__gthread_objc_thread_get_data(void)
+{
+  return thread_local_storage;
+}
+
+/* Backend mutex functions */
+
+/* Allocate a mutex. */
+int
+__gthread_objc_mutex_allocate(objc_mutex_t mutex)
+{
+  return 0;
+}
+
+/* Deallocate a mutex. */
+int
+__gthread_objc_mutex_deallocate(objc_mutex_t mutex)
+{
+  return 0;
+}
+
+/* Grab a lock on a mutex. */
+int
+__gthread_objc_mutex_lock(objc_mutex_t mutex)
+{
+  /* There can only be one thread, so we always get the lock */
+  return 0;
+}
+
+/* Try to grab a lock on a mutex. */
+int
+__gthread_objc_mutex_trylock(objc_mutex_t mutex)
+{
+  /* There can only be one thread, so we always get the lock */
+  return 0;
+}
+
+/* Unlock the mutex */
+int
+__gthread_objc_mutex_unlock(objc_mutex_t mutex)
+{
+  return 0;
+}
+
+/* Backend condition mutex functions */
+
+/* Allocate a condition. */
+int
+__gthread_objc_condition_allocate(objc_condition_t condition)
+{
+  return 0;
+}
+
+/* Deallocate a condition. */
+int
+__gthread_objc_condition_deallocate(objc_condition_t condition)
+{
+  return 0;
+}
+
+/* Wait on the condition */
+int
+__gthread_objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
+{
+  return 0;
+}
+
+/* Wake up all threads waiting on this condition. */
+int
+__gthread_objc_condition_broadcast(objc_condition_t condition)
+{
+  return 0;
+}
+
+/* Wake up one thread waiting on this condition. */
+int
+__gthread_objc_condition_signal(objc_condition_t condition)
+{
+  return 0;
+}
+
+#else /* _LIBOBJC */
+
 /* POSIX threads specific definitions.
    Easy, since the interface is just one-to-one mapping. */
 
@@ -138,5 +304,7 @@ __gthread_mutex_unlock (__gthread_mutex_
   /* We could return the */
   return semGive (*mutex);
 }
+
+#endif /* _LIBOBJC */
 
 #endif /* not __gthr_vxworks_h */


More information about the Gcc-patches mailing list