diff options
author | Andreas Hansson <andreas.hansson@arm.com> | 2014-12-02 06:07:43 -0500 |
---|---|---|
committer | Andreas Hansson <andreas.hansson@arm.com> | 2014-12-02 06:07:43 -0500 |
commit | 41846cb61b0f511099eb9a203f11885de328ab45 (patch) | |
tree | 7563b309ba914ea57dd12e6cfba3ea33817ab1b1 /src/mem | |
parent | 5df96cb690168d750ab0fafffd11fb51624374d2 (diff) | |
download | gem5-41846cb61b0f511099eb9a203f11885de328ab45.tar.xz |
mem: Assume all dynamic packet data is array allocated
This patch simplifies how we deal with dynamically allocated data in
the packet, always assuming that it is array allocated, and hence
should be array deallocated (delete[] as opposed to delete). The only
uses of dataDynamic was in the Ruby testers.
The ARRAY_DATA flag in the packet is removed accordingly. No
defragmentation of the flags is done at this point, leaving a gap in
the bit masks.
As the last part the patch, it renames dataDynamicArray to dataDynamic.
Diffstat (limited to 'src/mem')
-rw-r--r-- | src/mem/packet.hh | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/src/mem/packet.hh b/src/mem/packet.hh index e8fb00680..19423db58 100644 --- a/src/mem/packet.hh +++ b/src/mem/packet.hh @@ -247,11 +247,9 @@ class Packet : public Printable /// when the packet is destroyed? static const FlagsType STATIC_DATA = 0x00001000; /// The data pointer points to a value that should be freed when - /// the packet is destroyed. + /// the packet is destroyed. The pointer is assumed to be pointing + /// to an array, and delete [] is consequently called static const FlagsType DYNAMIC_DATA = 0x00002000; - /// the data pointer points to an array (thus delete []) needs to - /// be called on it rather than simply delete. - static const FlagsType ARRAY_DATA = 0x00004000; /// suppress the error if this packet encounters a functional /// access failure. static const FlagsType SUPPRESS_FUNC_ERROR = 0x00008000; @@ -813,7 +811,7 @@ class Packet : public Printable void dataStatic(T *p) { - assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); + assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); data = (PacketDataPtr)p; flags.set(STATIC_DATA); } @@ -830,7 +828,7 @@ class Packet : public Printable void dataStaticConst(const T *p) { - assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); + assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); data = const_cast<PacketDataPtr>(p); flags.set(STATIC_DATA); } @@ -841,22 +839,9 @@ class Packet : public Printable */ template <typename T> void - dataDynamicArray(T *p) - { - assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); - data = (PacketDataPtr)p; - flags.set(DYNAMIC_DATA|ARRAY_DATA); - } - - /** - * set the data pointer to a value that should have delete called - * on it. - */ - template <typename T> - void dataDynamic(T *p) { - assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA)); + assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); data = (PacketDataPtr)p; flags.set(DYNAMIC_DATA); } @@ -938,12 +923,10 @@ class Packet : public Printable void deleteData() { - if (flags.isSet(ARRAY_DATA)) + if (flags.isSet(DYNAMIC_DATA)) delete [] data; - else if (flags.isSet(DYNAMIC_DATA)) - delete data; - flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA); + flags.clear(STATIC_DATA|DYNAMIC_DATA); data = NULL; } @@ -952,7 +935,7 @@ class Packet : public Printable allocate() { assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA)); - flags.set(DYNAMIC_DATA|ARRAY_DATA); + flags.set(DYNAMIC_DATA); data = new uint8_t[getSize()]; } |