From 680311b4df5b56560e960bd1c1f7a9a5de079fda Mon Sep 17 00:00:00 2001 From: halx99 Date: Sat, 19 Oct 2024 08:21:39 +0800 Subject: [PATCH] Delete unused files --- core/base/AsyncTaskPool.cpp | 53 -------- core/base/AsyncTaskPool.h | 232 ------------------------------------ core/base/CMakeLists.txt | 5 - 3 files changed, 290 deletions(-) delete mode 100644 core/base/AsyncTaskPool.cpp delete mode 100644 core/base/AsyncTaskPool.h diff --git a/core/base/AsyncTaskPool.cpp b/core/base/AsyncTaskPool.cpp deleted file mode 100644 index 5ee32e08fd6..00000000000 --- a/core/base/AsyncTaskPool.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -https://axmol.dev/ - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#include "base/AsyncTaskPool.h" - -namespace ax -{ - -AsyncTaskPool* AsyncTaskPool::s_asyncTaskPool = nullptr; - -AsyncTaskPool* AsyncTaskPool::getInstance() -{ - if (s_asyncTaskPool == nullptr) - { - s_asyncTaskPool = new AsyncTaskPool(); - } - return s_asyncTaskPool; -} - -void AsyncTaskPool::destroyInstance() -{ - delete s_asyncTaskPool; - s_asyncTaskPool = nullptr; -} - -AsyncTaskPool::AsyncTaskPool() {} - -AsyncTaskPool::~AsyncTaskPool() {} - -} diff --git a/core/base/AsyncTaskPool.h b/core/base/AsyncTaskPool.h deleted file mode 100644 index dc189799b8c..00000000000 --- a/core/base/AsyncTaskPool.h +++ /dev/null @@ -1,232 +0,0 @@ -/**************************************************************************** -Copyright (c) 2013-2016 Chukong Technologies Inc. -Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - -https://axmol.dev/ - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -****************************************************************************/ - -#ifndef __CCSYNC_TASK_POOL_H_ -#define __CCSYNC_TASK_POOL_H_ - -#include "platform/PlatformMacros.h" -#include "base/Director.h" -#include "base/Scheduler.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * @addtogroup base - * @{ - */ -namespace ax -{ - -/** - * @class AsyncTaskPool - * @brief This class allows to perform background operations without having to manipulate threads. - * @js NA - */ -class AX_DLL AsyncTaskPool -{ -public: - typedef std::function TaskCallBack; - - enum class TaskType - { - TASK_IO, - TASK_NETWORK, - TASK_OTHER, - TASK_MAX_TYPE, - }; - - /** - * Returns the shared instance of the async task pool. - */ - static AsyncTaskPool* getInstance(); - - /** - * Destroys the async task pool. - */ - static void destroyInstance(); - - /** - * Stop tasks. - * - * @param type Task type you want to stop. - */ - void stopTasks(TaskType type); - - /** - * Enqueue a asynchronous task. - * - * @param type task type is io task, network task or others, each type of task has a thread to deal with it. - * @param callback callback when the task is finished. The callback is called in the main thread instead of task - * thread. - * @param callbackParam parameter used by the callback. - * @param task: task can be lambda function to be performed off thread. - * @lua NA - */ - void enqueue(TaskType type, TaskCallBack callback, void* callbackParam, std::function task); - - /** - * Enqueue a asynchronous task. - * - * @param type task type is io task, network task or others, each type of task has a thread to deal with it. - * @param task: task can be lambda function to be performed off thread. - * @lua NA - */ - void enqueue(AsyncTaskPool::TaskType type, std::function task); - - AsyncTaskPool(); - ~AsyncTaskPool(); - -protected: - // thread tasks internally used - class ThreadTasks - { - struct AsyncTaskCallBack - { - TaskCallBack callback; - void* callbackParam; - }; - - public: - ThreadTasks() : _stop(false) - { - _thread = std::thread([this] { - for (;;) - { - std::function task; - AsyncTaskCallBack callback; - { - std::unique_lock lock(this->_queueMutex); - this->_condition.wait(lock, [this] { return this->_stop || !this->_tasks.empty(); }); - if (this->_stop && this->_tasks.empty()) - return; - task = std::move(this->_tasks.front()); - callback = std::move(this->_taskCallBacks.front()); - this->_tasks.pop(); - this->_taskCallBacks.pop(); - } - - task(); - Director::getInstance()->getScheduler()->runOnAxmolThread( - std::bind(callback.callback, callback.callbackParam)); - } - }); - } - ~ThreadTasks() - { - { - std::unique_lock lock(_queueMutex); - _stop = true; - - while (_tasks.size()) - _tasks.pop(); - while (_taskCallBacks.size()) - _taskCallBacks.pop(); - } - _condition.notify_all(); - _thread.join(); - } - void clear() - { - std::unique_lock lock(_queueMutex); - while (_tasks.size()) - _tasks.pop(); - while (_taskCallBacks.size()) - _taskCallBacks.pop(); - } - - void enqueue(TaskCallBack callback, void* callbackParam, std::function task) - { - AsyncTaskCallBack taskCallBack; - taskCallBack.callback = std::move(callback); - taskCallBack.callbackParam = callbackParam; - - { - std::unique_lock lock(_queueMutex); - - // don't allow enqueueing after stopping the pool - if (_stop) - { - AX_ASSERT(0 && "already stop"); - return; - } - - _tasks.push(std::move(task)); - _taskCallBacks.push(std::move(taskCallBack)); - } - _condition.notify_one(); - } - - private: - // need to keep track of thread so we can join them - std::thread _thread; - // the task queue - std::queue> _tasks; - std::queue _taskCallBacks; - - // synchronization - std::mutex _queueMutex; - std::condition_variable _condition; - bool _stop; - }; - - // tasks - ThreadTasks _threadTasks[int(TaskType::TASK_MAX_TYPE)]; - - static AsyncTaskPool* s_asyncTaskPool; -}; - -inline void AsyncTaskPool::stopTasks(TaskType type) -{ - auto& threadTask = _threadTasks[(int)type]; - threadTask.clear(); -} - -inline void AsyncTaskPool::enqueue(AsyncTaskPool::TaskType type, - TaskCallBack callback, - void* callbackParam, - std::function task) -{ - auto& threadTask = _threadTasks[(int)type]; - - threadTask.enqueue(std::move(callback), callbackParam, std::move(task)); -} - -inline void AsyncTaskPool::enqueue(AsyncTaskPool::TaskType type, std::function task) -{ - enqueue( - type, [](void*) {}, nullptr, std::move(task)); -} - -} -// end group -/// @} -#endif //__CCSYNC_TASK_POOL_H_ diff --git a/core/base/CMakeLists.txt b/core/base/CMakeLists.txt index 371dc859240..8161cd1b224 100644 --- a/core/base/CMakeLists.txt +++ b/core/base/CMakeLists.txt @@ -139,11 +139,6 @@ set(_AX_BASE_SRC ${_AX_BASE_SPECIFIC_SRC} ) -if(NOT AX_CORE_PROFILE) - set(_AX_BASE_HEADER ${_AX_BASE_HEADER} base/AsyncTaskPool.h) - set(_AX_BASE_SRC ${_AX_BASE_SRC} base/AsyncTaskPool.cpp) -endif() - if(AX_ENABLE_CONSOLE) set(_AX_BASE_HEADER ${_AX_BASE_HEADER} base/Console.h) set(_AX_BASE_SRC ${_AX_BASE_SRC} base/Console.cpp)