summaryrefslogtreecommitdiff
path: root/lib/libthr/thread
diff options
context:
space:
mode:
authorMike Makonnen <mtm@FreeBSD.org>2003-12-30 08:44:55 +0000
committerMike Makonnen <mtm@FreeBSD.org>2003-12-30 08:44:55 +0000
commit2aa9de1f7720a241fc6f7c2debda834e3bea4a9d (patch)
treec494713f2d572e1958d88dfaaa98a84ff1673426 /lib/libthr/thread
parent2b33fc6470f5a93ffb2caf6316f01ea0f5aa089b (diff)
Notes
Diffstat (limited to 'lib/libthr/thread')
-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 33958b76c2a0..3567a3437d64 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