QSC Post Quantum Cryptographic Library 1.3.0.0 (C1)
A post quantum secure library written in Ansi C
Loading...
Searching...
No Matches
async.h
Go to the documentation of this file.
1/* 2020-2026 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE:
5 * This software and all accompanying materials are the exclusive property of
6 * Quantum Resistant Cryptographic Solutions Corporation (QRCS). The intellectual
7 * and technical concepts contained herein are proprietary to QRCS and are
8 * protected under applicable Canadian, U.S., and international copyright,
9 * patent, and trade secret laws.
10 *
11 * CRYPTOGRAPHIC ALGORITHMS AND IMPLEMENTATIONS:
12 * - This software includes implementations of cryptographic primitives and
13 * algorithms that are standardized or in the public domain, such as AES
14 * and SHA-3, which are not proprietary to QRCS.
15 * - This software also includes cryptographic primitives, constructions, and
16 * algorithms designed by QRCS, including but not limited to RCS, SCB, CSX, QMAC, and
17 * related components, which are proprietary to QRCS.
18 * - All source code, implementations, protocol compositions, optimizations,
19 * parameter selections, and engineering work contained in this software are
20 * original works of QRCS and are protected under this license.
21 *
22 * LICENSE AND USE RESTRICTIONS:
23 * - This software is licensed under the Quantum Resistant Cryptographic Solutions
24 * Public Research and Evaluation License (QRCS-PREL), 2025-2026.
25 * - Permission is granted solely for non-commercial evaluation, academic research,
26 * cryptographic analysis, interoperability testing, and feasibility assessment.
27 * - Commercial use, production deployment, commercial redistribution, or
28 * integration into products or services is strictly prohibited without a
29 * separate written license agreement executed with QRCS.
30 * - Licensing and authorized distribution are solely at the discretion of QRCS.
31 *
32 * EXPERIMENTAL CRYPTOGRAPHY NOTICE:
33 * Portions of this software may include experimental, novel, or evolving
34 * cryptographic designs. Use of this software is entirely at the user's risk.
35 *
36 * DISCLAIMER:
37 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS
39 * FOR A PARTICULAR PURPOSE, SECURITY, OR NON-INFRINGEMENT. QRCS DISCLAIMS ALL
40 * LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
41 * ARISING FROM THE USE OR MISUSE OF THIS SOFTWARE.
42 *
43 * FULL LICENSE:
44 * This software is subject to the Quantum Resistant Cryptographic Solutions
45 * Public Research and Evaluation License (QRCS-PREL), 2025-2026. The complete license terms
46 * are provided in the accompanying LICENSE file or at https://www.qrcscorp.ca.
47 *
48 * Written by: John G. Underhill
49 * Contact: contact@qrcscorp.ca
50 */
51
52#ifndef QSC_THREADS_H
53#define QSC_THREADS_H
54
55#include "qsccommon.h"
56#include <stdarg.h>
57
58#if defined(QSC_SYSTEM_OS_WINDOWS)
59 typedef void* qsc_mutex;
60 typedef void* qsc_thread;
61#elif defined(QSC_SYSTEM_OS_POSIX)
62# ifndef _XOPEN_SOURCE
63# define _XOPEN_SOURCE 700
64# endif
65# ifndef _DARWIN_C_SOURCE
66# define _DARWIN_C_SOURCE
67# endif
68# include <pthread.h>
69 typedef pthread_mutex_t* qsc_mutex;
70 typedef pthread_t qsc_thread;
71#else
72# error your operating system is not supported!
73#endif
74
75QSC_CPLUSPLUS_ENABLED_START
76
106
111#define QSC_ASYNC_PARALLEL_MAX 128ULL
112
125QSC_EXPORT_API bool qsc_async_atomic_bool_load(volatile bool* target);
126
138QSC_EXPORT_API void qsc_async_atomic_bool_store(volatile bool* target, bool value);
139
153QSC_EXPORT_API bool qsc_async_atomic_bool_exchange(volatile bool* target, bool value);
154
170QSC_EXPORT_API bool qsc_async_atomic_bool_compare_exchange(volatile bool* target, bool expected, bool desired);
171
181QSC_EXPORT_API int32_t qsc_async_atomic_int32_load(volatile int32_t* target);
182
191QSC_EXPORT_API void qsc_async_atomic_int32_store(volatile int32_t* target, int32_t value);
192
203QSC_EXPORT_API int32_t qsc_async_atomic_int32_exchange(volatile int32_t* target, int32_t value);
204
217QSC_EXPORT_API bool qsc_async_atomic_int32_compare_exchange(volatile int32_t* target, int32_t expected, int32_t desired);
218
229QSC_EXPORT_API int32_t qsc_async_atomic_int32_add(volatile int32_t* target, int32_t value);
230
241QSC_EXPORT_API int32_t qsc_async_atomic_int32_subtract(volatile int32_t* target, int32_t value);
242
252QSC_EXPORT_API int32_t qsc_async_atomic_int32_increment(volatile int32_t* target);
253
263QSC_EXPORT_API int32_t qsc_async_atomic_int32_decrement(volatile int32_t* target);
264
273QSC_EXPORT_API void qsc_async_launch_thread(void (*func)(void*), void* state);
274
284QSC_EXPORT_API void qsc_async_launch_parallel_threads(void (*func)(void*), size_t count, ...);
285
294
303QSC_EXPORT_API bool qsc_async_mutex_destroy(qsc_mutex mtx);
304
312QSC_EXPORT_API void qsc_async_mutex_lock(qsc_mutex mtx);
313
322
330QSC_EXPORT_API void qsc_async_mutex_unlock(qsc_mutex mtx);
331
339QSC_EXPORT_API void qsc_async_mutex_unlock_ex(qsc_mutex mtx);
340
349
360QSC_EXPORT_API qsc_thread qsc_async_thread_create(void (*func)(void*), void* state);
361
372QSC_EXPORT_API qsc_thread qsc_async_thread_create_ex(void (*func)(void**), void** args);
373
383QSC_EXPORT_API qsc_thread qsc_async_thread_create_noargs(void (*func)(void));
384
394QSC_EXPORT_API int32_t qsc_async_thread_resume(qsc_thread handle);
395
403QSC_EXPORT_API void qsc_async_thread_sleep(uint32_t msec);
404
414QSC_EXPORT_API int32_t qsc_async_thread_suspend(qsc_thread handle);
415
425QSC_EXPORT_API bool qsc_async_thread_terminate(qsc_thread handle);
426
434QSC_EXPORT_API void qsc_async_thread_wait(qsc_thread handle);
435
444QSC_EXPORT_API void qsc_async_thread_wait_time(qsc_thread handle, uint32_t msec);
445
454QSC_EXPORT_API void qsc_async_thread_wait_all(qsc_thread* handles, size_t count);
455
456QSC_CPLUSPLUS_ENABLED_END
457
458#endif
QSC_EXPORT_API qsc_mutex qsc_async_mutex_lock_ex(void)
Create and lock a mutex.
Definition async.c:367
QSC_EXPORT_API int32_t qsc_async_atomic_int32_increment(volatile int32_t *target)
Atomically increment an int32_t by one.
Definition async.c:245
QSC_EXPORT_API int32_t qsc_async_thread_suspend(qsc_thread handle)
Suspend a thread.
Definition async.c:594
QSC_EXPORT_API void qsc_async_thread_wait(qsc_thread handle)
Wait for a thread to complete execution.
Definition async.c:636
QSC_EXPORT_API qsc_mutex qsc_async_mutex_create(void)
Create a mutex.
Definition async.c:322
QSC_EXPORT_API qsc_thread qsc_async_thread_create_ex(void(*func)(void **), void **args)
Create a thread with multiple parameters.
Definition async.c:507
QSC_EXPORT_API void qsc_async_thread_sleep(uint32_t msec)
Suspend the calling thread for a specified number of milliseconds.
Definition async.c:576
QSC_EXPORT_API void qsc_async_mutex_unlock(qsc_mutex mtx)
Unlock a mutex.
Definition async.c:377
QSC_EXPORT_API bool qsc_async_mutex_destroy(qsc_mutex mtx)
Destroy a mutex.
Definition async.c:339
QSC_EXPORT_API int32_t qsc_async_atomic_int32_add(volatile int32_t *target, int32_t value)
Atomically add a value to an int32_t.
Definition async.c:203
QSC_EXPORT_API int32_t qsc_async_atomic_int32_exchange(volatile int32_t *target, int32_t value)
Atomically exchange an int32_t value.
Definition async.c:163
QSC_EXPORT_API int32_t qsc_async_atomic_int32_load(volatile int32_t *target)
Atomically load an int32_t value.
Definition async.c:128
QSC_EXPORT_API void qsc_async_launch_thread(void(*func)(void *), void *state)
Launch a function on a new thread.
Definition async.c:287
QSC_EXPORT_API qsc_thread qsc_async_thread_create_noargs(void(*func)(void))
Create a thread with no arguments parameter.
Definition async.c:534
QSC_EXPORT_API bool qsc_async_atomic_bool_load(volatile bool *target)
Atomically load the current value of a boolean.
Definition async.c:53
QSC_EXPORT_API bool qsc_async_atomic_bool_exchange(volatile bool *target, bool value)
Atomically swap a boolean with a new value.
Definition async.c:88
QSC_EXPORT_API void qsc_async_launch_parallel_threads(void(*func)(void *), size_t count,...)
Launch multiple threads in parallel using variadic arguments.
Definition async.c:300
QSC_EXPORT_API qsc_thread qsc_async_thread_create(void(*func)(void *), void *state)
Create a thread with one parameter.
Definition async.c:482
QSC_EXPORT_API void qsc_async_atomic_bool_store(volatile bool *target, bool value)
Atomically store a value into a boolean.
Definition async.c:74
QSC_EXPORT_API void qsc_async_thread_wait_time(qsc_thread handle, uint32_t msec)
Wait for a thread to complete execution with a timeout.
Definition async.c:646
QSC_EXPORT_API void qsc_async_thread_wait_all(qsc_thread *handles, size_t count)
Wait for an array of threads to complete execution.
Definition async.c:670
QSC_EXPORT_API bool qsc_async_thread_terminate(qsc_thread handle)
Terminate a thread.
Definition async.c:618
QSC_EXPORT_API int32_t qsc_async_thread_resume(qsc_thread handle)
Resume a suspended thread.
Definition async.c:559
QSC_EXPORT_API void qsc_async_mutex_unlock_ex(qsc_mutex mtx)
Unlock and destroy a mutex.
Definition async.c:386
QSC_EXPORT_API bool qsc_async_atomic_int32_compare_exchange(volatile int32_t *target, int32_t expected, int32_t desired)
Atomically compare and conditionally exchange an int32_t value.
Definition async.c:183
QSC_EXPORT_API void qsc_async_mutex_lock(qsc_mutex mtx)
Lock a mutex.
Definition async.c:358
QSC_EXPORT_API size_t qsc_async_processor_count(void)
Get the number of processor cores available.
Definition async.c:473
QSC_EXPORT_API int32_t qsc_async_atomic_int32_subtract(volatile int32_t *target, int32_t value)
Atomically subtract a value from an int32_t.
Definition async.c:224
QSC_EXPORT_API void qsc_async_atomic_int32_store(volatile int32_t *target, int32_t value)
Atomically store an int32_t value.
Definition async.c:149
QSC_EXPORT_API int32_t qsc_async_atomic_int32_decrement(volatile int32_t *target)
Atomically decrement an int32_t by one.
Definition async.c:266
QSC_EXPORT_API bool qsc_async_atomic_bool_compare_exchange(volatile bool *target, bool expected, bool desired)
Atomically compare a boolean and conditionally store a new value.
Definition async.c:108
Contains common definitions for the Quantum Secure Cryptographic (QSC) library.
#define QSC_EXPORT_API
API export macro for Microsoft compilers when importing from a DLL.
Definition qsccommon.h:645