summaryrefslogtreecommitdiffstats
path: root/lib/libthr
diff options
context:
space:
mode:
authormtm <mtm@FreeBSD.org>2003-12-30 08:44:55 +0000
committermtm <mtm@FreeBSD.org>2003-12-30 08:44:55 +0000
commit81dc42d3d9b547927cf8cb3d68345c9c09538b65 (patch)
treec494713f2d572e1958d88dfaaa98a84ff1673426 /lib/libthr
parentd4f59be550779a187578dac62baf0161eb09aa64 (diff)
downloadFreeBSD-src-81dc42d3d9b547927cf8cb3d68345c9c09538b65.zip
FreeBSD-src-81dc42d3d9b547927cf8cb3d68345c9c09538b65.tar.gz
o Implement pthread_mutex_timedlock(), which does not block indefinitely on
a mutex locked by another thread. o document it: pthread_mutex_timedlock(3)
Diffstat (limited to 'lib/libthr')
-rw-r--r--lib/libthr/thread/thr_mutex.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c
index 33958b7..3567a34 100644
--- a/lib/libthr/thread/thr_mutex.c
+++ b/lib/libthr/thread/thr_mutex.c
@@ -93,6 +93,7 @@ __weak_reference(__pthread_mutex_unlock, pthread_mutex_unlock);
/* No difference between libc and application usage of these: */
__weak_reference(_pthread_mutex_init, pthread_mutex_init);
__weak_reference(_pthread_mutex_destroy, pthread_mutex_destroy);
+__weak_reference(_pthread_mutex_timedlock, pthread_mutex_timedlock);
/*
@@ -556,6 +557,28 @@ _pthread_mutex_lock(pthread_mutex_t *mutex)
}
int
+_pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
+{
+ int error;
+
+ error = 0;
+ if (_thread_initial == NULL)
+ _thread_init();
+
+ /*
+ * Initialize it if it's a valid statically inited mutex.
+ */
+ if (mutex == NULL)
+ error = EINVAL;
+ else if ((*mutex != PTHREAD_MUTEX_INITIALIZER) ||
+ ((error = mutex_init(mutex, 0)) == 0))
+ error = mutex_lock_common(mutex, 0, abstime);
+
+ PTHREAD_ASSERT(error != EINTR, "According to SUSv3 this function shall not return an error code of EINTR");
+ return (error);
+}
+
+int
__pthread_mutex_unlock(pthread_mutex_t * mutex)
{
return (mutex_unlock_common(mutex, /* add reference */ 0));
@@ -1418,6 +1441,15 @@ get_mcontested(pthread_mutex_t mutexp, const struct timespec *abstime)
int error;
/*
+ * If the timeout is invalid this thread is not allowed
+ * to block;
+ */
+ if (abstime != NULL) {
+ if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000)
+ return (EINVAL);
+ }
+
+ /*
* Put this thread on the mutex's list of waiting threads.
* The lock on the thread ensures atomic (as far as other
* threads are concerned) setting of the thread state with
OpenPOWER on IntegriCloud