Loading...
Searching...
No Matches
thread_flags_group.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 ML!PA Consulting GmbH
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
49
50#include <limits.h>
51
52#include "atomic_utils.h"
53#include "thread.h"
54#include "thread_flags.h"
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60/* UINT_WIDTH is only provided starting with -std=c23 or newer. Until RIOT
61 * requires C23 as C version, we need provide it by hand when missing. */
62#ifndef UINT_WIDTH
66# define UINT_WIDTH (sizeof(unsigned) * 8)
67#endif
68
72typedef struct {
78
82#define THREAD_FLAGS_GROUP_INIT { .members = { 0 } }
83
94{
96 /* this also optimizes away the arithmetic below if MAXTHREADS <= UINT_WIDTH */
97 assume(pid < MAXTHREADS);
99 pid % UINT_WIDTH));
100}
101
111{
113 /* this also optimizes away the arithmetic below if MAXTHREADS <= UINT_WIDTH */
114 assume(pid < MAXTHREADS);
116 pid % UINT_WIDTH));
117}
118
126
127#ifdef __cplusplus
128}
129#endif
API of the utility functions for atomic accesses.
#define assume(cond)
Behaves like an assert(), but tells the compiler that cond can never be false.
Threading API.
int16_t kernel_pid_t
Unique process identifier.
Definition sched.h:135
#define MAXTHREADS
The maximum number of threads to be scheduled.
Definition sched.h:99
static void thread_flags_group_join(thread_flags_group_t *group)
Join a thread flags group.
#define UINT_WIDTH
Number of bits in unsigned int.
void thread_flags_group_set(thread_flags_group_t *group, thread_flags_t mask)
Set thread flags for all threads in a group.
static void thread_flags_group_leave(thread_flags_group_t *group)
Leave a thread flags group.
uint16_t thread_flags_t
Type definition of thread_flags_t.
static kernel_pid_t thread_getpid(void)
Returns the process ID of the currently running thread.
Definition thread.h:396
static void atomic_clear_bit_unsigned(atomic_bit_unsigned_t bit)
Atomic version of *dest &= ~(1 << bit)
static atomic_bit_unsigned_t atomic_bit_unsigned(volatile unsigned *dest, uint8_t bit)
Create a reference to a bit in an unsigned int
static void atomic_set_bit_unsigned(atomic_bit_unsigned_t bit)
Atomic version of *dest |= (1 << bit)
Thread flags group.
unsigned members[(MAXTHREADS/UINT_WIDTH)+!!(MAXTHREADS % UINT_WIDTH)]
Members bitfield.
Thread Flags API.