mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-29 16:03:14 +03:00
- Split most of the EspnowMeshBackend code into utility files and the new ConditionalPrinter, EspnowDatabase, EspnowConnectionManager, EspnowTransmitter and EspnowEncryptionBroker classes.
- Improve mutex handling. - Move verifyEncryptionRequestHmac function from JsonTranslator to EspnowEncryptionBroker. - Remove UtilityMethods.cpp.
This commit is contained in:
@ -26,12 +26,7 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
static std::shared_ptr<bool> _captureBan = std::make_shared<bool>(false);
|
||||
}
|
||||
|
||||
std::shared_ptr<bool> MutexTracker::captureBan()
|
||||
{
|
||||
return _captureBan;
|
||||
std::shared_ptr<bool> _captureBan = std::make_shared<bool>(false);
|
||||
}
|
||||
|
||||
MutexTracker::MutexTracker(const std::shared_ptr<bool> &mutexToCapture)
|
||||
@ -50,6 +45,14 @@ MutexTracker::~MutexTracker()
|
||||
_destructorHook();
|
||||
}
|
||||
|
||||
MutexTracker MutexTracker::captureBan()
|
||||
{
|
||||
// Syntax like this will move the resulting value into its new position (similar to NRVO): https://stackoverflow.com/a/11540204
|
||||
return MutexTracker(_captureBan);
|
||||
}
|
||||
|
||||
MutexTracker MutexTracker::captureBan(const std::function<void()> destructorHook) { return MutexTracker(_captureBan, destructorHook); }
|
||||
|
||||
bool MutexTracker::mutexFree(const std::shared_ptr<bool> &mutex)
|
||||
{
|
||||
if(mutex != nullptr && !(*mutex))
|
||||
@ -82,7 +85,7 @@ void MutexTracker::releaseMutex()
|
||||
|
||||
bool MutexTracker::attemptMutexCapture(const std::shared_ptr<bool> &mutexToCapture)
|
||||
{
|
||||
if(mutexFree(captureBan()) && mutexFree(mutexToCapture))
|
||||
if(mutexFree(_captureBan) && mutexFree(mutexToCapture))
|
||||
{
|
||||
_capturedMutex = mutexToCapture;
|
||||
*_capturedMutex = true;
|
||||
|
Reference in New Issue
Block a user