mirror of https://git.musl-libc.org/git/musl
Browse Source
despite looking like undefined behavior, the affected code is correct both before and after this patch. the pairs mtx_t and pthread_mutex_t, and cnd_t and pthread_cond_t, are not mutually compatible within a single translation unit (because they are distinct untagged aggregate instances), but they are compatible with an object of either type from another translation unit (6.2.7 ¶1), and therefore a given translation unit can choose which one it wants to use. in the interest of being able to move declarations out of source files to headers that facilitate checking, use the pthread type names in declaring the namespace-safe versions of the pthread functions and cast the argument pointer types when calling them.master
6 changed files with 17 additions and 12 deletions
@ -1,10 +1,11 @@ |
|||
#include <threads.h> |
|||
#include <pthread.h> |
|||
|
|||
int __private_cond_signal(cnd_t *, int); |
|||
int __private_cond_signal(pthread_cond_t *, int); |
|||
|
|||
int cnd_broadcast(cnd_t *c) |
|||
{ |
|||
/* This internal function never fails, and always returns zero,
|
|||
* which matches the value thrd_success is defined with. */ |
|||
return __private_cond_signal(c, -1); |
|||
return __private_cond_signal((pthread_cond_t *)c, -1); |
|||
} |
|||
|
|||
@ -1,10 +1,11 @@ |
|||
#include <threads.h> |
|||
#include <pthread.h> |
|||
|
|||
int __private_cond_signal(cnd_t *, int); |
|||
int __private_cond_signal(pthread_cond_t *, int); |
|||
|
|||
int cnd_signal(cnd_t *c) |
|||
{ |
|||
/* This internal function never fails, and always returns zero,
|
|||
* which matches the value thrd_success is defined with. */ |
|||
return __private_cond_signal(c, 1); |
|||
return __private_cond_signal((pthread_cond_t *)c, 1); |
|||
} |
|||
|
|||
@ -1,11 +1,12 @@ |
|||
#include <threads.h> |
|||
#include <pthread.h> |
|||
|
|||
int __pthread_mutex_unlock(mtx_t *); |
|||
int __pthread_mutex_unlock(pthread_mutex_t *); |
|||
|
|||
int mtx_unlock(mtx_t *mtx) |
|||
{ |
|||
/* The only cases where pthread_mutex_unlock can return an
|
|||
* error are undefined behavior for C11 mtx_unlock, so we can |
|||
* assume it does not return an error and simply tail call. */ |
|||
return __pthread_mutex_unlock(mtx); |
|||
return __pthread_mutex_unlock((pthread_mutex_t *)mtx); |
|||
} |
|||
|
|||
Loading…
Reference in new issue