ArmNN
 20.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 273 of file ProfilingMocks.hpp.

Constructor & Destructor Documentation

◆ MockStreamCounterBuffer()

MockStreamCounterBuffer ( unsigned int  maxBufferSize = 4096)
inline

Definition at line 276 of file ProfilingMocks.hpp.

277  : m_MaxBufferSize(maxBufferSize)
278  , m_BufferList()
279  , m_CommittedSize(0)
280  , m_ReadableSize(0)
281  , m_ReadSize(0)
282  {}

◆ ~MockStreamCounterBuffer()

Definition at line 283 of file ProfilingMocks.hpp.

283 {}

Member Function Documentation

◆ Commit()

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

Implements IBufferManager.

Definition at line 299 of file ProfilingMocks.hpp.

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

◆ FlushReadList()

void FlushReadList ( )
inlineoverridevirtual

Implements IBufferManager.

Definition at line 350 of file ProfilingMocks.hpp.

351  {
352  // notify consumer that packet is ready to read
353  if (m_Consumer != nullptr)
354  {
355  m_Consumer->SetReadyToRead();
356  }
357  }
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 359 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

359 { return m_CommittedSize; }

◆ GetReadableBuffer()

IPacketBufferPtr GetReadableBuffer ( )
inlineoverridevirtual

Implements IBufferManager.

Definition at line 320 of file ProfilingMocks.hpp.

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

◆ GetReadableSize()

unsigned int GetReadableSize ( ) const
inline

Definition at line 360 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

360 { return m_ReadableSize; }

◆ GetReadSize()

unsigned int GetReadSize ( ) const
inline

Definition at line 361 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

361 { return m_ReadSize; }

◆ MarkRead()

void MarkRead ( IPacketBufferPtr packetBuffer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 334 of file ProfilingMocks.hpp.

335  {
336  std::lock_guard<std::mutex> lock(m_Mutex);
337 
338  m_ReadSize += packetBuffer->GetSize();
339  packetBuffer->MarkRead();
340  }

◆ Release()

void Release ( IPacketBufferPtr packetBuffer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 313 of file ProfilingMocks.hpp.

314  {
315  std::lock_guard<std::mutex> lock(m_Mutex);
316 
317  packetBuffer->Release();
318  }

◆ Reserve()

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

Implements IBufferManager.

Definition at line 285 of file ProfilingMocks.hpp.

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

◆ SetConsumer()

void SetConsumer ( IConsumer consumer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 342 of file ProfilingMocks.hpp.

343  {
344  if (consumer != nullptr)
345  {
346  m_Consumer = consumer;
347  }
348  }

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