This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

ObjC runtime patch adds obcj_condition_timedwait


Once again, I'm sending you the patch which is already used by GNUSTEP.

It adds the function objc_condition_timedwait to the objC runtime. I've
used the patched runtime on a heavily multithreaded program and haven't
had any problems ( it's just a functionwrapper anyway ).

Please install this patch to gcc sources asap, that GnuStep developers
don't have to patch gcc when installing gcc.

Thanx in advance - Patrick


diff -Naur libobjc.orig/THREADS libobjc/THREADS
--- libobjc.orig/THREADS	Thu Sep 17 10:04:29 1998
+++ libobjc/THREADS	Fri Aug 27 13:13:12 1999
@@ -334,6 +334,17 @@
 	The mutex is used to lock access to the shared data that make up the
 	"condition" predicate.
 	Return -1 if error otherwise return 0.
+
+objc_condition_timedwait( objc_condition_t condition, objc_mutex_t mutex, 
+				const struct timespec *abstime), int
+	Wait on the condition like objc_condition_wait() does, but it also bounds
+	the duration of the wait. If cond has not been signaled within the amount
+	of time specified by abstime, the mutex mutex is re-acquired and retuns that
+	the condition was not met.
+	Return  ETIMEDOUT the condition variable was not signaled until the timeout
+			  specified by abstime.
+	Return	0	  condition variable was signaled within the time.
+	Return  errno     from native function otherwise.
 	
 objc_condition_broadcast(objc_condition_t condition), int
 	Wake up all threads waiting on this condition. It is recommended that 
diff -Naur libobjc.orig/confdefs.h libobjc/confdefs.h
--- libobjc.orig/confdefs.h	Thu Jan  1 01:00:00 1970
+++ libobjc/confdefs.h	Fri Aug 27 13:31:31 1999
@@ -0,0 +1 @@
+
diff -Naur libobjc.orig/config.cache libobjc/config.cache
--- libobjc.orig/config.cache	Thu Jan  1 01:00:00 1970
+++ libobjc/config.cache	Fri Aug 27 13:46:01 1999
@@ -0,0 +1,25 @@
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs.  It is not useful on other systems.
+# If it contains results you don't want to keep, you may remove or edit it.
+#
+# By default, configure uses ./config.cache as the cache file,
+# creating it if it does not exist already.  You can give configure
+# the --cache-file=FILE option to use a different cache file; that is
+# what configure does when it calls configure scripts in
+# subdirectories, so they share the cache.
+# Giving --cache-file=/dev/null disables caching, for debugging configure.
+# config.status only pays attention to the cache file if you give it the
+# --recheck option to rerun configure.
+#
+ac_cv_header_stdc=${ac_cv_header_stdc='yes'}
+ac_cv_header_stdio_h=${ac_cv_header_stdio_h='yes'}
+ac_cv_path_install=${ac_cv_path_install='/usr/bin/install -c'}
+ac_cv_prog_CC=${ac_cv_prog_CC='/Users/jolly/tmp/gcc-2.95.1/gcc/xgcc -B/Users/jolly/tmp/gcc-2.95.1/gcc/ -B/usr/i686-pc-linux-gnu/bin/'}
+ac_cv_prog_CPP=${ac_cv_prog_CPP='/Users/jolly/tmp/gcc-2.95.1/gcc/xgcc -B/Users/jolly/tmp/gcc-2.95.1/gcc/ -B/usr/i686-pc-linux-gnu/bin/ -E'}
+ac_cv_prog_cc_cross=${ac_cv_prog_cc_cross='no'}
+ac_cv_prog_cc_g=${ac_cv_prog_cc_g='yes'}
+ac_cv_prog_cc_works=${ac_cv_prog_cc_works='yes'}
+ac_cv_prog_gcc=${ac_cv_prog_gcc='yes'}
+objc_cv_compiler_exists=${objc_cv_compiler_exists='yes'}
+objc_cv_thread_file=${objc_cv_thread_file='posix'}
diff -Naur libobjc.orig/config.log libobjc/config.log
--- libobjc.orig/config.log	Thu Jan  1 01:00:00 1970
+++ libobjc/config.log	Sat Aug 28 17:50:51 1999
@@ -0,0 +1,14 @@
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+configure:566: checking if compiler cc1obj has been built
+configure:597: checking for gcc
+configure:710: checking whether the C compiler (/Users/jolly/tmp/gcc-2.95.1/gcc/xgcc -B/Users/jolly/tmp/gcc-2.95.1/gcc/ -B/usr/i686-pc-linux-gnu/bin/ -g -O2 ) works
+configure:726: /Users/jolly/tmp/gcc-2.95.1/gcc/xgcc -B/Users/jolly/tmp/gcc-2.95.1/gcc/ -B/usr/i686-pc-linux-gnu/bin/ -o conftest -g -O2   conftest.c  1>&5
+./configure: /Users/jolly/tmp/gcc-2.95.1/gcc/xgcc: No such file or directory
+configure: failed program was:
+
+#line 721 "configure"
+#include "confdefs.h"
+
+main(){return(0);}
diff -Naur libobjc.orig/objc/thr.h libobjc/objc/thr.h
--- libobjc.orig/objc/thr.h	Wed Sep 30 10:17:56 1998
+++ libobjc/objc/thr.h	Fri Aug 27 13:13:28 1999
@@ -1,6 +1,7 @@
 /* Thread and mutex controls for Objective C.
    Copyright (C) 1996, 1997 Free Software Foundation, Inc.
    Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
+   Added condition_timed_wait by Patrick Stein <jolly@jinx.de>
 
 This file is part of GNU CC.
 
@@ -37,7 +38,7 @@
 
 #ifndef __thread_INCLUDE_GNU
 #define __thread_INCLUDE_GNU
-
+#include <time.h>			// this is for struct timespec *
 #include "objc/objc.h"
 
 /*************************************************************************
@@ -84,6 +85,7 @@
 objc_condition_t objc_condition_allocate(void);
 int objc_condition_deallocate(objc_condition_t condition);
 int objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex);
+int objc_condition_timedwait(objc_condition_t condition, objc_mutex_t mutex,const struct timespec *timeout);
 int objc_condition_signal(objc_condition_t condition);
 int objc_condition_broadcast(objc_condition_t condition);
 
@@ -127,6 +129,7 @@
 int __objc_condition_allocate(objc_condition_t condition);
 int __objc_condition_deallocate(objc_condition_t condition);
 int __objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex);
+int __objc_condition_timedwait(objc_condition_t condition, objc_mutex_t mutex,const struct timespec *timeout);
 int __objc_condition_broadcast(objc_condition_t condition);
 int __objc_condition_signal(objc_condition_t condition);
 
diff -Naur libobjc.orig/thr-posix.c libobjc/thr-posix.c
--- libobjc.orig/thr-posix.c	Mon Sep 21 03:22:07 1998
+++ libobjc/thr-posix.c	Fri Aug 27 13:13:12 1999
@@ -25,6 +25,7 @@
    however invalidate any other reasons why the executable file might be
    covered by the GNU General Public License.  */
 
+#include <errno.h>
 #include <objc/thr.h>
 #include "runtime.h"
 #include <pthread.h>
@@ -210,6 +211,15 @@
 {
   return pthread_cond_wait((pthread_cond_t *)condition->backend,
 			   (pthread_mutex_t *)mutex->backend);
+}
+
+/* Wait on the condition till an enddate */
+int
+__objc_condition_timedwait(objc_condition_t condition, objc_mutex_t mutex,const struct timespec *timeout)
+{
+	return pthread_cond_timedwait((pthread_cond_t *)condition->backend,
+					(pthread_mutex_t *)mutex->backend,
+					(const struct timespec *)timeout);
 }
 
 /* Wake up all threads waiting on this condition. */
diff -Naur libobjc.orig/thr-single.c libobjc/thr-single.c
--- libobjc.orig/thr-single.c	Mon Sep 21 03:22:07 1998
+++ libobjc/thr-single.c	Fri Aug 27 13:13:12 1999
@@ -175,6 +175,13 @@
   return 0;
 }
 
+/* Wait on the condition till an enddate */
+int
+__objc_condition_timedwait(objc_condition_t condition, objc_mutex_t mutex, struct timespec *abstime)
+{
+  return 0;
+}
+
 /* Wake up all threads waiting on this condition. */
 int
 __objc_condition_broadcast(objc_condition_t condition)
diff -Naur libobjc.orig/thr.c libobjc/thr.c
--- libobjc.orig/thr.c	Mon Sep 21 03:22:07 1998
+++ libobjc/thr.c	Fri Aug 27 13:13:12 1999
@@ -1,7 +1,8 @@
 /* GNU Objective C Runtime Thread Interface
    Copyright (C) 1996, 1997 Free Software Foundation, Inc.
    Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
-
+   Added condition_timed_wait by Patrick Stein <jolly@jinx.de>
+   
 This file is part of GNU CC.
 
 GNU CC is free software; you can redistribute it and/or modify it under the
@@ -497,6 +498,39 @@
   mutex->depth = 1;
 
   return 0;
+}
+
+int
+objc_condition_timedwait(objc_condition_t condition, objc_mutex_t mutex,const struct timespec *timeout)
+{
+  objc_thread_t thread_id;
+  int value;
+
+  /* Valid arguments? */
+  if (!mutex || !condition)
+    return -1;
+
+  /* Make sure we are owner of mutex */
+  thread_id = objc_thread_id();
+  if (mutex->owner != thread_id)
+    return -1;
+
+  /* Cannot be locked more than once */
+  if (mutex->depth > 1)
+    return -1;
+
+  /* Virtually unlock the mutex */
+  mutex->depth = 0;
+  mutex->owner = (objc_thread_t)NULL;
+
+  /* Call the backend to wait */
+  value = __objc_condition_timedwait(condition, mutex, timeout);
+
+  /* Make ourselves owner of the mutex */
+  mutex->owner = thread_id;
+  mutex->depth = 1;
+
+  return value;
 }
 
 /*

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]