v2.0.0
sem.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef _PICO_SEM_H
8#define _PICO_SEM_H
9
10#include "pico/lock_core.h"
11
28#ifdef __cplusplus
29extern "C" {
30#endif
31 typedef struct semaphore {
32 struct lock_core core;
33 int16_t permits;
34 int16_t max_permits;
35} semaphore_t;
36
37
45void sem_init(semaphore_t *sem, int16_t initial_permits, int16_t max_permits);
46
53 int sem_available(semaphore_t *sem);
54
64 bool sem_release(semaphore_t *sem);
65
74 void sem_reset(semaphore_t *sem, int16_t permits);
75
83 void sem_acquire_blocking(semaphore_t *sem);
84
96 bool sem_acquire_timeout_ms(semaphore_t *sem, uint32_t timeout_ms);
97
109 bool sem_acquire_timeout_us(semaphore_t *sem, uint32_t timeout_us);
110
123 bool sem_acquire_block_until(semaphore_t *sem, absolute_time_t until);
124
134 bool sem_try_acquire(semaphore_t *sem);
135
136#ifdef __cplusplus
137}
138#endif
139#endif
sem_acquire_timeout_us
bool sem_acquire_timeout_us(semaphore_t *sem, uint32_t timeout_us)
Acquire a permit from a semaphore, with timeout.
sem_try_acquire
bool sem_try_acquire(semaphore_t *sem)
Attempt to acquire a permit from a semaphore without blocking.
sem_acquire_timeout_ms
bool sem_acquire_timeout_ms(semaphore_t *sem, uint32_t timeout_ms)
Acquire a permit from a semaphore, with timeout.
sem_acquire_block_until
bool sem_acquire_block_until(semaphore_t *sem, absolute_time_t until)
Wait to acquire a permit from a semaphore until a specific time.
sem_init
void sem_init(semaphore_t *sem, int16_t initial_permits, int16_t max_permits)
Initialise a semaphore structure.
Definition: sem.c:10
sem_reset
void sem_reset(semaphore_t *sem, int16_t permits)
Reset semaphore to a specific number of available permits.
sem_available
int sem_available(semaphore_t *sem)
Return number of available permits on the semaphore.
sem_release
bool sem_release(semaphore_t *sem)
Release a permit on a semaphore.
sem_acquire_blocking
void sem_acquire_blocking(semaphore_t *sem)
Acquire a permit from the semaphore.
absolute_time_t
uint64_t absolute_time_t
An opaque 64 bit timestamp in microseconds.
Definition: types.h:43
lock_core.h
lock_core
Definition: lock_core.h:53
semaphore
Definition: sem.h:31