Mbed TLS v2.28.8
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
13#if !defined(MBEDTLS_CONFIG_FILE)
14#include "mbedtls/config.h"
15#else
16#include MBEDTLS_CONFIG_FILE
17#endif
18
19#include <stdlib.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/* MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE is deprecated and should not be
26 * used. */
28#define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A
29
31#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C
33#define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E
34
35#if defined(MBEDTLS_THREADING_PTHREAD)
36#include <pthread.h>
38 pthread_mutex_t mutex;
39 /* is_valid is 0 after a failed init or a free, and nonzero after a
40 * successful init. This field is not considered part of the public
41 * API of Mbed TLS and may change without notice. */
44#endif
45
46#if defined(MBEDTLS_THREADING_ALT)
47/* You should define the mbedtls_threading_mutex_t type in your header */
48#include "threading_alt.h"
49
68void mbedtls_threading_set_alt(void (*mutex_init)(mbedtls_threading_mutex_t *),
69 void (*mutex_free)(mbedtls_threading_mutex_t *),
70 int (*mutex_lock)(mbedtls_threading_mutex_t *),
71 int (*mutex_unlock)(mbedtls_threading_mutex_t *));
72
76void mbedtls_threading_free_alt(void);
77#endif /* MBEDTLS_THREADING_ALT */
78
79#if defined(MBEDTLS_THREADING_C)
80/*
81 * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
82 *
83 * All these functions are expected to work or the result will be undefined.
84 */
89
90/*
91 * Global mutexes
92 */
93#if defined(MBEDTLS_FS_IO)
95#endif
96
97#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT)
98/* This mutex may or may not be used in the default definition of
99 * mbedtls_platform_gmtime_r(), but in order to determine that,
100 * we need to check POSIX features, hence modify _POSIX_C_SOURCE.
101 * With the current approach, this declaration is orphaned, lacking
102 * an accompanying definition, in case mbedtls_platform_gmtime_r()
103 * doesn't need it, but that's not a problem. */
105#endif /* MBEDTLS_HAVE_TIME_DATE && !MBEDTLS_PLATFORM_GMTIME_R_ALT */
106
107#endif /* MBEDTLS_THREADING_C */
108
109#ifdef __cplusplus
110}
111#endif
112
113#endif /* threading.h */
Configuration options (set of defines)
pthread_mutex_t mutex
Definition threading.h:38
void(* mbedtls_mutex_init)(mbedtls_threading_mutex_t *mutex)
struct mbedtls_threading_mutex_t mbedtls_threading_mutex_t
void(* mbedtls_mutex_free)(mbedtls_threading_mutex_t *mutex)
mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex
mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex
int(* mbedtls_mutex_unlock)(mbedtls_threading_mutex_t *mutex)
int(* mbedtls_mutex_lock)(mbedtls_threading_mutex_t *mutex)