Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-18 10:24:20

0001 /*
0002     Copyright (c) 2020-2024 Intel Corporation
0003 
0004     Licensed under the Apache License, Version 2.0 (the "License");
0005     you may not use this file except in compliance with the License.
0006     You may obtain a copy of the License at
0007 
0008         http://www.apache.org/licenses/LICENSE-2.0
0009 
0010     Unless required by applicable law or agreed to in writing, software
0011     distributed under the License is distributed on an "AS IS" BASIS,
0012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     See the License for the specific language governing permissions and
0014     limitations under the License.
0015 */
0016 
0017 
0018 #ifndef __TBB_task_handle_H
0019 #define __TBB_task_handle_H
0020 
0021 #include "_config.h"
0022 #include "_task.h"
0023 #include "_small_object_pool.h"
0024 #include "_utils.h"
0025 #include <memory>
0026 
0027 namespace tbb {
0028 namespace detail {
0029 
0030 namespace d1 { class task_group_context; class wait_context; struct execution_data; }
0031 namespace d2 {
0032 
0033 class task_handle;
0034 
0035 class task_handle_task : public d1::task {
0036     std::uint64_t m_version_and_traits{};
0037     d1::wait_tree_vertex_interface* m_wait_tree_vertex;
0038     d1::task_group_context& m_ctx;
0039     d1::small_object_allocator m_allocator;
0040 public:
0041     void finalize(const d1::execution_data* ed = nullptr) {
0042         if (ed) {
0043             m_allocator.delete_object(this, *ed);
0044         } else {
0045             m_allocator.delete_object(this);
0046         }
0047     }
0048 
0049     task_handle_task(d1::wait_tree_vertex_interface* vertex, d1::task_group_context& ctx, d1::small_object_allocator& alloc)
0050         : m_wait_tree_vertex(vertex)
0051         , m_ctx(ctx)
0052         , m_allocator(alloc) {
0053         suppress_unused_warning(m_version_and_traits);
0054         m_wait_tree_vertex->reserve();
0055     }
0056 
0057     ~task_handle_task() override {
0058         m_wait_tree_vertex->release();
0059     }
0060 
0061     d1::task_group_context& ctx() const { return m_ctx; }
0062 };
0063 
0064 
0065 class task_handle {
0066     struct task_handle_task_finalizer_t{
0067         void operator()(task_handle_task* p){ p->finalize(); }
0068     };
0069     using handle_impl_t = std::unique_ptr<task_handle_task, task_handle_task_finalizer_t>;
0070 
0071     handle_impl_t m_handle = {nullptr};
0072 public:
0073     task_handle() = default;
0074     task_handle(task_handle&&) = default;
0075     task_handle& operator=(task_handle&&) = default;
0076 
0077     explicit operator bool() const noexcept { return static_cast<bool>(m_handle); }
0078 
0079     friend bool operator==(task_handle const& th, std::nullptr_t) noexcept;
0080     friend bool operator==(std::nullptr_t, task_handle const& th) noexcept;
0081 
0082     friend bool operator!=(task_handle const& th, std::nullptr_t) noexcept;
0083     friend bool operator!=(std::nullptr_t, task_handle const& th) noexcept;
0084 
0085 private:
0086     friend struct task_handle_accessor;
0087 
0088     task_handle(task_handle_task* t) : m_handle {t}{};
0089 
0090     d1::task* release() {
0091        return m_handle.release();
0092     }
0093 };
0094 
0095 struct task_handle_accessor {
0096 static task_handle              construct(task_handle_task* t)  { return {t}; }
0097 static d1::task*                release(task_handle& th)        { return th.release(); }
0098 static d1::task_group_context&  ctx_of(task_handle& th)         {
0099     __TBB_ASSERT(th.m_handle, "ctx_of does not expect empty task_handle.");
0100     return th.m_handle->ctx();
0101 }
0102 };
0103 
0104 inline bool operator==(task_handle const& th, std::nullptr_t) noexcept {
0105     return th.m_handle == nullptr;
0106 }
0107 inline bool operator==(std::nullptr_t, task_handle const& th) noexcept {
0108     return th.m_handle == nullptr;
0109 }
0110 
0111 inline bool operator!=(task_handle const& th, std::nullptr_t) noexcept {
0112     return th.m_handle != nullptr;
0113 }
0114 
0115 inline bool operator!=(std::nullptr_t, task_handle const& th) noexcept {
0116     return th.m_handle != nullptr;
0117 }
0118 
0119 } // namespace d2
0120 } // namespace detail
0121 } // namespace tbb
0122 
0123 #endif /* __TBB_task_handle_H */