Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
threading.h
00001 /** 00002 * \file threading.h 00003 * 00004 * \brief Threading abstraction layer 00005 */ 00006 /* 00007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 00008 * SPDX-License-Identifier: Apache-2.0 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00011 * not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00018 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 * 00022 * This file is part of mbed TLS (https://tls.mbed.org) 00023 */ 00024 #ifndef MBEDTLS_THREADING_H 00025 #define MBEDTLS_THREADING_H 00026 00027 #if !defined(MBEDTLS_CONFIG_FILE) 00028 #include "mbedtls/config.h" 00029 #else 00030 #include MBEDTLS_CONFIG_FILE 00031 #endif 00032 00033 #include <stdlib.h> 00034 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif 00038 00039 /* MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE is deprecated and should not be 00040 * used. */ 00041 #define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */ 00042 00043 #define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */ 00044 #define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */ 00045 00046 #if defined(MBEDTLS_THREADING_PTHREAD) 00047 #include <pthread.h> 00048 typedef struct mbedtls_threading_mutex_t 00049 { 00050 pthread_mutex_t mutex; 00051 char is_valid; 00052 } mbedtls_threading_mutex_t; 00053 #endif 00054 00055 #if defined(MBEDTLS_THREADING_ALT) 00056 /* You should define the mbedtls_threading_mutex_t type in your header */ 00057 #include "threading_alt.h" 00058 00059 /** 00060 * \brief Set your alternate threading implementation function 00061 * pointers and initialize global mutexes. If used, this 00062 * function must be called once in the main thread before any 00063 * other mbed TLS function is called, and 00064 * mbedtls_threading_free_alt() must be called once in the main 00065 * thread after all other mbed TLS functions. 00066 * 00067 * \note mutex_init() and mutex_free() don't return a status code. 00068 * If mutex_init() fails, it should leave its argument (the 00069 * mutex) in a state such that mutex_lock() will fail when 00070 * called with this argument. 00071 * 00072 * \param mutex_init the init function implementation 00073 * \param mutex_free the free function implementation 00074 * \param mutex_lock the lock function implementation 00075 * \param mutex_unlock the unlock function implementation 00076 */ 00077 void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ), 00078 void (*mutex_free)( mbedtls_threading_mutex_t * ), 00079 int (*mutex_lock)( mbedtls_threading_mutex_t * ), 00080 int (*mutex_unlock)( mbedtls_threading_mutex_t * ) ); 00081 00082 /** 00083 * \brief Free global mutexes. 00084 */ 00085 void mbedtls_threading_free_alt( void ); 00086 #endif /* MBEDTLS_THREADING_ALT */ 00087 00088 #if defined(MBEDTLS_THREADING_C) 00089 /* 00090 * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock 00091 * 00092 * All these functions are expected to work or the result will be undefined. 00093 */ 00094 extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex ); 00095 extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex ); 00096 extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex ); 00097 extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex ); 00098 00099 /* 00100 * Global mutexes 00101 */ 00102 #if defined(MBEDTLS_FS_IO) 00103 extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex; 00104 #endif 00105 00106 #if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT) 00107 /* This mutex may or may not be used in the default definition of 00108 * mbedtls_platform_gmtime_r(), but in order to determine that, 00109 * we need to check POSIX features, hence modify _POSIX_C_SOURCE. 00110 * With the current approach, this declaration is orphaned, lacking 00111 * an accompanying definition, in case mbedtls_platform_gmtime_r() 00112 * doesn't need it, but that's not a problem. */ 00113 extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex; 00114 #endif /* MBEDTLS_HAVE_TIME_DATE && !MBEDTLS_PLATFORM_GMTIME_R_ALT */ 00115 00116 #endif /* MBEDTLS_THREADING_C */ 00117 00118 #ifdef __cplusplus 00119 } 00120 #endif 00121 00122 #endif /* threading.h */
Generated on Tue Jul 12 2022 13:55:00 by
