summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread/thr_mutex_prioceiling.c
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2005-04-02 01:20:00 +0000
committerdavidxu <davidxu@FreeBSD.org>2005-04-02 01:20:00 +0000
commitf066519e91e2290cb79ef12fe7c958ee462cda6c (patch)
tree6aaef5f553a6539306bd6f5679d039ed3c2abcce /lib/libthr/thread/thr_mutex_prioceiling.c
parent3cc412b7837a105c757df856c422eb5f497bad67 (diff)
downloadFreeBSD-src-f066519e91e2290cb79ef12fe7c958ee462cda6c.zip
FreeBSD-src-f066519e91e2290cb79ef12fe7c958ee462cda6c.tar.gz
Import my recent 1:1 threading working. some features improved includes:
1. fast simple type mutex. 2. __thread tls works. 3. asynchronous cancellation works ( using signal ). 4. thread synchronization is fully based on umtx, mainly, condition variable and other synchronization objects were rewritten by using umtx directly. those objects can be shared between processes via shared memory, it has to change ABI which does not happen yet. 5. default stack size is increased to 1M on 32 bits platform, 2M for 64 bits platform. As the result, some mysql super-smack benchmarks show performance is improved massivly. Okayed by: jeff, mtm, rwatson, scottl
Diffstat (limited to 'lib/libthr/thread/thr_mutex_prioceiling.c')
-rw-r--r--lib/libthr/thread/thr_mutex_prioceiling.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/lib/libthr/thread/thr_mutex_prioceiling.c b/lib/libthr/thread/thr_mutex_prioceiling.c
index c7396a4..edea124 100644
--- a/lib/libthr/thread/thr_mutex_prioceiling.c
+++ b/lib/libthr/thread/thr_mutex_prioceiling.c
@@ -31,6 +31,7 @@
*
* $FreeBSD$
*/
+
#include <string.h>
#include <stdlib.h>
#include <errno.h>
@@ -47,7 +48,9 @@ _pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
{
int ret = 0;
- if (*mattr == NULL)
+ if ((mattr == NULL) || (*mattr == NULL))
+ ret = EINVAL;
+ else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
ret = EINVAL;
else
*prioceiling = (*mattr)->m_ceiling;
@@ -60,26 +63,30 @@ _pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
{
int ret = 0;
- if (*mattr == NULL)
+ if ((mattr == NULL) || (*mattr == NULL))
ret = EINVAL;
- else if (prioceiling <= PTHREAD_MAX_PRIORITY &&
- prioceiling >= PTHREAD_MIN_PRIORITY)
- (*mattr)->m_ceiling = prioceiling;
- else
+ else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
ret = EINVAL;
+ else
+ (*mattr)->m_ceiling = prioceiling;
- return (ret);
+ return(ret);
}
int
_pthread_mutex_getprioceiling(pthread_mutex_t *mutex,
int *prioceiling)
{
- if (*mutex == NULL)
- return (EINVAL);
+ int ret;
+
+ if ((mutex == NULL) || (*mutex == NULL))
+ ret = EINVAL;
+ else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT)
+ ret = EINVAL;
else
- *prioceiling = (*mutex)->m_prio;
- return (0);
+ ret = (*mutex)->m_prio;
+
+ return(ret);
}
int
@@ -87,27 +94,23 @@ _pthread_mutex_setprioceiling(pthread_mutex_t *mutex,
int prioceiling, int *old_ceiling)
{
int ret = 0;
+ int tmp;
- if (*mutex == NULL)
- return (EINVAL);
- else if (prioceiling > PTHREAD_MAX_PRIORITY ||
- prioceiling < PTHREAD_MIN_PRIORITY)
- return (EINVAL);
-
- /*
- * Because of the use of pthread_mutex_unlock(), the
- * priority ceiling of a mutex cannot be changed
- * while the mutex is held by another thread. It also,
- * means that the the thread trying to change the
- * priority ceiling must adhere to prio protection rules.
- */
- if ((ret = pthread_mutex_lock(mutex)) == 0) {
- /* Return the old ceiling and set the new ceiling: */
- *old_ceiling = (*mutex)->m_prio;
+ if ((mutex == NULL) || (*mutex == NULL))
+ ret = EINVAL;
+ else if ((*mutex)->m_protocol != PTHREAD_PRIO_PROTECT)
+ ret = EINVAL;
+ /* Lock the mutex: */
+ else if ((ret = pthread_mutex_lock(mutex)) == 0) {
+ tmp = (*mutex)->m_prio;
+ /* Set the new ceiling: */
(*mutex)->m_prio = prioceiling;
/* Unlock the mutex: */
ret = pthread_mutex_unlock(mutex);
+
+ /* Return the old ceiling: */
+ *old_ceiling = tmp;
}
return(ret);
}
OpenPOWER on IntegriCloud