Line data Source code
1 : // 2 : // Copyright 2024 OpenModelViewer Authors 3 : // 4 : // Licensed under the Apache License, Version 2.0 (the "License"); 5 : // you may not use this file except in compliance with the License. 6 : // You may obtain a copy of the License at 7 : // 8 : // http://www.apache.org/licenses/LICENSE-2.0 9 : // 10 : // Unless required by applicable law or agreed to in writing, software 11 : // distributed under the License is distributed on an "AS IS" BASIS, 12 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 : // See the License for the specific language governing permissions and 14 : // limitations under the License. 15 : // 16 : 17 : #pragma once 18 : 19 : #include "openmodelviewer/core/async/task_handle.hpp" 20 : #include "openmodelviewer/core/async/task_type.hpp" 21 : #include "openmodelviewer/core/id/atomic_id_generator.hpp" 22 : 23 : namespace openmodelviewer::core::async 24 : { 25 : /** 26 : * @brief Generator for creating unique TaskHandle objects. 27 : * 28 : * This class encapsulates the logic for assigning thread-safe unique IDs 29 : * to tasks. It relies on an AtomicIdGenerator internally to ensure 30 : * uniqueness across threads. 31 : */ 32 : class TaskHandleGenerator 33 : { 34 : public: 35 : /** 36 : * @brief Constructs a new TaskHandleGenerator. 37 : * 38 : * Initializes the internal counter to start at 1. 39 : */ 40 63 : TaskHandleGenerator() = default; 41 : 42 : /** 43 : * @brief Generates a new TaskHandle with a unique TaskId. 44 : * 45 : * Each call produces a TaskHandle with a unique TaskId and the 46 : * specified TaskType. 47 : * 48 : * @param type The type of thread or queue for which the task is scheduled. 49 : * @return A TaskHandle with a unique identifier and the specified type. 50 : */ 51 : TaskHandle generate(TaskType type) noexcept; 52 : 53 : private: 54 : id::AtomicIdGenerator m_generator; 55 : }; 56 : } // namespace openmodelviewer::core::async