aboutsummaryrefslogtreecommitdiffstats
path: root/libc/bionic/pthread_mutex.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-03-04 10:55:39 -0800
committerElliott Hughes <enh@google.com>2014-03-04 10:55:39 -0800
commit39b644a0e270df453c53d6060cd364391bb1c512 (patch)
treefc937b2b00e2efe603ac0bd48fc0a1c832b46456 /libc/bionic/pthread_mutex.cpp
parenta0bf9bdea24164db96ec1d5dfa2cd327942671b6 (diff)
downloadandroid_bionic-39b644a0e270df453c53d6060cd364391bb1c512.tar.gz
android_bionic-39b644a0e270df453c53d6060cd364391bb1c512.tar.bz2
android_bionic-39b644a0e270df453c53d6060cd364391bb1c512.zip
Remove dead NULL checks from pthread code.
GCC is removing these checks anyway because it knows the arguments must be non-null, so leaving this code around is just confusing. We know from experience that people were shipping code with locking bugs because they weren't checking for error returns. Failing hard like glibc does seems the better choice. (And it's what the checked in code was already doing; this patch doesn't change that. It just makes it more obvious that that's what's going on.) Change-Id: I167c6d7c0a296822baf0cb9b43b97821eba7ab35
Diffstat (limited to 'libc/bionic/pthread_mutex.cpp')
-rw-r--r--libc/bionic/pthread_mutex.cpp51
1 files changed, 17 insertions, 34 deletions
diff --git a/libc/bionic/pthread_mutex.cpp b/libc/bionic/pthread_mutex.cpp
index 90726052e..a2e7b25dc 100644
--- a/libc/bionic/pthread_mutex.cpp
+++ b/libc/bionic/pthread_mutex.cpp
@@ -207,55 +207,42 @@ extern void pthread_debug_mutex_unlock_check(pthread_mutex_t *mutex);
int pthread_mutexattr_init(pthread_mutexattr_t *attr)
{
- if (attr) {
- *attr = PTHREAD_MUTEX_DEFAULT;
- return 0;
- } else {
- return EINVAL;
- }
+ *attr = PTHREAD_MUTEX_DEFAULT;
+ return 0;
}
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
{
- if (attr) {
- *attr = -1;
- return 0;
- } else {
- return EINVAL;
- }
+ *attr = -1;
+ return 0;
}
-int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type)
+int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type_p)
{
- if (attr) {
- int atype = (*attr & MUTEXATTR_TYPE_MASK);
+ int type = (*attr & MUTEXATTR_TYPE_MASK);
- if (atype >= PTHREAD_MUTEX_NORMAL &&
- atype <= PTHREAD_MUTEX_ERRORCHECK) {
- *type = atype;
- return 0;
- }
+ if (type < PTHREAD_MUTEX_NORMAL || type > PTHREAD_MUTEX_ERRORCHECK) {
+ return EINVAL;
}
- return EINVAL;
+
+ *type_p = type;
+ return 0;
}
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
{
- if (attr && type >= PTHREAD_MUTEX_NORMAL &&
- type <= PTHREAD_MUTEX_ERRORCHECK ) {
- *attr = (*attr & ~MUTEXATTR_TYPE_MASK) | type;
- return 0;
+ if (type < PTHREAD_MUTEX_NORMAL || type > PTHREAD_MUTEX_ERRORCHECK ) {
+ return EINVAL;
}
- return EINVAL;
+
+ *attr = (*attr & ~MUTEXATTR_TYPE_MASK) | type;
+ return 0;
}
/* process-shared mutexes are not supported at the moment */
int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
{
- if (!attr)
- return EINVAL;
-
switch (pshared) {
case PTHREAD_PROCESS_PRIVATE:
*attr &= ~MUTEXATTR_SHARED_MASK;
@@ -274,11 +261,7 @@ int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
}
int pthread_mutexattr_getpshared(const pthread_mutexattr_t* attr, int* pshared) {
- if (!attr || !pshared)
- return EINVAL;
-
- *pshared = (*attr & MUTEXATTR_SHARED_MASK) ? PTHREAD_PROCESS_SHARED
- : PTHREAD_PROCESS_PRIVATE;
+ *pshared = (*attr & MUTEXATTR_SHARED_MASK) ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE;
return 0;
}