summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Kondik <shade@chemlab.org>2014-02-03 13:38:59 -0800
committerRicardo Cerqueira <cyanogenmod@cerqueira.org>2014-02-04 01:37:24 +0000
commit8548390323252cb50baebb266abdbf58946de03e (patch)
tree1febfa6ade543b13c5327334ec54c0c6906b625f
parent53f15d0325feeaf7e58dc79fce4ddf55e0a64b7a (diff)
downloadbionic-8548390323252cb50baebb266abdbf58946de03e.zip
bionic-8548390323252cb50baebb266abdbf58946de03e.tar.gz
bionic-8548390323252cb50baebb266abdbf58946de03e.tar.bz2
Revert "Remove harmful attempts to be helpful in pthread_mutex functions."
This reverts commit 53f15d0325feeaf7e58dc79fce4ddf55e0a64b7a.
-rw-r--r--libc/bionic/pthread.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index 764e01d..92e2c27 100644
--- a/libc/bionic/pthread.c
+++ b/libc/bionic/pthread.c
@@ -391,16 +391,21 @@ int pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared)
return 0;
}
-int pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attr) {
+int pthread_mutex_init(pthread_mutex_t *mutex,
+ const pthread_mutexattr_t *attr)
+{
+ int value = 0;
+
+ if (mutex == NULL)
+ return EINVAL;
+
if (__predict_true(attr == NULL)) {
mutex->value = MUTEX_TYPE_BITS_NORMAL;
return 0;
}
- int value = 0;
- if ((*attr & MUTEXATTR_SHARED_MASK) != 0) {
+ if ((*attr & MUTEXATTR_SHARED_MASK) != 0)
value |= MUTEX_SHARED_MASK;
- }
switch (*attr & MUTEXATTR_TYPE_MASK) {
case PTHREAD_MUTEX_NORMAL:
@@ -577,6 +582,9 @@ int pthread_mutex_lock_impl(pthread_mutex_t *mutex)
{
int mvalue, mtype, tid, shared;
+ if (__predict_false(mutex == NULL))
+ return EINVAL;
+
mvalue = mutex->value;
mtype = (mvalue & MUTEX_TYPE_MASK);
shared = (mvalue & MUTEX_SHARED_MASK);
@@ -668,6 +676,9 @@ int pthread_mutex_unlock_impl(pthread_mutex_t *mutex)
{
int mvalue, mtype, tid, shared;
+ if (__predict_false(mutex == NULL))
+ return EINVAL;
+
mvalue = mutex->value;
mtype = (mvalue & MUTEX_TYPE_MASK);
shared = (mvalue & MUTEX_SHARED_MASK);
@@ -732,6 +743,9 @@ int pthread_mutex_trylock_impl(pthread_mutex_t *mutex)
{
int mvalue, mtype, tid, shared;
+ if (__predict_false(mutex == NULL))
+ return EINVAL;
+
mvalue = mutex->value;
mtype = (mvalue & MUTEX_TYPE_MASK);
shared = (mvalue & MUTEX_SHARED_MASK);
@@ -827,6 +841,9 @@ int pthread_mutex_lock_timeout_np_impl(pthread_mutex_t *mutex, unsigned msecs)
/* compute absolute expiration time */
__timespec_to_relative_msec(&abstime, msecs, clock);
+ if (__predict_false(mutex == NULL))
+ return EINVAL;
+
mvalue = mutex->value;
mtype = (mvalue & MUTEX_TYPE_MASK);
shared = (mvalue & MUTEX_SHARED_MASK);