summaryrefslogtreecommitdiff
path: root/mysys/my_pthread.c
diff options
context:
space:
mode:
authorunknown <heikki@hundin.mysql.fi>2002-08-14 00:41:33 +0300
committerunknown <heikki@hundin.mysql.fi>2002-08-14 00:41:33 +0300
commit6fbcad539d7f3c96dca4aa3cfdf4d28ee0d4ced2 (patch)
tree7f50ac4375ab4aee434988a6f9a78711b640208f /mysys/my_pthread.c
parent405b8f1ada6e6e574e47c62bd2ecbd3d479cbd0e (diff)
downloadmariadb-git-6fbcad539d7f3c96dca4aa3cfdf4d28ee0d4ced2.tar.gz
my_pthread.c:
In HP-UX-10.20 my_pthread_mutex_trylock erroneously returned 0 also in the case where the mutex was not acquired mysys/my_pthread.c: In HP-UX-10.20 my_pthread_mutex_trylock erroneously returned 0 also in the case where the mutex was not acquired
Diffstat (limited to 'mysys/my_pthread.c')
-rw-r--r--mysys/my_pthread.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c
index 15ca8934bcb..12a49a7a916 100644
--- a/mysys/my_pthread.c
+++ b/mysys/my_pthread.c
@@ -434,17 +434,42 @@ int my_pthread_cond_timedwait(pthread_cond_t *cond,
In HP-UX-10.20 and other old Posix 1003.4a Draft 4 implementations
pthread_mutex_trylock returns 1 on success, not 0 like
pthread_mutex_lock
+
+ From the HP-UX-10.20 man page:
+ RETURN VALUES
+ If the function fails, errno may be set to one of the following
+ values:
+ Return | Error | Description
+ _______|__________|_________________________________________
+ 1 | | Successful completion.
+ 0 | | The mutex is locked; therefore, it was
+ | | not acquired.
+ -1 | [EINVAL] | The value specified by mutex is invalid.
+
+*/
+/* We defined pthread_mutex_trylock as a macro in my_pthread.h, we have
+ to undef it here to prevent infinite recursion! Note that this comment
+ documents the pushed bugfix, not just the the code itself here. That is why
+ this comment is good here.
*/
+
#undef pthread_mutex_trylock
+/*
+This function returns 0 if we are able successfully lock the mutex. If
+the mutex cannot be locked or there is an error, then returns != 0
+*/
int my_pthread_mutex_trylock(pthread_mutex_t *mutex)
{
- int error=pthread_mutex_trylock(mutex);
- if (error == 1) /* Safety if the lib is fixed */
- return 0; /* Mutex was locked */
- if (error == -1) /* Safety if the lib is fixed */
- error=errno;
- return error;
+ int error = pthread_mutex_trylock(mutex);
+
+ if (error == 1)
+ return 0; /* success */
+
+ if (error == -1)
+ error=errno; /* parameter invalid */
+
+ return 1; /* we were not able to lock the mutex */
}
#endif