From 49da48dc0dc45025ea7fb7cdff21539c5e6d91bd Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Wed, 12 May 2021 17:40:14 +0200 Subject: [PATCH] fixed mutex bug --- linux/spi/SpiComIF.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/linux/spi/SpiComIF.cpp b/linux/spi/SpiComIF.cpp index 2724ac4..3dc4b84 100644 --- a/linux/spi/SpiComIF.cpp +++ b/linux/spi/SpiComIF.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include @@ -180,8 +179,11 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s /* Pull SPI CS low. For now, no support for active high given */ if(gpioId != gpio::NO_GPIO) { - /* GPIO access is mutex protected */ - MutexGuard(spiMutex, timeoutType, timeoutMs); + result = spiMutex->lockMutex(timeoutType, timeoutMs); + if (result != RETURN_OK) { + sif::error << "SpiComIF::sendMessage: Failed to lock mutex" << std::endl; + return result; + } gpioComIF->pullLow(gpioId); } @@ -226,6 +228,11 @@ ReturnValue_t SpiComIF::sendMessage(CookieIF *cookie, const uint8_t *sendData, s if(gpioId != gpio::NO_GPIO) { gpioComIF->pullHigh(gpioId); + result = spiMutex->unlockMutex(); + if (result != RETURN_OK) { + sif::error << "SpiComIF::sendMessage: Failed to unlock mutex" << std::endl; + return result; + } } return result; } @@ -263,7 +270,11 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLe gpioId_t gpioId = spiCookie->getChipSelectPin(); if(gpioId != gpio::NO_GPIO) { - MutexGuard(spiMutex, timeoutType, timeoutMs); + result = spiMutex->lockMutex(timeoutType, timeoutMs); + if (result != RETURN_OK) { + sif::error << "SpiComIF::getSendSuccess: Failed to lock mutex" << std::endl; + return result; + } gpioComIF->pullLow(gpioId); } @@ -280,6 +291,11 @@ ReturnValue_t SpiComIF::requestReceiveMessage(CookieIF *cookie, size_t requestLe if(gpioId != gpio::NO_GPIO) { gpioComIF->pullHigh(gpioId); + result = spiMutex->unlockMutex(); + if (result != RETURN_OK) { + sif::error << "SpiComIF::getSendSuccess: Failed to unlock mutex" << std::endl; + return result; + } } return HasReturnvaluesIF::RETURN_OK; -- 2.34.1