]> git.ipfire.org Git - thirdparty/openssl.git/blob - include/internal/thread_arch.h
thread: remove remnants of ossl_crypto_mem_barrier
[thirdparty/openssl.git] / include / internal / thread_arch.h
1 /*
2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #ifndef OSSL_INTERNAL_THREAD_ARCH_H
11 # define OSSL_INTERNAL_THREAD_ARCH_H
12 # include <openssl/configuration.h>
13 # include <openssl/e_os2.h>
14
15 # if defined(_WIN32)
16 # include <windows.h>
17 # endif
18
19 # if defined(OPENSSL_THREADS) && defined(OPENSSL_SYS_UNIX)
20 # define OPENSSL_THREADS_POSIX
21 # elif defined(OPENSSL_THREADS) && defined(OPENSSL_SYS_VMS)
22 # define OPENSSL_THREADS_POSIX
23 # elif defined(OPENSSL_THREADS) && defined(OPENSSL_SYS_WINDOWS) && \
24 defined(_WIN32_WINNT)
25 # if _WIN32_WINNT >= 0x0600
26 # define OPENSSL_THREADS_WINNT
27 # else
28 # define OPENSSL_THREADS_NONE
29 # endif
30 # else
31 # define OPENSSL_THREADS_NONE
32 # endif
33
34 # include <openssl/crypto.h>
35
36 typedef void CRYPTO_MUTEX;
37 typedef void CRYPTO_CONDVAR;
38
39 CRYPTO_MUTEX *ossl_crypto_mutex_new(void);
40 void ossl_crypto_mutex_lock(CRYPTO_MUTEX *mutex);
41 int ossl_crypto_mutex_try_lock(CRYPTO_MUTEX *mutex);
42 void ossl_crypto_mutex_unlock(CRYPTO_MUTEX *mutex);
43 void ossl_crypto_mutex_free(CRYPTO_MUTEX **mutex);
44
45 CRYPTO_CONDVAR *ossl_crypto_condvar_new(void);
46 void ossl_crypto_condvar_wait(CRYPTO_CONDVAR *cv, CRYPTO_MUTEX *mutex);
47 void ossl_crypto_condvar_broadcast(CRYPTO_CONDVAR *cv);
48 void ossl_crypto_condvar_free(CRYPTO_CONDVAR **cv);
49
50 typedef uint32_t CRYPTO_THREAD_RETVAL;
51 typedef CRYPTO_THREAD_RETVAL (*CRYPTO_THREAD_ROUTINE)(void *);
52 typedef CRYPTO_THREAD_RETVAL (*CRYPTO_THREAD_ROUTINE_CB)(void *,
53 void (**)(void *),
54 void **);
55
56 # define CRYPTO_THREAD_NO_STATE 0UL
57 # define CRYPTO_THREAD_FINISHED (1UL << 0)
58 # define CRYPTO_THREAD_JOIN_AWAIT (1UL << 1)
59 # define CRYPTO_THREAD_JOINED (1UL << 2)
60
61 # define CRYPTO_THREAD_GET_STATE(THREAD, FLAG) ((THREAD)->state & (FLAG))
62 # define CRYPTO_THREAD_GET_ERROR(THREAD, FLAG) (((THREAD)->state >> 16) & (FLAG))
63
64 typedef struct crypto_thread_st {
65 uint32_t state;
66 void *data;
67 CRYPTO_THREAD_ROUTINE routine;
68 CRYPTO_THREAD_RETVAL retval;
69 void *handle;
70 CRYPTO_MUTEX *lock;
71 CRYPTO_MUTEX *statelock;
72 CRYPTO_CONDVAR *condvar;
73 unsigned long thread_id;
74 int joinable;
75 OSSL_LIB_CTX *ctx;
76 } CRYPTO_THREAD;
77
78 # if defined(OPENSSL_THREADS)
79
80 # define CRYPTO_THREAD_UNSET_STATE(THREAD, FLAG) \
81 do { \
82 (THREAD)->state &= ~(FLAG); \
83 } while ((void)0, 0)
84
85 # define CRYPTO_THREAD_SET_STATE(THREAD, FLAG) \
86 do { \
87 (THREAD)->state |= (FLAG); \
88 } while ((void)0, 0)
89
90 # define CRYPTO_THREAD_SET_ERROR(THREAD, FLAG) \
91 do { \
92 (THREAD)->state |= ((FLAG) << 16); \
93 } while ((void)0, 0)
94
95 # define CRYPTO_THREAD_UNSET_ERROR(THREAD, FLAG) \
96 do { \
97 (THREAD)->state &= ~((FLAG) << 16); \
98 } while ((void)0, 0)
99
100 # else
101
102 # define CRYPTO_THREAD_UNSET_STATE(THREAD, FLAG)
103 # define CRYPTO_THREAD_SET_STATE(THREAD, FLAG)
104 # define CRYPTO_THREAD_SET_ERROR(THREAD, FLAG)
105 # define CRYPTO_THREAD_UNSET_ERROR(THREAD, FLAG)
106
107 # endif /* defined(OPENSSL_THREADS) */
108
109 CRYPTO_THREAD * ossl_crypto_thread_native_start(CRYPTO_THREAD_ROUTINE routine,
110 void *data, int joinable);
111 int ossl_crypto_thread_native_spawn(CRYPTO_THREAD *thread);
112 int ossl_crypto_thread_native_join(CRYPTO_THREAD *thread,
113 CRYPTO_THREAD_RETVAL *retval);
114 int ossl_crypto_thread_native_perform_join(CRYPTO_THREAD *thread,
115 CRYPTO_THREAD_RETVAL *retval);
116 int ossl_crypto_thread_native_exit(void);
117 int ossl_crypto_thread_native_is_self(CRYPTO_THREAD *thread);
118 int ossl_crypto_thread_native_clean(CRYPTO_THREAD *thread);
119
120 #endif /* OSSL_INTERNAL_THREAD_ARCH_H */