ArmNN
 21.02
MockStreamCounterBuffer Class Reference

#include <ProfilingMocks.hpp>

Inheritance diagram for MockStreamCounterBuffer:
IBufferManager

Public Member Functions

 MockStreamCounterBuffer (unsigned int maxBufferSize=4096)
 
 ~MockStreamCounterBuffer ()
 
IPacketBufferPtr Reserve (unsigned int requestedSize, unsigned int &reservedSize) override
 
void Commit (IPacketBufferPtr &packetBuffer, unsigned int size, bool notifyConsumer=true) override
 
void Release (IPacketBufferPtr &packetBuffer) override
 
IPacketBufferPtr GetReadableBuffer () override
 
void MarkRead (IPacketBufferPtr &packetBuffer) override
 
void SetConsumer (IConsumer *consumer) override
 
void FlushReadList () override
 
unsigned int GetCommittedSize () const
 
unsigned int GetReadableSize () const
 
unsigned int GetReadSize () const
 
- Public Member Functions inherited from IBufferManager
virtual ~IBufferManager ()
 

Detailed Description

Definition at line 277 of file ProfilingMocks.hpp.

Constructor & Destructor Documentation

◆ MockStreamCounterBuffer()

MockStreamCounterBuffer ( unsigned int  maxBufferSize = 4096)
inline

Definition at line 280 of file ProfilingMocks.hpp.

281  : m_MaxBufferSize(maxBufferSize)
282  , m_BufferList()
283  , m_CommittedSize(0)
284  , m_ReadableSize(0)
285  , m_ReadSize(0)
286  {}

◆ ~MockStreamCounterBuffer()

Definition at line 287 of file ProfilingMocks.hpp.

287 {}

Member Function Documentation

◆ Commit()

void Commit ( IPacketBufferPtr packetBuffer,
unsigned int  size,
bool  notifyConsumer = true 
)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 303 of file ProfilingMocks.hpp.

304  {
305  std::lock_guard<std::mutex> lock(m_Mutex);
306 
307  packetBuffer->Commit(size);
308  m_BufferList.push_back(std::move(packetBuffer));
309  m_CommittedSize += size;
310 
311  if (notifyConsumer)
312  {
313  FlushReadList();
314  }
315  }

◆ FlushReadList()

void FlushReadList ( )
inlineoverridevirtual

Implements IBufferManager.

Definition at line 354 of file ProfilingMocks.hpp.

355  {
356  // notify consumer that packet is ready to read
357  if (m_Consumer != nullptr)
358  {
359  m_Consumer->SetReadyToRead();
360  }
361  }
virtual void SetReadyToRead()=0
Set a "ready to read" flag in the buffer to notify the reading thread to start reading it...

◆ GetCommittedSize()

unsigned int GetCommittedSize ( ) const
inline

Definition at line 363 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

363 { return m_CommittedSize; }

◆ GetReadableBuffer()

IPacketBufferPtr GetReadableBuffer ( )
inlineoverridevirtual

Implements IBufferManager.

Definition at line 324 of file ProfilingMocks.hpp.

325  {
326  std::lock_guard<std::mutex> lock(m_Mutex);
327 
328  if (m_BufferList.empty())
329  {
330  return nullptr;
331  }
332  IPacketBufferPtr buffer = std::move(m_BufferList.back());
333  m_BufferList.pop_back();
334  m_ReadableSize += buffer->GetSize();
335  return buffer;
336  }
std::unique_ptr< IPacketBuffer > IPacketBufferPtr

◆ GetReadableSize()

unsigned int GetReadableSize ( ) const
inline

Definition at line 364 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

364 { return m_ReadableSize; }

◆ GetReadSize()

unsigned int GetReadSize ( ) const
inline

Definition at line 365 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

365 { return m_ReadSize; }

◆ MarkRead()

void MarkRead ( IPacketBufferPtr packetBuffer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 338 of file ProfilingMocks.hpp.

339  {
340  std::lock_guard<std::mutex> lock(m_Mutex);
341 
342  m_ReadSize += packetBuffer->GetSize();
343  packetBuffer->MarkRead();
344  }

◆ Release()

void Release ( IPacketBufferPtr packetBuffer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 317 of file ProfilingMocks.hpp.

318  {
319  std::lock_guard<std::mutex> lock(m_Mutex);
320 
321  packetBuffer->Release();
322  }

◆ Reserve()

IPacketBufferPtr Reserve ( unsigned int  requestedSize,
unsigned int &  reservedSize 
)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 289 of file ProfilingMocks.hpp.

290  {
291  std::lock_guard<std::mutex> lock(m_Mutex);
292 
293  reservedSize = 0;
294  if (requestedSize > m_MaxBufferSize)
295  {
296  throw armnn::InvalidArgumentException("The maximum buffer size that can be requested is [" +
297  std::to_string(m_MaxBufferSize) + "] bytes");
298  }
299  reservedSize = requestedSize;
300  return std::make_unique<MockPacketBuffer>(requestedSize);
301  }

◆ SetConsumer()

void SetConsumer ( IConsumer consumer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 346 of file ProfilingMocks.hpp.

347  {
348  if (consumer != nullptr)
349  {
350  m_Consumer = consumer;
351  }
352  }

The documentation for this class was generated from the following file: