Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDick Porter <dick@acm.org>2001-10-05 16:15:07 +0400
committerDick Porter <dick@acm.org>2001-10-05 16:15:07 +0400
commitbc3c9f9944cc0e57c69e70ed72312c5a171ae8d3 (patch)
tree304928d37c0fcd5f061fcabcc6451eb7fa70bc90
parentd660164d3811b1ead8f5b84be086d52b2278d591 (diff)
2001-10-05 Dick Porter <dick@ximian.com>
* threads-pthread.c (pthread_mutex_timedlock): Simple compatibility version for C libraries that lack this call. svn path=/trunk/mono/; revision=1096
-rw-r--r--configure.in1
-rw-r--r--mono/metadata/ChangeLog4
-rw-r--r--mono/metadata/threads-pthread.c42
3 files changed, 39 insertions, 8 deletions
diff --git a/configure.in b/configure.in
index 3b7de9c95d6..666589b9a71 100644
--- a/configure.in
+++ b/configure.in
@@ -74,7 +74,6 @@ AC_CHECK_LIB(pthread, pthread_create, [
], [
AC_MSG_RESULT(no)
dnl Add other variants here
- #AC_MSG_ERROR(Need pthread_mutex_timedlock)
AC_MSG_WARN(Working around pthread_mutex_timedlock)
])
])
diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog
index 2debf817dd2..f1d96ae256c 100644
--- a/mono/metadata/ChangeLog
+++ b/mono/metadata/ChangeLog
@@ -1,3 +1,7 @@
+2001-10-05 Dick Porter <dick@ximian.com>
+
+ * threads-pthread.c (pthread_mutex_timedlock): Simple
+ compatibility version for C libraries that lack this call.
Thu Oct 4 19:10:30 CEST 2001 Paolo Molaro <lupus@ximian.com>
diff --git a/mono/metadata/threads-pthread.c b/mono/metadata/threads-pthread.c
index 3fd2b664309..9062dc30f54 100644
--- a/mono/metadata/threads-pthread.c
+++ b/mono/metadata/threads-pthread.c
@@ -59,6 +59,41 @@ typedef struct
static pthread_mutex_t data_slots_mutex;
static GHashTable *data_slots=NULL;
+#ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
+/*
+ * This stuff should go in a separate support code library if it gets any
+ * bigger.
+ */
+
+/*
+ * Implementation of timed mutex locking also from the P1003.1d/D14
+ * (July 1999) draft spec, figure B-4.
+ */
+static int pthread_mutex_timedlock(pthread_mutex_t *mutex,
+ const struct timespec *timeout)
+{
+ struct timeval timenow;
+ struct timespec sleepytime;
+
+ /* This is just to avoid a completely busy wait */
+ sleepytime.tv_sec=0;
+ sleepytime.tv_nsec=10000; /* 10ms */
+
+ while(pthread_mutex_trylock(mutex)==EBUSY) {
+ gettimeofday(&timenow, NULL);
+
+ if(timenow.tv_sec >= timeout->tv_sec &&
+ timenow.tv_usec >= (timeout->tv_nsec * 1000)) {
+ return(ETIMEDOUT);
+ }
+
+ nanosleep(&sleepytime, NULL);
+ }
+
+ return(0);
+}
+#endif /* !HAVE_PTHREAD_MUTEX_TIMEDLOCK */
+
static void timed_thread_init()
{
pthread_key_create(&timed_thread_key, NULL);
@@ -656,11 +691,6 @@ gboolean ves_icall_System_Threading_Monitor_Monitor_try_enter(MonoObject *obj,
return(TRUE);
}
-#ifndef HAVE_PTHREAD_MUTEX_TIMEDLOCK
- /* Nasty temporary kludge to work around older pthreads */
-#warning("Limiting Try_Enter(timeout) because of missing pthread_mutex_timedlock()");
- ms=0;
-#endif
if(ms==0) {
ret=pthread_mutex_trylock(&obj->synchronisation.mutex);
if(ret==0) {
@@ -675,7 +705,6 @@ gboolean ves_icall_System_Threading_Monitor_Monitor_try_enter(MonoObject *obj,
return(FALSE);
}
} else {
-#ifdef HAVE_PTHREAD_MUTEX_TIMEDLOCK
struct timespec timeout;
struct timeval now;
div_t divvy;
@@ -699,7 +728,6 @@ gboolean ves_icall_System_Threading_Monitor_Monitor_try_enter(MonoObject *obj,
#endif
return(FALSE);
}
-#endif /* HAVE_PTHREAD_MUTEX_TIMEDLOCK */
}
}