mirror of
https://github.com/wolfcw/libfaketime.git
synced 2026-05-17 08:36:28 +03:00
libfaketime.c: fix pthread_cleanup_push() build failure
gcc 8.x introduced stricter checking on types, and the trick to cast
pthread_mutex_unlock() into a function acceptable for
pthread_cleanup_push() no longer builds:
libfaketime.c: In function 'fake_clock_gettime':
libfaketime.c:2039:24: error: cast between incompatible function types from 'int (*)(pthread_mutex_t *)' {aka 'int (*)(union <anonymous> *)'} to 'void (*)(void *)' [-Werror=cast-function-type]
pthread_cleanup_push((void (*)(void *))pthread_mutex_unlock, (void *)&time_mutex);
^
Rather than continuing to hack around, introduce an auxilliary
function with the type expected by pthread_cleanup_push().
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
@@ -2015,6 +2015,14 @@ static void remove_trailing_eols(char *line)
|
||||
* =======================================================================
|
||||
*/
|
||||
|
||||
#ifdef PTHREAD_SINGLETHREADED_TIME
|
||||
static void pthread_cleanup_mutex_lock(void *data)
|
||||
{
|
||||
pthread_mutex_t *mutex = data;
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
#endif
|
||||
|
||||
int fake_clock_gettime(clockid_t clk_id, struct timespec *tp)
|
||||
{
|
||||
/* variables used for caching, introduced in version 0.6 */
|
||||
@@ -2038,7 +2046,7 @@ int fake_clock_gettime(clockid_t clk_id, struct timespec *tp)
|
||||
#ifdef PTHREAD_SINGLETHREADED_TIME
|
||||
static pthread_mutex_t time_mutex=PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_lock(&time_mutex);
|
||||
pthread_cleanup_push((void (*)(void *))pthread_mutex_unlock, (void *)&time_mutex);
|
||||
pthread_cleanup_push(pthread_cleanup_mutex_lock, &time_mutex);
|
||||
#endif
|
||||
|
||||
if ((limited_faking &&
|
||||
|
||||
Reference in New Issue
Block a user