From fd7f2211a8824cf135ca6a4b3ef6f1e66eac016e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Wed, 12 Sep 2018 15:04:24 +0900 Subject: [PATCH] [coco] Support Bag destruction (#1463) This commit extends BagManager with destroy method. This change allows users to safely destruct bags allocated via Bagmanager. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/BagManager.h | 6 ++++++ contrib/coco/core/src/IR/BagManager.cpp | 2 ++ contrib/coco/core/src/IR/BagManager.test.cpp | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/contrib/coco/core/include/coco/IR/BagManager.h b/contrib/coco/core/include/coco/IR/BagManager.h index 42cf793..81851bd 100644 --- a/contrib/coco/core/include/coco/IR/BagManager.h +++ b/contrib/coco/core/include/coco/IR/BagManager.h @@ -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 *const _link; }; diff --git a/contrib/coco/core/src/IR/BagManager.cpp b/contrib/coco/core/src/IR/BagManager.cpp index 36ff82f..fce9344 100644 --- a/contrib/coco/core/src/IR/BagManager.cpp +++ b/contrib/coco/core/src/IR/BagManager.cpp @@ -19,4 +19,6 @@ Bag *BagManager::create(uint32_t size) return take(std::move(bag)); } +void BagManager::destroy(Bag *b) { release(b); } + } // namespace coco diff --git a/contrib/coco/core/src/IR/BagManager.test.cpp b/contrib/coco/core/src/IR/BagManager.test.cpp index a165269..43fa616 100644 --- a/contrib/coco/core/src/IR/BagManager.test.cpp +++ b/contrib/coco/core/src/IR/BagManager.test.cpp @@ -19,3 +19,14 @@ TEST(IR_BAG_MANAGER, create) ASSERT_EQ(info->size(), 3); } + +TEST(IR_BAG_MANAGER, destruct) +{ + coco::PtrLink bag_link; + coco::BagManager mgr{&bag_link}; + + auto b = mgr.create(3); + mgr.destroy(b); + + ASSERT_EQ(mgr.size(), 0); +} -- 2.7.4