Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
IoT
Open IoT SDK
examples
total-solutions
Commits
9254e295
Verified
Commit
9254e295
authored
May 23, 2022
by
Vincent Coubard
Browse files
Socket: Use atomic operations instead of mutex
Signed-off-by:
Vincent Coubard
<
vincent.coubard@arm.com
>
parent
c6e5161f
Changes
1
Hide whitespace changes
Inline
Side-by-side
bsp/aws_libraries/abstractions/secure_sockets/lwip/iot_secure_sockets.c
View file @
9254e295
...
...
@@ -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
;
/*-----------------------------------------------------------*/
...
...
@@ -151,11 +152,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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment