QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
async.h
Go to the documentation of this file.
1/*
2 * 2025 Quantum Resistant Cryptographic Solutions Corporation
3 * All Rights Reserved.
4 *
5 * NOTICE: This software and all accompanying materials are the exclusive
6 * property of Quantum Resistant Cryptographic Solutions Corporation (QRCS).
7 * The intellectual and technical concepts contained within this implementation
8 * are proprietary to QRCS and its authorized licensors and are protected under
9 * applicable U.S. and international copyright, patent, and trade secret laws.
10 *
11 * CRYPTOGRAPHIC STANDARDS:
12 * - This software includes implementations of cryptographic algorithms such as
13 * SHA3, AES, and others. These algorithms are public domain or standardized
14 * by organizations such as NIST and are NOT the property of QRCS.
15 * - However, all source code, optimizations, and implementations in this library
16 * are original works of QRCS and are protected under this license.
17 *
18 * RESTRICTIONS:
19 * - Redistribution, modification, or unauthorized distribution of this software,
20 * in whole or in part, is strictly prohibited.
21 * - This software is provided for non-commercial, educational, and research
22 * purposes only. Commercial use in any form is expressly forbidden.
23 * - Licensing and authorized distribution are solely at the discretion of QRCS.
24 * - Any use of this software implies acceptance of these restrictions.
25 *
26 * DISCLAIMER:
27 * This software is provided "as is," without warranty of any kind, express or
28 * implied, including but not limited to warranties of merchantability or fitness
29 * for a particular purpose. QRCS disclaims all liability for any direct, indirect,
30 * incidental, or consequential damages resulting from the use or misuse of this software.
31 *
32 * FULL LICENSE:
33 * This software is subject to the Quantum Resistant Cryptographic Solutions
34 * Proprietary License (QRCS-PL). The complete license terms are included
35 * in the LICENSE.txt file distributed with this software.
36 *
37 * Written by: John G. Underhill
38 * Contact: john.underhill@protonmail.com
39 */
40
41#ifndef QSC_THREADS_H
42#define QSC_THREADS_H
43
44#include "common.h"
45#include <stdarg.h>
46
47#if defined(QSC_SYSTEM_OS_WINDOWS)
48 /* Windows-specific thread and mutex definitions */
50 #include <process.h>
51 #include <Windows.h>
52 typedef HANDLE qsc_mutex;
53 typedef HANDLE qsc_thread;
54#elif defined(QSC_SYSTEM_OS_POSIX)
55 #include <sys/types.h>
56 #include <unistd.h>
57 #include <pthread.h>
58 typedef pthread_mutex_t qsc_mutex;
59 typedef pthread_t qsc_thread;
60#else
61 #error your operating system is not supported!
62#endif
63
64QSC_CPLUSPLUS_ENABLED_START
65
95
100#define QSC_ASYNC_PARALLEL_MAX 128ULL
101
102/* Function Declarations */
103
112QSC_EXPORT_API void qsc_async_launch_thread(void (*func)(void*), void* state);
113
123QSC_EXPORT_API void qsc_async_launch_parallel_threads(void (*func)(void*), size_t count, ...);
124
133
142QSC_EXPORT_API bool qsc_async_mutex_destroy(qsc_mutex mtx);
143
151QSC_EXPORT_API void qsc_async_mutex_lock(qsc_mutex mtx);
152
161
169QSC_EXPORT_API void qsc_async_mutex_unlock(qsc_mutex mtx);
170
178QSC_EXPORT_API void qsc_async_mutex_unlock_ex(qsc_mutex mtx);
179
188
198QSC_EXPORT_API qsc_thread qsc_async_thread_create(void (*func)(void*), void* state);
199
209QSC_EXPORT_API qsc_thread qsc_async_thread_create_ex(void (*func)(void**), void** args);
210
219QSC_EXPORT_API int32_t qsc_async_thread_resume(qsc_thread handle);
220
228QSC_EXPORT_API void qsc_async_thread_sleep(uint32_t msec);
229
238QSC_EXPORT_API int32_t qsc_async_thread_suspend(qsc_thread handle);
239
248QSC_EXPORT_API bool qsc_async_thread_terminate(qsc_thread handle);
249
257QSC_EXPORT_API void qsc_async_thread_wait(qsc_thread handle);
258
267QSC_EXPORT_API void qsc_async_thread_wait_time(qsc_thread handle, uint32_t msec);
268
277QSC_EXPORT_API void qsc_async_thread_wait_all(qsc_thread* handles, size_t count);
278
279QSC_CPLUSPLUS_ENABLED_END
280
281#endif
QSC_EXPORT_API qsc_mutex qsc_async_mutex_lock_ex(void)
Create and lock a mutex.
Definition async.c:183
QSC_EXPORT_API int32_t qsc_async_thread_suspend(qsc_thread handle)
Suspend a thread.
Definition async.c:310
QSC_EXPORT_API void qsc_async_thread_wait(qsc_thread handle)
Wait for a thread to complete execution.
Definition async.c:348
QSC_EXPORT_API qsc_mutex qsc_async_mutex_create(void)
Create a mutex.
Definition async.c:144
QSC_EXPORT_API qsc_thread qsc_async_thread_create_ex(void(*func)(void **), void **args)
Create a thread with multiple parameters.
Definition async.c:249
QSC_EXPORT_API void qsc_async_thread_sleep(uint32_t msec)
Suspend the calling thread for a specified number of milliseconds.
Definition async.c:295
QSC_EXPORT_API void qsc_async_mutex_unlock(qsc_mutex mtx)
Unlock a mutex.
Definition async.c:193
QSC_EXPORT_API bool qsc_async_mutex_destroy(qsc_mutex mtx)
Destroy a mutex.
Definition async.c:159
QSC_EXPORT_API void qsc_async_launch_thread(void(*func)(void *), void *state)
Launch a function on a new thread.
Definition async.c:103
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:119
QSC_EXPORT_API qsc_thread qsc_async_thread_create(void(*func)(void *), void *state)
Create a thread with one parameter.
Definition async.c:224
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:361
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:374
QSC_EXPORT_API bool qsc_async_thread_terminate(qsc_thread handle)
Terminate a thread.
Definition async.c:332
QSC_EXPORT_API int32_t qsc_async_thread_resume(qsc_thread handle)
Resume a suspended thread.
Definition async.c:275
QSC_EXPORT_API void qsc_async_mutex_unlock_ex(qsc_mutex mtx)
Unlock and destroy a mutex.
Definition async.c:202
QSC_EXPORT_API void qsc_async_mutex_lock(qsc_mutex mtx)
Lock a mutex.
Definition async.c:174
QSC_EXPORT_API size_t qsc_async_processor_count(void)
Get the number of processor cores available.
Definition async.c:208
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 common.h:520
#define QSC_SYSTEM_CONDITION_IGNORE(x)
MSVC-specific macro to disable a specific warning condition.
Definition common.h:784