| Paul Bakker | 2466d93 | 2013-09-28 14:40:38 +0200 | [diff] [blame] | 1 | /** | 
|  | 2 | * \file threading.h | 
|  | 3 | * | 
|  | 4 | * \brief Threading abstraction layer | 
|  | 5 | * | 
|  | 6 | *  Copyright (C) 2006-2013, Brainspark B.V. | 
|  | 7 | * | 
|  | 8 | *  This file is part of PolarSSL (http://www.polarssl.org) | 
|  | 9 | *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> | 
|  | 10 | * | 
|  | 11 | *  All rights reserved. | 
|  | 12 | * | 
|  | 13 | *  This program is free software; you can redistribute it and/or modify | 
|  | 14 | *  it under the terms of the GNU General Public License as published by | 
|  | 15 | *  the Free Software Foundation; either version 2 of the License, or | 
|  | 16 | *  (at your option) any later version. | 
|  | 17 | * | 
|  | 18 | *  This program is distributed in the hope that it will be useful, | 
|  | 19 | *  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 20 | *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 21 | *  GNU General Public License for more details. | 
|  | 22 | * | 
|  | 23 | *  You should have received a copy of the GNU General Public License along | 
|  | 24 | *  with this program; if not, write to the Free Software Foundation, Inc., | 
|  | 25 | *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 
|  | 26 | */ | 
|  | 27 | #ifndef POLARSSL_THREADING_H | 
|  | 28 | #define POLARSSL_THREADING_H | 
|  | 29 |  | 
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 30 | #if !defined(POLARSSL_CONFIG_FILE) | 
| Paul Bakker | 2466d93 | 2013-09-28 14:40:38 +0200 | [diff] [blame] | 31 | #include "config.h" | 
| Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 32 | #else | 
|  | 33 | #include POLARSSL_CONFIG_FILE | 
|  | 34 | #endif | 
| Paul Bakker | 2466d93 | 2013-09-28 14:40:38 +0200 | [diff] [blame] | 35 |  | 
|  | 36 | #include <stdlib.h> | 
|  | 37 |  | 
|  | 38 | #ifdef __cplusplus | 
|  | 39 | extern "C" { | 
|  | 40 | #endif | 
|  | 41 |  | 
|  | 42 | #define POLARSSL_ERR_THREADING_FEATURE_UNAVAILABLE         -0x001A  /**< The selected feature is not available. */ | 
|  | 43 | #define POLARSSL_ERR_THREADING_BAD_INPUT_DATA              -0x001C  /**< Bad input parameters to function. */ | 
|  | 44 | #define POLARSSL_ERR_THREADING_MUTEX_ERROR                 -0x001E  /**< Locking / unlocking / free failed with error code. */ | 
|  | 45 |  | 
| Paul Bakker | 2466d93 | 2013-09-28 14:40:38 +0200 | [diff] [blame] | 46 | #if defined(POLARSSL_THREADING_PTHREAD) | 
|  | 47 | #include <pthread.h> | 
|  | 48 | typedef pthread_mutex_t threading_mutex_t; | 
|  | 49 | #endif | 
|  | 50 |  | 
|  | 51 | #if defined(POLARSSL_THREADING_ALT) | 
|  | 52 | /* You should define the threading_mutex_t type in your header */ | 
|  | 53 | #include "threading_alt.h" | 
|  | 54 |  | 
|  | 55 | /** | 
|  | 56 | * \brief           Set your alternate threading implementation function | 
|  | 57 | *                  pointers | 
|  | 58 | * | 
| Paul Bakker | 6838bd1 | 2013-09-30 13:56:38 +0200 | [diff] [blame] | 59 | * \param mutex_init    the init function implementation | 
| Paul Bakker | 2466d93 | 2013-09-28 14:40:38 +0200 | [diff] [blame] | 60 | * \param mutex_free    the free function implementation | 
|  | 61 | * \param mutex_lock    the lock function implementation | 
|  | 62 | * \param mutex_unlock  the unlock function implementation | 
|  | 63 | * | 
|  | 64 | * \return              0 if successful | 
|  | 65 | */ | 
|  | 66 | int threading_set_alt( int (*mutex_init)( threading_mutex_t * ), | 
|  | 67 | int (*mutex_free)( threading_mutex_t * ), | 
|  | 68 | int (*mutex_lock)( threading_mutex_t * ), | 
|  | 69 | int (*mutex_unlock)( threading_mutex_t * ) ); | 
|  | 70 | #endif /* POLARSSL_THREADING_ALT_C */ | 
|  | 71 |  | 
|  | 72 | /* | 
|  | 73 | * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock | 
| Paul Bakker | 6838bd1 | 2013-09-30 13:56:38 +0200 | [diff] [blame] | 74 | * | 
|  | 75 | * All these functions are expected to work or the result will be undefined. | 
| Paul Bakker | 2466d93 | 2013-09-28 14:40:38 +0200 | [diff] [blame] | 76 | */ | 
|  | 77 | extern int (*polarssl_mutex_init)( threading_mutex_t *mutex ); | 
|  | 78 | extern int (*polarssl_mutex_free)( threading_mutex_t *mutex ); | 
|  | 79 | extern int (*polarssl_mutex_lock)( threading_mutex_t *mutex ); | 
|  | 80 | extern int (*polarssl_mutex_unlock)( threading_mutex_t *mutex ); | 
|  | 81 |  | 
|  | 82 | #ifdef __cplusplus | 
|  | 83 | } | 
|  | 84 | #endif | 
|  | 85 |  | 
|  | 86 | #endif /* threading.h */ |