mbed TLS library
Dependents: HTTPClient-SSL WS_SERVER
threading.c
00001 /* 00002 * Threading abstraction layer 00003 * 00004 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved 00005 * 00006 * This file is part of mbed TLS (https://tls.mbed.org) 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License along 00019 * with this program; if not, write to the Free Software Foundation, Inc., 00020 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00021 */ 00022 00023 #if !defined(POLARSSL_CONFIG_FILE) 00024 #include "polarssl/config.h" 00025 #else 00026 #include POLARSSL_CONFIG_FILE 00027 #endif 00028 00029 #if defined(POLARSSL_THREADING_C) 00030 00031 #include "polarssl/threading.h" 00032 00033 #if defined(POLARSSL_THREADING_PTHREAD) 00034 static int threading_mutex_init_pthread( threading_mutex_t *mutex ) 00035 { 00036 if( mutex == NULL ) 00037 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00038 00039 if( pthread_mutex_init( mutex, NULL ) != 0 ) 00040 return( POLARSSL_ERR_THREADING_MUTEX_ERROR ); 00041 00042 return( 0 ); 00043 } 00044 00045 static int threading_mutex_free_pthread( threading_mutex_t *mutex ) 00046 { 00047 if( mutex == NULL ) 00048 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00049 00050 if( pthread_mutex_destroy( mutex ) != 0 ) 00051 return( POLARSSL_ERR_THREADING_MUTEX_ERROR ); 00052 00053 return( 0 ); 00054 } 00055 00056 static int threading_mutex_lock_pthread( threading_mutex_t *mutex ) 00057 { 00058 if( mutex == NULL ) 00059 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00060 00061 if( pthread_mutex_lock( mutex ) != 0 ) 00062 return( POLARSSL_ERR_THREADING_MUTEX_ERROR ); 00063 00064 return( 0 ); 00065 } 00066 00067 static int threading_mutex_unlock_pthread( threading_mutex_t *mutex ) 00068 { 00069 if( mutex == NULL ) 00070 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00071 00072 if( pthread_mutex_unlock( mutex ) != 0 ) 00073 return( POLARSSL_ERR_THREADING_MUTEX_ERROR ); 00074 00075 return( 0 ); 00076 } 00077 00078 int (*polarssl_mutex_init)( threading_mutex_t * ) = threading_mutex_init_pthread; 00079 int (*polarssl_mutex_free)( threading_mutex_t * ) = threading_mutex_free_pthread; 00080 int (*polarssl_mutex_lock)( threading_mutex_t * ) = threading_mutex_lock_pthread; 00081 int (*polarssl_mutex_unlock)( threading_mutex_t * ) = threading_mutex_unlock_pthread; 00082 #endif /* POLARSSL_THREADING_PTHREAD */ 00083 00084 #if defined(POLARSSL_THREADING_ALT) 00085 static int threading_mutex_fail( threading_mutex_t *mutex ) 00086 { 00087 ((void) mutex ); 00088 return( POLARSSL_ERR_THREADING_BAD_INPUT_DATA ); 00089 } 00090 00091 int (*polarssl_mutex_init)( threading_mutex_t * ) = threading_mutex_fail; 00092 int (*polarssl_mutex_free)( threading_mutex_t * ) = threading_mutex_fail; 00093 int (*polarssl_mutex_lock)( threading_mutex_t * ) = threading_mutex_fail; 00094 int (*polarssl_mutex_unlock)( threading_mutex_t * ) = threading_mutex_fail; 00095 00096 int threading_set_alt( int (*mutex_init)( threading_mutex_t * ), 00097 int (*mutex_free)( threading_mutex_t * ), 00098 int (*mutex_lock)( threading_mutex_t * ), 00099 int (*mutex_unlock)( threading_mutex_t * ) ) 00100 { 00101 polarssl_mutex_init = mutex_init; 00102 polarssl_mutex_free = mutex_free; 00103 polarssl_mutex_lock = mutex_lock; 00104 polarssl_mutex_unlock = mutex_unlock; 00105 00106 return( 0 ); 00107 } 00108 #endif /* POLARSSL_THREADING_ALT_C */ 00109 00110 #endif /* POLARSSL_THREADING_C */ 00111
Generated on Tue Jul 12 2022 13:50:38 by 1.7.2