ArmNN
 20.05
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 275 of file ProfilingMocks.hpp.

Constructor & Destructor Documentation

◆ MockStreamCounterBuffer()

MockStreamCounterBuffer ( unsigned int  maxBufferSize = 4096)
inline

Definition at line 278 of file ProfilingMocks.hpp.

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

◆ ~MockStreamCounterBuffer()

Definition at line 285 of file ProfilingMocks.hpp.

285 {}

Member Function Documentation

◆ Commit()

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

Implements IBufferManager.

Definition at line 301 of file ProfilingMocks.hpp.

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

◆ FlushReadList()

void FlushReadList ( )
inlineoverridevirtual

Implements IBufferManager.

Definition at line 352 of file ProfilingMocks.hpp.

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

Referenced by BOOST_AUTO_TEST_CASE().

361 { return m_CommittedSize; }

◆ GetReadableBuffer()

IPacketBufferPtr GetReadableBuffer ( )
inlineoverridevirtual

Implements IBufferManager.

Definition at line 322 of file ProfilingMocks.hpp.

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

◆ GetReadableSize()

unsigned int GetReadableSize ( ) const
inline

Definition at line 362 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

362 { return m_ReadableSize; }

◆ GetReadSize()

unsigned int GetReadSize ( ) const
inline

Definition at line 363 of file ProfilingMocks.hpp.

Referenced by BOOST_AUTO_TEST_CASE().

363 { return m_ReadSize; }

◆ MarkRead()

void MarkRead ( IPacketBufferPtr packetBuffer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 336 of file ProfilingMocks.hpp.

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

◆ Release()

void Release ( IPacketBufferPtr packetBuffer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 315 of file ProfilingMocks.hpp.

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

◆ Reserve()

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

Implements IBufferManager.

Definition at line 287 of file ProfilingMocks.hpp.

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

◆ SetConsumer()

void SetConsumer ( IConsumer consumer)
inlineoverridevirtual

Implements IBufferManager.

Definition at line 344 of file ProfilingMocks.hpp.

345  {
346  if (consumer != nullptr)
347  {
348  m_Consumer = consumer;
349  }
350  }

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