Loading...
Searching...
No Matches
thread_flags_group.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 ML!PA Consulting GmbH
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
9#pragma once
10
52
53#include <limits.h>
54
55#include "atomic_utils.h"
56#include "thread.h"
57#include "thread_flags.h"
58
59#ifdef __cplusplus
60extern "C" {
61#endif
62
63/* UINT_WIDTH is only provided starting with -std=c23 or newer. Until RIOT
64 * requires C23 as C version, we need provide it by hand when missing. */
65#ifndef UINT_WIDTH
69# define UINT_WIDTH (sizeof(unsigned) * 8)
70#endif
71
75typedef struct {
81
85#define THREAD_FLAGS_GROUP_INIT { .members = { 0 } }
86
97{
99 /* this also optimizes away the arithmetic below if MAXTHREADS <= UINT_WIDTH */
100 assume(pid < MAXTHREADS);
102 pid % UINT_WIDTH));
103}
104
114{
116 /* this also optimizes away the arithmetic below if MAXTHREADS <= UINT_WIDTH */
117 assume(pid < MAXTHREADS);
119 pid % UINT_WIDTH));
120}
121
129
130#ifdef __cplusplus
131}
132#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:138
#define MAXTHREADS
The maximum number of threads to be scheduled.
Definition sched.h:102
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:399
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.