Skip to content

Commit 0906671

Browse files
pfalconnashif
authored andcommitted
posix: pthread: pthread_mutex_timedlock should accept absolute deadline
It was coded as if it accepts relative timeout. Normative reference: http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_timedlock.html Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent 68c7dc6 commit 0906671

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

include/posix/pthread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ int pthread_mutex_unlock(pthread_mutex_t *m);
224224
*/
225225

226226
int pthread_mutex_timedlock(pthread_mutex_t *m,
227-
const struct timespec *to);
227+
const struct timespec *abstime);
228228

229229
/**
230230
* @brief POSIX threading compatibility API

lib/posix/pthread_mutex.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <wait_q.h>
1010
#include <posix/pthread.h>
1111

12+
s64_t timespec_to_timeoutms(const struct timespec *abstime);
13+
1214
#define MUTEX_MAX_REC_LOCK 32767
1315

1416
/*
@@ -73,9 +75,10 @@ int pthread_mutex_trylock(pthread_mutex_t *m)
7375
* See IEEE 1003.1
7476
*/
7577
int pthread_mutex_timedlock(pthread_mutex_t *m,
76-
const struct timespec *to)
78+
const struct timespec *abstime)
7779
{
78-
return acquire_mutex(m, _ts_to_ms(to));
80+
s32_t timeout = (s32_t)timespec_to_timeoutms(abstime);
81+
return acquire_mutex(m, timeout);
7982
}
8083

8184
/**

0 commit comments

Comments
 (0)