mbed TLS Build

Dependents:   Slave-prot-prod

Committer:
williequesada
Date:
Tue Jun 04 16:03:38 2019 +0000
Revision:
1:1a219dea6cb5
Parent:
0:cdf462088d13
compartir a Pablo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
markrad 0:cdf462088d13 1 /**
markrad 0:cdf462088d13 2 * \file threading.h
markrad 0:cdf462088d13 3 *
markrad 0:cdf462088d13 4 * \brief Threading abstraction layer
markrad 0:cdf462088d13 5 *
markrad 0:cdf462088d13 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
markrad 0:cdf462088d13 7 * SPDX-License-Identifier: Apache-2.0
markrad 0:cdf462088d13 8 *
markrad 0:cdf462088d13 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
markrad 0:cdf462088d13 10 * not use this file except in compliance with the License.
markrad 0:cdf462088d13 11 * You may obtain a copy of the License at
markrad 0:cdf462088d13 12 *
markrad 0:cdf462088d13 13 * http://www.apache.org/licenses/LICENSE-2.0
markrad 0:cdf462088d13 14 *
markrad 0:cdf462088d13 15 * Unless required by applicable law or agreed to in writing, software
markrad 0:cdf462088d13 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
markrad 0:cdf462088d13 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
markrad 0:cdf462088d13 18 * See the License for the specific language governing permissions and
markrad 0:cdf462088d13 19 * limitations under the License.
markrad 0:cdf462088d13 20 *
markrad 0:cdf462088d13 21 * This file is part of mbed TLS (https://tls.mbed.org)
markrad 0:cdf462088d13 22 */
markrad 0:cdf462088d13 23 #ifndef MBEDTLS_THREADING_H
markrad 0:cdf462088d13 24 #define MBEDTLS_THREADING_H
markrad 0:cdf462088d13 25
markrad 0:cdf462088d13 26 #if !defined(MBEDTLS_CONFIG_FILE)
markrad 0:cdf462088d13 27 #include "config.h"
markrad 0:cdf462088d13 28 #else
markrad 0:cdf462088d13 29 #include MBEDTLS_CONFIG_FILE
markrad 0:cdf462088d13 30 #endif
markrad 0:cdf462088d13 31
markrad 0:cdf462088d13 32 #include <stdlib.h>
markrad 0:cdf462088d13 33
markrad 0:cdf462088d13 34 #ifdef __cplusplus
markrad 0:cdf462088d13 35 extern "C" {
markrad 0:cdf462088d13 36 #endif
markrad 0:cdf462088d13 37
markrad 0:cdf462088d13 38 #define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A /**< The selected feature is not available. */
markrad 0:cdf462088d13 39 #define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C /**< Bad input parameters to function. */
markrad 0:cdf462088d13 40 #define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E /**< Locking / unlocking / free failed with error code. */
markrad 0:cdf462088d13 41
markrad 0:cdf462088d13 42 #if defined(MBEDTLS_THREADING_PTHREAD)
markrad 0:cdf462088d13 43 #include <pthread.h>
markrad 0:cdf462088d13 44 typedef struct
markrad 0:cdf462088d13 45 {
markrad 0:cdf462088d13 46 pthread_mutex_t mutex;
markrad 0:cdf462088d13 47 char is_valid;
markrad 0:cdf462088d13 48 } mbedtls_threading_mutex_t;
markrad 0:cdf462088d13 49 #endif
markrad 0:cdf462088d13 50
markrad 0:cdf462088d13 51 #if defined(MBEDTLS_THREADING_ALT)
markrad 0:cdf462088d13 52 /* You should define the mbedtls_threading_mutex_t type in your header */
markrad 0:cdf462088d13 53 #include "threading_alt.h"
markrad 0:cdf462088d13 54
markrad 0:cdf462088d13 55 /**
markrad 0:cdf462088d13 56 * \brief Set your alternate threading implementation function
markrad 0:cdf462088d13 57 * pointers and initialize global mutexes. If used, this
markrad 0:cdf462088d13 58 * function must be called once in the main thread before any
markrad 0:cdf462088d13 59 * other mbed TLS function is called, and
markrad 0:cdf462088d13 60 * mbedtls_threading_free_alt() must be called once in the main
markrad 0:cdf462088d13 61 * thread after all other mbed TLS functions.
markrad 0:cdf462088d13 62 *
markrad 0:cdf462088d13 63 * \note mutex_init() and mutex_free() don't return a status code.
markrad 0:cdf462088d13 64 * If mutex_init() fails, it should leave its argument (the
markrad 0:cdf462088d13 65 * mutex) in a state such that mutex_lock() will fail when
markrad 0:cdf462088d13 66 * called with this argument.
markrad 0:cdf462088d13 67 *
markrad 0:cdf462088d13 68 * \param mutex_init the init function implementation
markrad 0:cdf462088d13 69 * \param mutex_free the free function implementation
markrad 0:cdf462088d13 70 * \param mutex_lock the lock function implementation
markrad 0:cdf462088d13 71 * \param mutex_unlock the unlock function implementation
markrad 0:cdf462088d13 72 */
markrad 0:cdf462088d13 73 void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ),
markrad 0:cdf462088d13 74 void (*mutex_free)( mbedtls_threading_mutex_t * ),
markrad 0:cdf462088d13 75 int (*mutex_lock)( mbedtls_threading_mutex_t * ),
markrad 0:cdf462088d13 76 int (*mutex_unlock)( mbedtls_threading_mutex_t * ) );
markrad 0:cdf462088d13 77
markrad 0:cdf462088d13 78 /**
markrad 0:cdf462088d13 79 * \brief Free global mutexes.
markrad 0:cdf462088d13 80 */
markrad 0:cdf462088d13 81 void mbedtls_threading_free_alt( void );
markrad 0:cdf462088d13 82 #endif /* MBEDTLS_THREADING_ALT */
markrad 0:cdf462088d13 83
markrad 0:cdf462088d13 84 #if defined(MBEDTLS_THREADING_C)
markrad 0:cdf462088d13 85 /*
markrad 0:cdf462088d13 86 * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
markrad 0:cdf462088d13 87 *
markrad 0:cdf462088d13 88 * All these functions are expected to work or the result will be undefined.
markrad 0:cdf462088d13 89 */
markrad 0:cdf462088d13 90 extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex );
markrad 0:cdf462088d13 91 extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex );
markrad 0:cdf462088d13 92 extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex );
markrad 0:cdf462088d13 93 extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex );
markrad 0:cdf462088d13 94
markrad 0:cdf462088d13 95 /*
markrad 0:cdf462088d13 96 * Global mutexes
markrad 0:cdf462088d13 97 */
markrad 0:cdf462088d13 98 extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex;
markrad 0:cdf462088d13 99 extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex;
markrad 0:cdf462088d13 100 #endif /* MBEDTLS_THREADING_C */
markrad 0:cdf462088d13 101
markrad 0:cdf462088d13 102 #ifdef __cplusplus
markrad 0:cdf462088d13 103 }
markrad 0:cdf462088d13 104 #endif
markrad 0:cdf462088d13 105
markrad 0:cdf462088d13 106 #endif /* threading.h */