Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers threading.h Source File

threading.h

Go to the documentation of this file.
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 "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 #define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE         -0x001A  /**< The selected feature is not available. */
00040 #define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA              -0x001C  /**< Bad input parameters to function. */
00041 #define MBEDTLS_ERR_THREADING_MUTEX_ERROR                 -0x001E  /**< Locking / unlocking / free failed with error code. */
00042 
00043 #if defined(MBEDTLS_THREADING_PTHREAD)
00044 #include <pthread.h>
00045 typedef struct
00046 {
00047     pthread_mutex_t mutex;
00048     char is_valid;
00049 } mbedtls_threading_mutex_t;
00050 #endif
00051 
00052 #if defined(MBEDTLS_THREADING_ALT)
00053 /* You should define the mbedtls_threading_mutex_t type in your header */
00054 #include "threading_alt.h"
00055 
00056 /**
00057  * \brief           Set your alternate threading implementation function
00058  *                  pointers and initialize global mutexes. If used, this
00059  *                  function must be called once in the main thread before any
00060  *                  other mbed TLS function is called, and
00061  *                  mbedtls_threading_free_alt() must be called once in the main
00062  *                  thread after all other mbed TLS functions.
00063  *
00064  * \note            mutex_init() and mutex_free() don't return a status code.
00065  *                  If mutex_init() fails, it should leave its argument (the
00066  *                  mutex) in a state such that mutex_lock() will fail when
00067  *                  called with this argument.
00068  *
00069  * \param mutex_init    the init function implementation
00070  * \param mutex_free    the free function implementation
00071  * \param mutex_lock    the lock function implementation
00072  * \param mutex_unlock  the unlock function implementation
00073  */
00074 void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ),
00075                        void (*mutex_free)( mbedtls_threading_mutex_t * ),
00076                        int (*mutex_lock)( mbedtls_threading_mutex_t * ),
00077                        int (*mutex_unlock)( mbedtls_threading_mutex_t * ) );
00078 
00079 /**
00080  * \brief               Free global mutexes.
00081  */
00082 void mbedtls_threading_free_alt( void );
00083 #endif /* MBEDTLS_THREADING_ALT */
00084 
00085 #if defined(MBEDTLS_THREADING_C)
00086 /*
00087  * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
00088  *
00089  * All these functions are expected to work or the result will be undefined.
00090  */
00091 extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex );
00092 extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex );
00093 extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex );
00094 extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex );
00095 
00096 /*
00097  * Global mutexes
00098  */
00099 extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex;
00100 extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex;
00101 #endif /* MBEDTLS_THREADING_C */
00102 
00103 #ifdef __cplusplus
00104 }
00105 #endif
00106 
00107 #endif /* threading.h */