mbed TLS library

Dependents:   HTTPClient-SSL WS_SERVER

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  *  Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
00007  *
00008  *  This file is part of mbed TLS (https://tls.mbed.org)
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License along
00021  *  with this program; if not, write to the Free Software Foundation, Inc.,
00022  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00023  */
00024 #ifndef POLARSSL_THREADING_H
00025 #define POLARSSL_THREADING_H
00026 
00027 #if !defined(POLARSSL_CONFIG_FILE)
00028 #include "config.h"
00029 #else
00030 #include POLARSSL_CONFIG_FILE
00031 #endif
00032 
00033 #include <stdlib.h>
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038 
00039 #define POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE         -0x001A  /**< The selected feature is not available. */
00040 #define POLARSSL_ERR_THREADING_BAD_INPUT_DATA              -0x001C  /**< Bad input parameters to function. */
00041 #define POLARSSL_ERR_THREADING_MUTEX_ERROR                 -0x001E  /**< Locking / unlocking / free failed with error code. */
00042 
00043 #if defined(POLARSSL_THREADING_PTHREAD)
00044 #include <pthread.h>
00045 typedef pthread_mutex_t threading_mutex_t;
00046 #endif
00047 
00048 #if defined(POLARSSL_THREADING_ALT)
00049 /* You should define the threading_mutex_t type in your header */
00050 #include "threading_alt.h"
00051 
00052 /**
00053  * \brief           Set your alternate threading implementation function
00054  *                  pointers
00055  *
00056  * \param mutex_init    the init function implementation
00057  * \param mutex_free    the free function implementation
00058  * \param mutex_lock    the lock function implementation
00059  * \param mutex_unlock  the unlock function implementation
00060  *
00061  * \return              0 if successful
00062  */
00063 int threading_set_alt( int (*mutex_init)( threading_mutex_t * ),
00064                        int (*mutex_free)( threading_mutex_t * ),
00065                        int (*mutex_lock)( threading_mutex_t * ),
00066                        int (*mutex_unlock)( threading_mutex_t * ) );
00067 #endif /* POLARSSL_THREADING_ALT_C */
00068 
00069 /*
00070  * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
00071  *
00072  * All these functions are expected to work or the result will be undefined.
00073  */
00074 extern int (*polarssl_mutex_init)( threading_mutex_t *mutex );
00075 extern int (*polarssl_mutex_free)( threading_mutex_t *mutex );
00076 extern int (*polarssl_mutex_lock)( threading_mutex_t *mutex );
00077 extern int (*polarssl_mutex_unlock)( threading_mutex_t *mutex );
00078 
00079 #ifdef __cplusplus
00080 }
00081 #endif
00082 
00083 #endif /* threading.h */
00084