Skip to content

Commit

Permalink
Style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
multiplemonomials committed Aug 23, 2023
1 parent 8beba56 commit 8833852
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
5 changes: 4 additions & 1 deletion drivers/include/drivers/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,10 @@ class SPI : private NonCopyable<SPI> {

private:

rtos::Mutex & _get_peripherals_mutex();
/**
* Get a reference to the mutex used to protect the peripherals array.
*/
rtos::Mutex &_get_peripherals_mutex();

void _do_construct();

Expand Down
21 changes: 9 additions & 12 deletions drivers/source/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ void SPI::_do_init_direct(SPI *obj)
spi_init_direct(&obj->_peripheral->spi, obj->_static_pinmap);
}

rtos::Mutex &SPI::_get_peripherals_mutex()
{
static rtos::Mutex peripherals_mutex;
return peripherals_mutex;
}

void SPI::_do_construct()
{
// No lock needed in the constructor
Expand All @@ -135,7 +141,7 @@ void SPI::_do_construct()
_write_fill = SPI_FILL_CHAR;

{
rtos::ScopedMutexLock lock(_get_peripherals_mutex());
rtos::ScopedMutexLock lock(_get_peripherals_mutex());

// lookup and claim the peripheral with the mutex locked in case another thread is
// also trying to claim it
Expand Down Expand Up @@ -171,13 +177,11 @@ SPI::~SPI()
rtos::ScopedMutexLock lock(_get_peripherals_mutex());

/* Make sure a stale pointer isn't left in peripheral's owner field */
if (_peripheral->owner == this)
{
if (_peripheral->owner == this) {
_peripheral->owner = nullptr;
}

if (--_peripheral->numUsers == 0)
{
if (--_peripheral->numUsers == 0) {
_dealloc(_peripheral);
}
}
Expand Down Expand Up @@ -524,13 +528,6 @@ void SPI::irq_handler_asynch(void)
#endif
}

rtos::Mutex &SPI::_get_peripherals_mutex()
{
static rtos::Mutex peripherals_mutex;
return peripherals_mutex;
}


#endif

} // namespace mbed
Expand Down

0 comments on commit 8833852

Please sign in to comment.