Skip to content

Commit

Permalink
Add mutex lock/unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
vshymanskyy committed Dec 27, 2023
1 parent a0350c6 commit da6a963
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 42 deletions.
15 changes: 13 additions & 2 deletions src/BlynkRpcConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#endif

#if defined(RPC_INPUT_BUFFER)
// Use the specified value
/* OK, use the specified value */
#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__)
#define RPC_INPUT_BUFFER 256
#elif defined(LINUX) || defined(ESP32)
Expand All @@ -16,12 +16,23 @@
#endif

#if defined(RPC_ENABLE_SMALL_CRC8)
// Use the specified value
/* OK, use the specified value */
#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__)
#define RPC_ENABLE_SMALL_CRC8 1
#else
#define RPC_ENABLE_SMALL_CRC8 0
#endif

/*
* Define global RPC mutex operations, if needed.
* The mutex should be reentrant/recursive.
*/
#if !defined(RPC_MUTEX_LOCK)
#define RPC_MUTEX_LOCK()
#endif
#if !defined(RPC_MUTEX_UNLOCK)
#define RPC_MUTEX_UNLOCK()
#endif

#endif /* BLYNK_RPC_CONFIG_H */

2 changes: 2 additions & 0 deletions src/BlynkRpcInfra.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ RpcStatus rpc_wait_result(uint16_t expected_seq, MessageBuffer* buff, uint32_t t
}

void rpc_run(void) {
RPC_MUTEX_LOCK();
MessageBuffer buff;
MessageBuffer_init(&buff, NULL, 0);
while (rpc_recv_msg(&buff, 0)) {
_rpc_last_rx_time = rpc_system_millis();
rpc_handle_msg(&buff);
}
RPC_MUTEX_UNLOCK();
}
Loading

0 comments on commit da6a963

Please sign in to comment.