46#if LELY_NO_THREADS || (LELY_NO_ATOMICS && (!_WIN32 || defined(__MINGW32__)))
48#elif _WIN64 && !defined(__MINGW32__)
50#elif _WIN32 && !defined(__MINGW32__)
76#if LELY_NO_THREADS || (LELY_NO_ATOMICS && (!_WIN32 || defined(__MINGW32__)))
78#elif _WIN64 && !defined(__MINGW32__)
79 volatile LONGLONG
value;
80#elif _WIN32 && !defined(__MINGW32__)
95static void *stop_source_alloc(
void);
96static void stop_source_free(
void *ptr);
107#if LELY_NO_THREADS || (LELY_NO_ATOMICS && (!_WIN32 || defined(__MINGW32__)))
109#elif _WIN64 && !defined(__MINGW32__)
110 InterlockedIncrementNoFence64(&token->
refcnt);
111#elif _WIN32 && !defined(__MINGW32__)
112 InterlockedIncrementNoFence(&token->
refcnt);
125#if LELY_NO_THREADS || (LELY_NO_ATOMICS && (!_WIN32 || defined(__MINGW32__)))
127#elif _WIN64 && !defined(__MINGW32__)
128 if (!InterlockedDecrementRelease64(&token->
refcnt)) {
130#elif _WIN32 && !defined(__MINGW32__)
131 if (!InterlockedDecrementRelease(&token->
refcnt)) {
138 stop_source_destroy(stop_source_from_token(token));
153#if LELY_NO_THREADS || LELY_NO_ATOMICS
154 size_t value = source->
value;
168#if LELY_NO_THREADS || LELY_NO_ATOMICS
169 size_t value = source->
value;
247 stop_source_free(source);
258#if LELY_NO_THREADS || (LELY_NO_ATOMICS && (!_WIN32 || defined(__MINGW32__)))
260#elif _WIN64 && !defined(__MINGW32__)
261 InterlockedAddNoFence64(&source->
value, 2);
262#elif _WIN32 && !defined(__MINGW32__)
263 InterlockedaddNoFence(&source->
value, 2);
278#elif _WIN64 && !defined(__MINGW32__)
279 InterlockedAddRelease64(&source->
value, -2);
280#elif _WIN32 && !defined(__MINGW32__)
281 InterlockedAddRelease(&source->
value, -2);
298#if LELY_NO_THREADS || LELY_NO_ATOMICS
299 if (source->
value & 1)
309#if LELY_NO_THREADS || (LELY_NO_ATOMICS && (!_WIN32 || defined(__MINGW32__)))
312#if _WIN64 && !defined(__MINGW32__)
313 LONGLONG value = InterlockedOrNoFence64(&source->
value, 1);
314#elif _WIN32 && !defined(__MINGW32__)
315 LONG value = InterlockedOrNoFence(&source->
value, 1);
370#if LELY_NO_THREADS || LELY_NO_ATOMICS
371 return source->
value & 1;
395#if LELY_NO_THREADS || LELY_NO_ATOMICS || (_WIN32 && !defined(__MINGW32__))
409 goto error_init_cond;
450stop_source_alloc(
void)
461stop_source_free(
void *ptr)
471#if LELY_NO_THREADS || LELY_NO_ATOMICS || (_WIN32 && !defined(__MINGW32__))
477 if (!stop_token_init(&source->
token))
488 stop_token_fini(&source->
token);
495 stop_source_fini(source);
496 stop_source_free(source);
This header file is part of the utilities library; it contains the native and platform-independent er...
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
This is the public header file of the utilities library.
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
void sllist_init(struct sllist *list)
Initializes a singly-linked list.
void sllist_push_front(struct sllist *list, struct slnode *node)
Pushes a node to the front of a singly-linked list.
struct slnode * sllist_remove(struct sllist *list, struct slnode *node)
Removes a node from a singly-linked list.
struct slnode * sllist_pop_front(struct sllist *list)
Pops a node from the front of a singly-linked list.
This is the internal header file of the utilities library.
This header file is part of the C11 and POSIX compatibility library; it includes <stdatomic....
@ memory_order_release
A store operation performs a release operation on the affected memory location.
@ memory_order_relaxed
No operation orders memory.
@ memory_order_acquire
A load operation performs an acquire operation on the affected memory location.
#define atomic_fetch_add_explicit(object, operand, order)
Atomically replaces the value at object with *object + operand.
#define atomic_load_explicit(object, order)
Atomically returns the value at object.
#define atomic_fetch_or_explicit(object, operand, order)
Atomically replaces the value at object with *object | operand.
void atomic_thread_fence(memory_order order)
Inserts a fence with semantics according to order.
#define atomic_init(obj, value)
Initializes the atomic object at obj with the value value.
#define atomic_fetch_sub_explicit(object, operand, order)
Atomically replaces the value at object with *object - operand.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....
int stop_token_insert(stop_token_t *token, struct stop_func *func)
Registers a callback function with the specified stop token.
void stop_token_release(stop_token_t *token)
Releases a reference to a stop token.
int stop_source_request_stop(stop_source_t *source)
Issues a stop request to the stop-state associated with the specified stop source,...
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.
stop_source_t * stop_source_acquire(stop_source_t *source)
Acquires a reference to a stop source.
void stop_source_release(stop_source_t *source)
Releases a reference to a stop source.
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.
void stop_token_remove(stop_token_t *token, struct stop_func *func)
Deregisters a callback function from the specified stop token.
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,...
stop_source_t * stop_source_create(void)
Creates a stop source with a new stop-state.
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.
stop_token_t * stop_token_acquire(stop_token_t *token)
Acquires a reference to a stop token.
This header file is part of the utilities library; it contains the stop token declarations.
A node in a singly-linked list.
An object providing the means to register a callback function with an stop_token_t object.
void(* func)(struct stop_func *func)
The function to be invoked when a stop request is issued.
thrd_t thr
The identifier of the thread invoking stop_source_request_stop().
struct stop_token token
The stop token associated with this source.
atomic_size_t value
Twice the number of references to this source, plus a single (least significant) bit indicating wheth...
atomic_size_t refcnt
The number of references to this token or its associated source.
cnd_t cond
The condition variable signaled once func completes.
struct sllist queue
The queue of callback functions registered with this token.
struct stop_func * func
A pointer to the currently running callback.
This header file is part of the C11 and POSIX compatibility library; it includes <threads....
int cnd_init(cnd_t *cond)
Creates a condition variable.
int thrd_equal(thrd_t thr0, thrd_t thr1)
Determines whether the thread identified by thr0 refers to the thread identified by thr1.
pthread_t thrd_t
A complete object type that holds an identifier for a thread.
int mtx_init(mtx_t *mtx, int type)
Creates a mutex object with properties indicated by type, which must have one of the four values:
int mtx_lock(mtx_t *mtx)
Blocks until it locks the mutex at mtx.
pthread_cond_t cnd_t
A complete object type that holds an identifier for a condition variable.
void cnd_destroy(cnd_t *cond)
Releases all resources used by the condition variable at cond.
thrd_t thrd_current(void)
Identifies the thread that called it.
int cnd_wait(cnd_t *cond, mtx_t *mtx)
Atomically unlocks the mutex at mtx and endeavors to block until the condition variable at cond is si...
@ thrd_success
Indicates that the requested operation succeeded.
int mtx_unlock(mtx_t *mtx)
Unlocks the mutex at mtx.
pthread_mutex_t mtx_t
A complete object type that holds an identifier for a mutex.
void mtx_destroy(mtx_t *mtx)
Releases any resources used by the mutex at mtx.
int cnd_signal(cnd_t *cond)
Unblocks one of the threads that are blocked on the condition variable at cond at the time of the cal...
@ mtx_plain
A mutex type that supports neither timeout nor test and return.