Skip to content

Commit f9ecc9a

Browse files
Christopher Friedtcfriedt
authored andcommitted
posix: mutex: return ETIMEDOUT from pthread_mutex_timedlock()
The normative spec for `pthread_mutex_timedlock()` says that it should return `ETIMEDOUT` when a timeout occurs. However, currently it returns `EAGAIN`, which reflects what is returned by `k_mutex_lock()`. Inspect and update the return value to account for this slight difference. Signed-off-by: Christopher Friedt <[email protected]>
1 parent a419f9b commit f9ecc9a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/posix/mutex.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ static int acquire_mutex(pthread_mutex_t *mu, k_timeout_t timeout)
147147

148148
if (ret == 0) {
149149
ret = k_mutex_lock(m, timeout);
150+
if (ret == -EAGAIN) {
151+
/*
152+
* special quirk - k_mutex_lock() returns EAGAIN if a timeout occurs, but
153+
* for pthreads, that means something different
154+
*/
155+
ret = -ETIMEDOUT;
156+
}
150157
}
151158

152159
if (ret < 0) {

0 commit comments

Comments
 (0)