Commit 6fbcad53 authored by unknown's avatar unknown

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
parent 405b8f1a
...@@ -434,17 +434,42 @@ int my_pthread_cond_timedwait(pthread_cond_t *cond, ...@@ -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 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_trylock returns 1 on success, not 0 like
pthread_mutex_lock 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 #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 my_pthread_mutex_trylock(pthread_mutex_t *mutex)
{ {
int error=pthread_mutex_trylock(mutex); int error = pthread_mutex_trylock(mutex);
if (error == 1) /* Safety if the lib is fixed */
return 0; /* Mutex was locked */ if (error == 1)
if (error == -1) /* Safety if the lib is fixed */ return 0; /* success */
error=errno;
return error; if (error == -1)
error=errno; /* parameter invalid */
return 1; /* we were not able to lock the mutex */
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment