ArmNN
 21.08
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 278 of file ProfilingMocks.hpp.

Constructor & Destructor Documentation

◆ MockStreamCounterBuffer()

MockStreamCounterBuffer ( unsigned int  maxBufferSize = 4096)
inline

Definition at line 281 of file ProfilingMocks.hpp.

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

◆ ~MockStreamCounterBuffer()

Definition at line 288 of file ProfilingMocks.hpp.

288 {}

Member Function Documentation

◆ Commit()

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

Implements IBufferManager.

Definition at line 304 of file ProfilingMocks.hpp.

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

◆ FlushReadList()

void FlushReadList ( )
inlineoverridevirtual

Implements IBufferManager.

Definition at line 355 of file ProfilingMocks.hpp.

356  {
357  // notify consumer that packet is ready to read
358  if (m_Consumer != nullptr)
359  {
360  m_Consumer->SetReadyToRead();
361  }
362  }
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 364 of file ProfilingMocks.hpp.

364 { return m_CommittedSize; }

◆ GetReadableBuffer()

IPacketBufferPtr GetReadableBuffer ( )
inlineoverridevirtual

Implements IBufferManager.

Definition at line 325 of file ProfilingMocks.hpp.

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

◆ GetReadableSize()

unsigned int GetReadableSize ( ) const
inline

Definition at line 365 of file ProfilingMocks.hpp.

365 { return m_ReadableSize; }

◆ GetReadSize()

unsigned int GetReadSize ( ) const
inline

Definition at line 366 of file ProfilingMocks.hpp.

366 { return m_ReadSize; }

◆ MarkRead()

void MarkRead ( IPacketBufferPtr packetBuffer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 339 of file ProfilingMocks.hpp.

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

◆ Release()

void Release ( IPacketBufferPtr packetBuffer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 318 of file ProfilingMocks.hpp.

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

◆ Reserve()

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

Implements IBufferManager.

Definition at line 290 of file ProfilingMocks.hpp.

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

◆ SetConsumer()

void SetConsumer ( IConsumer consumer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 347 of file ProfilingMocks.hpp.

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

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