|
Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
|
Macros | |
| #define | SCOPE_VAR_DEFINE(_name, _type, _exit_fn, _init_fn, ...) |
| Define a scoped variable type. | |
| #define | SCOPE_GUARD_DEFINE(_name, _type, _lock, _unlock) |
| Define a scoped guard type. | |
| #define | SCOPE_DEFER_DEFINE(_func, ...) |
| Define a scoped defer type. | |
| #define | scope_var(_name, _var) |
| Declare a variable with automatic cleanup. | |
| #define | scope_var_init(_name, _var, _init_expr) |
| Declare a variable with automatic cleanup using direct initialization. | |
| #define | scope_guard(_name) |
| Acquire a scoped guard lock. | |
| #define | scope_defer(_name) |
| Register a scoped deferred call. | |
| #define scope_defer | ( | _name | ) |
#include <zephyr/cleanup.h>
Register a scoped deferred call.
This macro creates a defer variable with an automatically generated unique name. The defer will execute its cleanup action when going out of scope.
| _name | Name of the defer type (defined by SCOPE_DEFER_DEFINE or SCOPE_VAR_DEFINE with defer_ prefix) |
CONFIG_SCOPE_CLEANUP_HELPERS.Usage:
| #define SCOPE_DEFER_DEFINE | ( | _func, | |
| ... ) |
#include <zephyr/cleanup.h>
Define a scoped defer type.
This macro defines a defer that executes a cleanup function when the variable goes out of scope. Unlike guards, defers don't acquire a resource on initialization.
| _func | The function to call at cleanup |
| ... | The argument types to pass to the cleanup function |
CONFIG_SCOPE_CLEANUP_HELPERS.Usage:
| #define scope_guard | ( | _name | ) |
#include <zephyr/cleanup.h>
Acquire a scoped guard lock.
This macro creates a guard variable with an automatically generated unique name. The guard will acquire the lock on initialization and release it when going out of scope.
| _name | Name of the guard type (defined by SCOPE_GUARD_DEFINE or SCOPE_VAR_DEFINE with guard_ prefix) |
CONFIG_SCOPE_CLEANUP_HELPERS.Usage:
| #define SCOPE_GUARD_DEFINE | ( | _name, | |
| _type, | |||
| _lock, | |||
| _unlock ) |
#include <zephyr/cleanup.h>
Define a scoped guard type.
This macro defines a guard that automatically acquires a lock on initialization and releases it when going out of scope.
| _name | Name of the guard (will be prefixed with guard_) |
| _type | Type of the lock object (typically a pointer) |
| _lock | Expression to acquire the lock (can reference _T) |
| _unlock | Expression to release the lock (can reference _T) |
CONFIG_SCOPE_CLEANUP_HELPERS.Usage:
| #define scope_var | ( | _name, | |
| _var ) |
#include <zephyr/cleanup.h>
Declare a variable with automatic cleanup.
This macro declares a variable with automatic cleanup using a previously defined cleanup helper. The variable will be automatically cleaned up when it goes out of scope.
The variable is initialized by calling the init function defined in SCOPE_VAR_DEFINE. Use scope_var_init if you want to initialize the variable with a direct expression instead of calling the init function.
| _name | Name of the cleanup helper (defined by SCOPE_VAR_DEFINE) |
| _var | Name of the variable to declare |
CONFIG_SCOPE_CLEANUP_HELPERS.Usage:
| #define SCOPE_VAR_DEFINE | ( | _name, | |
| _type, | |||
| _exit_fn, | |||
| _init_fn, | |||
| ... ) |
#include <zephyr/cleanup.h>
Define a scoped variable type.
This macro defines a new cleanup helper that can be used with the __cleanup attribute to automatically execute cleanup code when a variable goes out of scope.
| _name | Name of the cleanup helper |
| _type | Type of the variable to be cleaned up |
| _exit_fn | Cleanup code to execute when variable goes out of scope (can reference _T) |
| _init_fn | Initialization expression for the variable |
| ... | Initialization arguments (variadic) |
The macro creates:
CONFIG_SCOPE_CLEANUP_HELPERS.Usage:
| #define scope_var_init | ( | _name, | |
| _var, | |||
| _init_expr ) |
#include <zephyr/cleanup.h>
Declare a variable with automatic cleanup using direct initialization.
This macro declares a variable with automatic cleanup using a previously defined cleanup helper. The variable will be automatically cleaned up when it goes out of scope.
Unlike scope_var, this macro accepts a direct initialization expression instead of calling the init function defined in SCOPE_VAR_DEFINE. Use this when you need to bypass the init function and initialize the variable directly (e.g., with a struct initializer, a different function, or a literal value).
| _name | Name of the cleanup helper (defined by SCOPE_VAR_DEFINE) |
| _var | Name of the variable to declare |
| _init_expr | Direct initialization expression for the variable (e.g., {0}, NULL, or a function call) |
CONFIG_SCOPE_CLEANUP_HELPERS.Usage: