mirror of https://github.com/ARMmbed/mbed-os.git
Address concurrency and style issues
1. Use atomic operations to increase and decrease counter. 2. Style fixes. Remove unused function declaration.pull/7099/head
parent
479438953f
commit
1f5cee967d
|
@ -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.
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue