Skip to content

Commit 325abfb

Browse files
youvedeep-singhAnas Nashif
authored andcommitted
kernel: POSIX: Fixing return value of POSIX APIs on error.
As per IEEE 1003.1 POSIX APIs should return ERROR_CODE on error. But currently these are returning -ERROR_CODE instead of ERROR_CODE. So fixing the return value. Signed-off-by: Youvedeep Singh <[email protected]>
1 parent f31245d commit 325abfb

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

include/posix/pthread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static inline int pthread_mutex_timedlock(pthread_mutex_t *m,
193193
{
194194
int ret = k_sem_take(m->sem, _ts_to_ms(to));
195195

196-
return ret == -EAGAIN ? -ETIMEDOUT : ret;
196+
return ret == 0 ? ret : ETIMEDOUT;
197197
}
198198

199199
/**

kernel/posix/pthread_cond.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static int cond_wait(pthread_cond_t *cv, pthread_mutex_t *mut, int timeout)
3434
*/
3535
pthread_mutex_lock(mut);
3636

37-
return ret == -EAGAIN ? -ETIMEDOUT : ret;
37+
return ret == -EAGAIN ? ETIMEDOUT : ret;
3838
}
3939

4040
/* This implements a "fair" scheduling policy: at the end of a POSIX

kernel/posix/pthread_mutex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
int pthread_mutex_trylock(pthread_mutex_t *m)
1313
{
14-
int key = irq_lock(), ret = -EBUSY;
14+
int key = irq_lock(), ret = EBUSY;
1515

1616
if (m->sem->count) {
1717
m->sem->count = 0;

0 commit comments

Comments
 (0)