mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-26 15:23:59 +08:00
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. <!-- Default settings, if it is a dropdown it will set after submission -->
This commit is contained in:
committed by
Amar Takhar
parent
087645e58f
commit
acf12498cf
@@ -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
|
||||
)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user