[coco] Support Bag destruction (#1463)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 12 Sep 2018 06:04:24 +0000 (15:04 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 12 Sep 2018 06:04:24 +0000 (15:04 +0900)
This commit extends BagManager with destroy method. This change allows
users to safely destruct bags allocated via Bagmanager.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/BagManager.h
contrib/coco/core/src/IR/BagManager.cpp
contrib/coco/core/src/IR/BagManager.test.cpp

index 42cf793..81851bd 100644 (file)
@@ -20,6 +20,12 @@ public:
 public:
   Bag *create(uint32_t size);
 
+public:
+  // @brief Destroy (= deallocate) a Bag entity
+  //
+  // NOTE A Bag SHOULD BE detached from IR before destruction
+  void destroy(Bag *b);
+
 private:
   PtrLink<Bag, BagInfo> *const _link;
 };
index 36ff82f..fce9344 100644 (file)
@@ -19,4 +19,6 @@ Bag *BagManager::create(uint32_t size)
   return take(std::move(bag));
 }
 
+void BagManager::destroy(Bag *b) { release(b); }
+
 } // namespace coco
index a165269..43fa616 100644 (file)
@@ -19,3 +19,14 @@ TEST(IR_BAG_MANAGER, create)
 
   ASSERT_EQ(info->size(), 3);
 }
+
+TEST(IR_BAG_MANAGER, destruct)
+{
+  coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
+  coco::BagManager mgr{&bag_link};
+
+  auto b = mgr.create(3);
+  mgr.destroy(b);
+
+  ASSERT_EQ(mgr.size(), 0);
+}