blob: 3b5fd3570b84c6868bcf1929e7e7aadfe7c571d3 [file] [log] [blame]
Narumol Prangnawarat7be47ef2019-09-27 18:00:11 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "PacketBuffer.hpp"
7
Jim Flynnf9db3ef2022-03-08 21:23:44 +00008#include <common/include/ProfilingException.hpp>
Narumol Prangnawarat7be47ef2019-09-27 18:00:11 +01009
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000010namespace arm
Narumol Prangnawarat7be47ef2019-09-27 18:00:11 +010011{
12
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000013namespace pipe
Narumol Prangnawarat7be47ef2019-09-27 18:00:11 +010014{
15
16PacketBuffer::PacketBuffer(unsigned int maxSize)
17 : m_MaxSize(maxSize)
18 , m_Size(0)
19{
20 m_Data = std::make_unique<unsigned char[]>(m_MaxSize);
21}
22
Matteo Martincigh76c50d82019-11-21 12:10:42 +000023const unsigned char* PacketBuffer::GetReadableData() const
Narumol Prangnawarat7be47ef2019-09-27 18:00:11 +010024{
25 return m_Data.get();
26}
27
28unsigned int PacketBuffer::GetSize() const
29{
30 return m_Size;
31}
32
33void PacketBuffer::MarkRead()
34{
35 m_Size = 0;
36}
37
38void PacketBuffer::Commit(unsigned int size)
39{
40 if (size > m_MaxSize)
41 {
Jim Flynnf9db3ef2022-03-08 21:23:44 +000042 throw arm::pipe::ProfilingException("Cannot commit [" + std::to_string(size) +
43 "] bytes which is more than the maximum size of the buffer [" + std::to_string(m_MaxSize) + "]");
Narumol Prangnawarat7be47ef2019-09-27 18:00:11 +010044 }
45 m_Size = size;
46}
47
48void PacketBuffer::Release()
49{
50 m_Size = 0;
51}
52
53unsigned char* PacketBuffer::GetWritableData()
54{
55 return m_Data.get();
56}
57
Jim Flynn0204f092020-06-22 20:41:43 +010058void PacketBuffer::Destroy()
59{
60 m_Data.reset(nullptr);
61 m_Size = 0;
62 m_MaxSize = 0;
63}
64
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000065} // namespace pipe
Narumol Prangnawarat7be47ef2019-09-27 18:00:11 +010066
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000067} // namespace arm