Lely core libraries 2.3.4
|
This file is part of the utilities library; it contains the implementation of the stop token. More...
#include "util.h"
#include <lely/libc/stdatomic.h>
#include <lely/libc/threads.h>
#include <lely/util/errnum.h>
#include <lely/util/stop.h>
#include <lely/util/util.h>
#include <assert.h>
#include <stdlib.h>
Go to the source code of this file.
Data Structures | |
struct | stop_token |
A stop token. More... | |
struct | stop_source |
A stop source. More... | |
Functions | |
stop_token_t * | stop_token_acquire (stop_token_t *token) |
Acquires a reference to a stop token. More... | |
void | stop_token_release (stop_token_t *token) |
Releases a reference to a stop token. More... | |
int | stop_token_stop_requested (const stop_token_t *token) |
Checks if the stop-state associated with the specified stop token has received a stop request. More... | |
int | stop_token_stop_possible (const stop_token_t *token) |
Checks if the stop-state associated with the specified stop token has received a stop request, or if it has an associated stop source that can still issue such an request. More... | |
int | stop_token_insert (stop_token_t *token, struct stop_func *func) |
Registers a callback function with the specified stop token. More... | |
void | stop_token_remove (stop_token_t *token, struct stop_func *func) |
Deregisters a callback function from the specified stop token. More... | |
stop_source_t * | stop_source_create (void) |
Creates a stop source with a new stop-state. More... | |
stop_source_t * | stop_source_acquire (stop_source_t *source) |
Acquires a reference to a stop source. More... | |
void | stop_source_release (stop_source_t *source) |
Releases a reference to a stop source. More... | |
int | stop_source_request_stop (stop_source_t *source) |
Issues a stop request to the stop-state associated with the specified stop source, if it has not already received a stop request. More... | |
int | stop_source_stop_requested (const stop_source_t *source) |
Checks if the stop-state associated with the specified stop source has received a stop request. More... | |
stop_token_t * | stop_source_get_token (stop_source_t *source) |
Returns (a reference to) a stop token associated with the specified stop source's stop-state. | |
This file is part of the utilities library; it contains the implementation of the stop token.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Definition in file stop.c.
stop_token_t * stop_token_acquire | ( | stop_token_t * | token | ) |
Acquires a reference to a stop token.
If token is NULL, this function has no effect.
void stop_token_release | ( | stop_token_t * | token | ) |
Releases a reference to a stop token.
If this is the last reference to the token, the token is destroyed. If no references remain to its associated stop source, the stop-state is destroyed. The object pointed to by token MUST NOT be referenced after this function has been invoked.
int stop_token_stop_requested | ( | const stop_token_t * | token | ) |
Checks if the stop-state associated with the specified stop token has received a stop request.
int stop_token_stop_possible | ( | const stop_token_t * | token | ) |
Checks if the stop-state associated with the specified stop token has received a stop request, or if it has an associated stop source that can still issue such an request.
int stop_token_insert | ( | stop_token_t * | token, |
struct stop_func * | func | ||
) |
Registers a callback function with the specified stop token.
If a stop request has already been issued for the associated stop source (i.e., stop_token_stop_requested() returns 1), the callback function is invoked in the calling thread before this function returns.
void stop_token_remove | ( | stop_token_t * | token, |
struct stop_func * | func | ||
) |
Deregisters a callback function from the specified stop token.
If the callback function is being invoked concurrently on another thread, this function does not return until the callback function invocation is complete. If the callback function is being invoked on the calling thread, this function does not wait until the invocation is complete. Hence it is safe to invoke this function from the callback function.
stop_source_t * stop_source_create | ( | void | ) |
Creates a stop source with a new stop-state.
The stop source is destroyed once the last reference to it is released.
stop_source_t * stop_source_acquire | ( | stop_source_t * | source | ) |
Acquires a reference to a stop source.
If source is NULL, this function has no effect.
void stop_source_release | ( | stop_source_t * | source | ) |
Releases a reference to a stop source.
If this is the last reference to the source, the source is destroyed. If no references remain to its associated stop token, the stop-state is destroyed. The object pointed to by source MUST NOT be referenced after this function has been invoked.
int stop_source_request_stop | ( | stop_source_t * | source | ) |
Issues a stop request to the stop-state associated with the specified stop source, if it has not already received a stop request.
Once a stop is requested, it cannot be withdrawn. If a stop request is issued, any stop_func callbacks registered with the associated stop token are invoked synchronously on the calling thread.
int stop_source_stop_requested | ( | const stop_source_t * | source | ) |
Checks if the stop-state associated with the specified stop source has received a stop request.