Mbed TLS v4.1.1
Toggle main menu visibility
Loading...
Searching...
No Matches
threading.h
Go to the documentation of this file.
1
6
/*
7
* Copyright The Mbed TLS Contributors
8
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9
*/
10
#ifndef MBEDTLS_THREADING_H
11
#define MBEDTLS_THREADING_H
12
#include "mbedtls/private_access.h"
13
14
#include "
tf-psa-crypto/build_info.h
"
15
#include "
mbedtls/compat-3-crypto.h
"
16
17
#include <stdlib.h>
18
19
#ifdef __cplusplus
20
extern
"C"
{
21
#endif
22
30
#define MBEDTLS_ERR_THREADING_USAGE_ERROR -0x001E
31
33
#define MBEDTLS_ERR_THREADING_MUTEX_ERROR MBEDTLS_ERR_THREADING_USAGE_ERROR
34
35
#if defined(MBEDTLS_THREADING_C)
36
37
#if defined(MBEDTLS_THREADING_PTHREAD)
38
#include <pthread.h>
39
typedef
pthread_mutex_t
mbedtls_platform_mutex_t
;
40
typedef
pthread_cond_t
mbedtls_platform_condition_variable_t
;
41
#endif
42
43
#if defined(MBEDTLS_THREADING_ALT)
44
/* You should define the types mbedtls_platform_mutex_t and
45
* mbedtls_platform_condition_variable_t in your header. */
46
#include "
threading_alt.h
"
47
109
void
mbedtls_threading_set_alt(
110
int
(*mutex_init)(
mbedtls_platform_mutex_t
*),
111
void
(*mutex_destroy)(
mbedtls_platform_mutex_t
*),
112
int
(*mutex_lock)(
mbedtls_platform_mutex_t
*),
113
int
(*mutex_unlock)(
mbedtls_platform_mutex_t
*),
114
int
(*cond_init)(
mbedtls_platform_condition_variable_t
*),
115
void
(*cond_destroy)(
mbedtls_platform_condition_variable_t
*),
116
int
(*cond_signal)(
mbedtls_platform_condition_variable_t
*),
117
int
(*cond_broadcast)(
mbedtls_platform_condition_variable_t
*),
118
int
(*cond_wait)(
mbedtls_platform_condition_variable_t
*,
119
mbedtls_platform_mutex_t
*));
120
124
void
mbedtls_threading_free_alt(
void
);
125
#endif
/* MBEDTLS_THREADING_ALT */
126
127
typedef
struct
mbedtls_threading_mutex_t
{
128
mbedtls_platform_mutex_t
MBEDTLS_PRIVATE(mutex);
129
130
/* Whether the mutex has been initialized successfully.
131
*
132
* Attempting to lock or destroy a platform mutex that hasn't been
133
* successfully initialized can cause a crash or other undefined
134
* behavior on some platforms. Keeping track of a successful
135
* initialization makes it possible to turn such misuse into
136
* a predictable error. This is especially useful because
137
* mbedtls_mutex_init() doesn't return an error code, for
138
* historical reasons, so the application cannot handle such
139
* failures by itself.
140
*/
141
char
MBEDTLS_PRIVATE(initialized);
142
143
/* WARNING - state should only be accessed when holding the mutex lock in
144
* framework/tests/src/threading_helpers.c, otherwise corruption can occur.
145
* state will be 0 after a failed init or a free, and nonzero after a
146
* successful init. This field is for testing only and thus not considered
147
* part of the public API of Mbed TLS and may change without notice.*/
148
char
MBEDTLS_PRIVATE(state);
149
150
}
mbedtls_threading_mutex_t
;
151
152
typedef
struct
mbedtls_threading_condition_variable_t
{
153
mbedtls_platform_condition_variable_t
MBEDTLS_PRIVATE(cond);
154
}
mbedtls_threading_condition_variable_t
;
155
174
void
mbedtls_mutex_init
(
mbedtls_threading_mutex_t
*mutex);
175
195
void
mbedtls_mutex_free
(
mbedtls_threading_mutex_t
*mutex);
196
226
int
mbedtls_mutex_lock
(
mbedtls_threading_mutex_t
*mutex);
227
254
int
mbedtls_mutex_unlock
(
mbedtls_threading_mutex_t
*mutex);
255
278
int
mbedtls_condition_variable_init
(
279
mbedtls_threading_condition_variable_t
*cond);
280
281
295
void
mbedtls_condition_variable_free
(
296
mbedtls_threading_condition_variable_t
*cond);
297
321
int
mbedtls_condition_variable_signal
(
322
mbedtls_threading_condition_variable_t
*cond);
323
345
int
mbedtls_condition_variable_broadcast
(
346
mbedtls_threading_condition_variable_t
*cond);
347
385
int
mbedtls_condition_variable_wait
(
386
mbedtls_threading_condition_variable_t
*cond,
387
mbedtls_threading_mutex_t
*mutex);
388
389
/*
390
* Global mutexes
391
*/
392
#if defined(MBEDTLS_FS_IO)
393
extern
mbedtls_threading_mutex_t
mbedtls_threading_readdir_mutex
;
394
#endif
395
396
#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT)
397
/* This mutex may or may not be used in the default definition of
398
* mbedtls_platform_gmtime_r(), but in order to determine that,
399
* we need to check POSIX features, hence modify _POSIX_C_SOURCE.
400
* With the current approach, this declaration is orphaned, lacking
401
* an accompanying definition, in case mbedtls_platform_gmtime_r()
402
* doesn't need it, but that's not a problem. */
403
extern
mbedtls_threading_mutex_t
mbedtls_threading_gmtime_mutex
;
404
#endif
/* MBEDTLS_HAVE_TIME_DATE && !MBEDTLS_PLATFORM_GMTIME_R_ALT */
405
406
#endif
/* MBEDTLS_THREADING_C */
407
408
#ifdef __cplusplus
409
}
410
#endif
411
412
#endif
/* MBEDTLS_THREADING_H */
compat-3-crypto.h
Compatibility definitions for MbedTLS 3.x code built with MbedTLS 4.x or TF-PSA-Crypto 1....
mbedtls_threading_condition_variable_t
Definition
threading.h:152
mbedtls_threading_mutex_t
Definition
threading.h:127
build_info.h
Build-time configuration info.
mbedtls_condition_variable_signal
int mbedtls_condition_variable_signal(mbedtls_threading_condition_variable_t *cond)
mbedtls_condition_variable_wait
int mbedtls_condition_variable_wait(mbedtls_threading_condition_variable_t *cond, mbedtls_threading_mutex_t *mutex)
mbedtls_mutex_init
void mbedtls_mutex_init(mbedtls_threading_mutex_t *mutex)
mbedtls_condition_variable_init
int mbedtls_condition_variable_init(mbedtls_threading_condition_variable_t *cond)
mbedtls_platform_condition_variable_t
pthread_cond_t mbedtls_platform_condition_variable_t
Definition
threading.h:40
mbedtls_mutex_lock
int mbedtls_mutex_lock(mbedtls_threading_mutex_t *mutex)
mbedtls_mutex_free
void mbedtls_mutex_free(mbedtls_threading_mutex_t *mutex)
mbedtls_platform_mutex_t
pthread_mutex_t mbedtls_platform_mutex_t
Definition
threading.h:39
mbedtls_mutex_unlock
int mbedtls_mutex_unlock(mbedtls_threading_mutex_t *mutex)
mbedtls_threading_gmtime_mutex
mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex
mbedtls_threading_readdir_mutex
mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex
mbedtls_condition_variable_broadcast
int mbedtls_condition_variable_broadcast(mbedtls_threading_condition_variable_t *cond)
mbedtls_condition_variable_free
void mbedtls_condition_variable_free(mbedtls_threading_condition_variable_t *cond)
threading_alt.h
tf-psa-crypto
include
mbedtls
threading.h
Generated on
for Mbed TLS v4.1.1 by
1.17.0