Address concurrency and style issues

1. Use atomic operations to increase and decrease counter.
2. Style fixes.
Remove unused function declaration.
pull/7099/head
Ron Eldor 2018-08-30 11:18:23 +03:00
parent 479438953f
commit 1f5cee967d
2 changed files with 7 additions and 7 deletions

View File

@ -36,7 +36,6 @@ typedef struct {
mbedtls_platform_context; mbedtls_platform_context;
void mbedtls_platform_init( mbedtls_platform_context* ctx);
/** /**
* \brief This function performs any platform initialization operations, * \brief This function performs any platform initialization operations,
* needed for setting up cryptographic modules. * needed for setting up cryptographic modules.

View File

@ -20,17 +20,19 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT) #if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
mbedtls_platform_context ctx = {0}; #include "mbed_critical.h"
mbedtls_platform_context ctx = { };
int mbedtls_platform_setup( mbedtls_platform_context *obsolete_ctx ) int mbedtls_platform_setup( mbedtls_platform_context *obsolete_ctx )
{ {
int ret = 0; int ret = 0;
ctx.reference_count++; core_util_atomic_incr_u32( ( volatile uint32_t * )&ctx.reference_count, 1 );
if( ctx.reference_count == 1 ) if( ctx.reference_count == 1 )
{ {
/* call platform specific code to setup crypto driver*/ /* call platform specific code to setup crypto driver */
ret = crypto_platform_setup( &ctx.platform_impl_ctx ); ret = crypto_platform_setup( &ctx.platform_impl_ctx );
} }
return ( ret ); return ( ret );
@ -39,11 +41,10 @@ int mbedtls_platform_setup( mbedtls_platform_context *obsolete_ctx )
void mbedtls_platform_teardown( mbedtls_platform_context *obsolete_ctx ) void mbedtls_platform_teardown( mbedtls_platform_context *obsolete_ctx )
{ {
ctx.reference_count--; core_util_atomic_decr_u32( ( volatile uint32_t * )&ctx.reference_count, 1 );
if( ctx.reference_count <= 0 ) if( ctx.reference_count <= 0 )
{ {
/* call platform specific code to terminate crypto driver*/ /* call platform specific code to terminate crypto driver */
crypto_platform_terminate( &ctx.platform_impl_ctx ); crypto_platform_terminate( &ctx.platform_impl_ctx );
ctx.reference_count = 0; ctx.reference_count = 0;
} }