Added lock/unlock interface

This commit is contained in:
John Wellbelove 2021-01-20 14:07:27 +00:00
parent 2e7c79ed38
commit 66304646a5
2 changed files with 22 additions and 0 deletions

View File

@ -46,6 +46,24 @@ namespace etl
virtual ~ireference_counted_message_pool() {}
virtual void release(const etl::ireference_counted_message& msg) = 0;
//***************************************************************************
/// The pool lock function.
/// Override to add thread or interrupt locking to the pool.
//***************************************************************************
virtual void lock()
{
// The default implementation does nothing.
}
//***************************************************************************
/// The pool unlock function.
/// Override to add thread or interrupt unlocking to the pool.
//***************************************************************************
virtual void unlock()
{
// The default implementation does nothing.
}
};
}

View File

@ -116,7 +116,9 @@ namespace etl
prcm_t p = ETL_NULLPTR;
lock();
p = static_cast<prcm_t>(memory_block_allocator.allocate(sizeof(rcm_t)));
unlock();
if (p != ETL_NULLPTR)
{
@ -134,7 +136,9 @@ namespace etl
void release(const etl::ireference_counted_message& rcmessage)
{
rcmessage.~ireference_counted_message();
lock();
bool released = memory_block_allocator.release(&rcmessage);
unlock();
ETL_ASSERT(released, ETL_ERROR(etl::reference_counted_message_pool_release_failure));
}