Verified Commit 9254e295 authored by Vincent Coubard's avatar Vincent Coubard
Browse files

Socket: Use atomic operations instead of mutex



Signed-off-by: Vincent Coubard's avatarVincent Coubard <vincent.coubard@arm.com>
parent c6e5161f
......@@ -41,6 +41,8 @@
#include <string.h>
#include <stdbool.h>
#include "bootstrap/mbed_atomic.h"
/*-----------------------------------------------------------*/
#define SS_STATUS_CONNECTED ( 1 )
......@@ -85,7 +87,6 @@ typedef struct _ss_ctx_t
char ** ppcAlpnProtocols;
uint32_t ulAlpnProtocolsCount;
uint32_t ulRefcount;
osMutexId_t RefcountLock;
} ss_ctx_t;
/*-----------------------------------------------------------*/
......@@ -152,11 +153,6 @@ static void prvSocketsClose( ss_ctx_t * ctx )
vPortFree( ctx->destination );
}
if ( ctx->RefcountLock )
{
osMutexDelete( ctx->RefcountLock );
}
vPortFree( ctx );
}
......@@ -166,15 +162,9 @@ static void prvSocketsClose( ss_ctx_t * ctx )
*/
static void prvDecrementRefCount( ss_ctx_t * ctx )
{
osMutexAcquire( ctx->RefcountLock, osWaitForever );
ctx->ulRefcount -= 1;
if( ctx->ulRefcount == 0 )
{
if ( core_util_atomic_decr_u32( &ctx->ulRefcount, 1 ) ) {
prvSocketsClose( ctx );
// do not release lock as it's been removed
return;
}
osMutexRelease( ctx->RefcountLock );
}
/*
......@@ -182,9 +172,7 @@ static void prvDecrementRefCount( ss_ctx_t * ctx )
*/
static void prvIncrementRefCount( ss_ctx_t * ctx )
{
osMutexAcquire( ctx->RefcountLock, osWaitForever );
ctx->ulRefcount += 1;
osMutexRelease( ctx->RefcountLock );
core_util_atomic_incr_u32( &ctx->ulRefcount, 1 );
}
/*
......@@ -364,7 +352,6 @@ Socket_t SOCKETS_Socket( int32_t lDomain,
if( ctx )
{
ctx->RefcountLock = osMutexNew( NULL );
memset( ctx, 0, sizeof( *ctx ) );
ctx->ip_socket = iotSocketCreate( IOT_SOCKET_AF_INET, IOT_SOCKET_SOCK_STREAM, IOT_SOCKET_IPPROTO_TCP );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment