Add sem_try_acquire(). Fixes #846 (#856)

Co-authored-by: Geoff Simmons <geoff@uplex.de>
This commit is contained in:
Graham Sanderson
2022-06-08 13:23:36 -05:00
committed by GitHub
parent ef47dfeeaf
commit 672e48e9e9
5 changed files with 57 additions and 1 deletions

View File

@ -0,0 +1,4 @@
add_executable(pico_sem_test pico_sem_test.c)
target_link_libraries(pico_sem_test PRIVATE pico_test pico_sync)
pico_add_extra_outputs(pico_sem_test)

View File

@ -0,0 +1,29 @@
/**
* Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "pico/sem.h"
#include "pico/test.h"
#include "pico/stdio.h"
PICOTEST_MODULE_NAME("SEM", "semaphore test");
int main() {
semaphore_t sem;
stdio_init_all();
sem_init(&sem, 1, 1);
PICOTEST_START();
PICOTEST_START_SECTION("sem_try_acquire");
PICOTEST_CHECK(sem_try_acquire(&sem), "available permit not acquired");
PICOTEST_CHECK(!sem_try_acquire(&sem), "success with no permits");
PICOTEST_END_SECTION();
PICOTEST_END_TEST();
}