From 2fc39f37dc389505171c596094815c6ac0ab8455 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 10 Feb 2022 08:44:44 +0100 Subject: [PATCH] Remove the ObjectPool from trantor. --- .../drogon/trantor/utils/ObjectPool.h | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 web_backends/drogon/trantor/utils/ObjectPool.h diff --git a/web_backends/drogon/trantor/utils/ObjectPool.h b/web_backends/drogon/trantor/utils/ObjectPool.h deleted file mode 100644 index 145a355..0000000 --- a/web_backends/drogon/trantor/utils/ObjectPool.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * - * @file ObjectPool.h - * @author An Tao - * - * Public header file in trantor lib. - * - * Copyright 2018, An Tao. All rights reserved. - * Use of this source code is governed by a BSD-style license - * that can be found in the License file. - * - * - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace trantor -{ -/** - * @brief This class template represents a object pool. - * - * @tparam T - */ -template -class ObjectPool : public NonCopyable, - public std::enable_shared_from_this> -{ - public: - std::shared_ptr getObject() - { - static_assert(!std::is_pointer::value, - "The parameter type of the ObjectPool template can't be " - "pointer type"); - T *p{nullptr}; - { - std::lock_guard lock(mtx_); - if (!objs_.empty()) - { - p = objs_.back(); - objs_.pop_back(); - } - } - - if (p == nullptr) - { - p = new T; - } - - assert(p); - std::weak_ptr> weakPtr = this->shared_from_this(); - auto obj = std::shared_ptr(p, [weakPtr](T *ptr) { - auto self = weakPtr.lock(); - if (self) - { - std::lock_guard lock(self->mtx_); - self->objs_.push_back(ptr); - } - else - { - delete ptr; - } - }); - return obj; - } - - private: - std::vector objs_; - std::mutex mtx_; -}; -} // namespace trantor \ No newline at end of file