mbed TLS v2.16.9
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 * This file is provided under the Apache License 2.0, or the
11 * GNU General Public License v2.0 or later.
12 *
13 * **********
14 * Apache License 2.0:
15 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 *
28 * **********
29 *
30 * **********
31 * GNU General Public License v2.0 or later:
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License along
44 * with this program; if not, write to the Free Software Foundation, Inc.,
45 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46 *
47 * **********
48 */
49#ifndef MBEDTLS_THREADING_H
50#define MBEDTLS_THREADING_H
51
52#if !defined(MBEDTLS_CONFIG_FILE)
53#include "config.h"
54#else
55#include MBEDTLS_CONFIG_FILE
56#endif
57
58#include <stdlib.h>
59
60#ifdef __cplusplus
61extern "C" {
62#endif
63
64/* MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE is deprecated and should not be
65 * used. */
66#define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A
68#define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C
69#define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E
71#if defined(MBEDTLS_THREADING_PTHREAD)
72#include <pthread.h>
74{
75 pthread_mutex_t mutex;
78#endif
79
80#if defined(MBEDTLS_THREADING_ALT)
81/* You should define the mbedtls_threading_mutex_t type in your header */
82#include "threading_alt.h"
83
102void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ),
103 void (*mutex_free)( mbedtls_threading_mutex_t * ),
104 int (*mutex_lock)( mbedtls_threading_mutex_t * ),
105 int (*mutex_unlock)( mbedtls_threading_mutex_t * ) );
106
110void mbedtls_threading_free_alt( void );
111#endif /* MBEDTLS_THREADING_ALT */
112
113#if defined(MBEDTLS_THREADING_C)
114/*
115 * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
116 *
117 * All these functions are expected to work or the result will be undefined.
118 */
119extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex );
120extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex );
121extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex );
122extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex );
123
124/*
125 * Global mutexes
126 */
127#if defined(MBEDTLS_FS_IO)
129#endif
130
131#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT)
132/* This mutex may or may not be used in the default definition of
133 * mbedtls_platform_gmtime_r(), but in order to determine that,
134 * we need to check POSIX features, hence modify _POSIX_C_SOURCE.
135 * With the current approach, this declaration is orphaned, lacking
136 * an accompanying definition, in case mbedtls_platform_gmtime_r()
137 * doesn't need it, but that's not a problem. */
139#endif /* MBEDTLS_HAVE_TIME_DATE && !MBEDTLS_PLATFORM_GMTIME_R_ALT */
140
141#endif /* MBEDTLS_THREADING_C */
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif /* threading.h */
Configuration options (set of defines)
pthread_mutex_t mutex
Definition threading.h:75
void(* mbedtls_mutex_init)(mbedtls_threading_mutex_t *mutex)
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)