Skip to content

Commit 12fdb3a

Browse files
authored
Properly use critical section
The critical section was not actually protecting the variable as it is read, but could change prior to the critical section start. With this change, the variable is read and reset inside the critical section in order to make this atomic and not miss any events.
1 parent 5466e49 commit 12fdb3a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/mac/LoRaMac.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,13 +1351,15 @@ static void ProcessRadioRxTimeout( void )
13511351

13521352
static void LoRaMacHandleIrqEvents( void )
13531353
{
1354-
LoRaMacRadioEvents_t events = LoRaMacRadioEvents;
1354+
LoRaMacRadioEvents_t events;
1355+
1356+
CRITICAL_SECTION_BEGIN( );
1357+
events = LoRaMacRadioEvents;
1358+
LoRaMacRadioEvents.Value = 0;
1359+
CRITICAL_SECTION_END( );
1360+
13551361
if( events.Value != 0 )
13561362
{
1357-
CRITICAL_SECTION_BEGIN( );
1358-
LoRaMacRadioEvents.Value = 0;
1359-
CRITICAL_SECTION_END( );
1360-
13611363
if( events.Events.TxDone == 1 )
13621364
{
13631365
ProcessRadioTxDone( );

0 commit comments

Comments
 (0)