From acf12498cf00ab469e8139c55515f3b3c46cc5ac Mon Sep 17 00:00:00 2001 From: xiaojun zheng Date: Tue, 2 Jul 2024 01:49:24 +0000 Subject: [PATCH] add rtems_counting_semaphore_wait_timed_ticks and rtems_counting_semaphore_try_wait for self-contained object counting semaphore Closes #5055 ## Summary add rtems_counting_semaphore_wait_timed_ticks and rtems_counting_semaphore_try_wait for self-contained object counting semaphore. 1. rtems_counting_semaphore_wait_timed_ticks(rtems_counting_semaphore \*counting_semaphore,uint32_t ticks) 2. rtems_counting_semaphore_try_wait(rtems_counting_semaphore \*counting_semaphore) close issue #5055. --- cpukit/include/rtems/thread.h | 15 +++++++++++++++ testsuites/sptests/spthread01/init.c | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/cpukit/include/rtems/thread.h b/cpukit/include/rtems/thread.h index c3d7de67f4..2b9bc9f8ce 100644 --- a/cpukit/include/rtems/thread.h +++ b/cpukit/include/rtems/thread.h @@ -248,6 +248,21 @@ static __inline void rtems_counting_semaphore_wait( _Semaphore_Wait( counting_semaphore ); } +static __inline int rtems_counting_semaphore_wait_timed_ticks( + rtems_counting_semaphore *counting_semaphore, + uint32_t ticks +) +{ + return _Semaphore_Wait_timed_ticks( counting_semaphore, ticks ); +} + +static __inline int rtems_counting_semaphore_try_wait( + rtems_counting_semaphore *counting_semaphore +) +{ + return _Semaphore_Try_wait( counting_semaphore ); +} + static __inline void rtems_counting_semaphore_post( rtems_counting_semaphore *counting_semaphore ) diff --git a/testsuites/sptests/spthread01/init.c b/testsuites/sptests/spthread01/init.c index 4baf0dba2f..bedd9590b0 100644 --- a/testsuites/sptests/spthread01/init.c +++ b/testsuites/sptests/spthread01/init.c @@ -229,6 +229,7 @@ static void test_counting_semaphore(void) { rtems_counting_semaphore a = RTEMS_COUNTING_SEMAPHORE_INITIALIZER("a", 1); const char *name; + int eno; name = rtems_counting_semaphore_get_name(&a); rtems_test_assert(strcmp(name, "a") == 0); @@ -245,10 +246,26 @@ static void test_counting_semaphore(void) name = rtems_counting_semaphore_get_name(&a); rtems_test_assert(strcmp(name, "c") == 0); + eno = rtems_counting_semaphore_try_wait(&a); + rtems_test_assert(eno == EAGAIN); + + eno = rtems_counting_semaphore_wait_timed_ticks(&a, 1); + rtems_test_assert(eno == ETIMEDOUT); + rtems_counting_semaphore_post(&a); rtems_counting_semaphore_wait(&a); + rtems_counting_semaphore_post(&a); + + eno = rtems_counting_semaphore_try_wait(&a); + rtems_test_assert(eno == 0); + + rtems_counting_semaphore_post(&a); + + eno = rtems_counting_semaphore_wait_timed_ticks(&a, 1); + rtems_test_assert(eno == 0); + rtems_counting_semaphore_destroy(&a); }