|
|
|||
Warning, file /include/Geant4/PTL/VUserTaskQueue.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // 0002 // MIT License 0003 // Copyright (c) 2020 Jonathan R. Madsen 0004 // Permission is hereby granted, free of charge, to any person obtaining a copy 0005 // of this software and associated documentation files (the "Software"), to deal 0006 // in the Software without restriction, including without limitation the rights 0007 // to use, copy, modify, merge, publish, distribute, sublicense, and 0008 // copies of the Software, and to permit persons to whom the Software is 0009 // furnished to do so, subject to the following conditions: 0010 // The above copyright notice and this permission notice shall be included in 0011 // all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 0012 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 0013 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 0014 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 0015 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 0016 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 0017 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 0018 // 0019 // --------------------------------------------------------------- 0020 // Tasking class header 0021 // Class Description: 0022 // Abstract base class for creating a task queue used by 0023 // ThreadPool 0024 // --------------------------------------------------------------- 0025 // Author: Jonathan Madsen 0026 // --------------------------------------------------------------- 0027 0028 #pragma once 0029 0030 #include "PTL/Macros.hh" 0031 #include "PTL/Types.hh" 0032 0033 #include <atomic> 0034 #include <cstdint> 0035 #include <functional> 0036 #include <memory> 0037 #include <set> 0038 0039 namespace PTL 0040 { 0041 class VTask; 0042 class ThreadPool; 0043 class ThreadData; 0044 0045 class VUserTaskQueue 0046 { 0047 public: 0048 using task_pointer = std::shared_ptr<VTask>; 0049 using AtomicInt = std::atomic<intmax_t>; 0050 using size_type = uintmax_t; 0051 using function_type = std::function<void()>; 0052 using ThreadIdSet = std::set<ThreadId>; 0053 0054 public: 0055 // Constructor - accepting the number of workers 0056 explicit VUserTaskQueue(intmax_t nworkers = -1); 0057 // Virtual destructors are required by abstract classes 0058 // so add it by default, just in case 0059 virtual ~VUserTaskQueue() = default; 0060 0061 public: 0062 // Virtual function for getting a task from the queue 0063 // parameters: 0064 // 1. int - get from specific sub-queue 0065 // 2. int - number of iterations 0066 // returns: 0067 // VTask* - a task or nullptr 0068 virtual task_pointer GetTask(intmax_t subq = -1, intmax_t nitr = -1) = 0; 0069 0070 // Virtual function for inserting a task into the queue 0071 // parameters: 0072 // 1. VTask* - task to insert 0073 // 2. int - sub-queue to inserting into 0074 // return: 0075 // int - subqueue inserted into 0076 virtual intmax_t InsertTask(task_pointer&&, ThreadData* = nullptr, 0077 intmax_t subq = -1) PTL_NO_SANITIZE_THREAD = 0; 0078 0079 // Overload this function to hold threads 0080 virtual void Wait() = 0; 0081 virtual intmax_t GetThreadBin() const = 0; 0082 0083 virtual void resize(intmax_t) = 0; 0084 0085 // these are used for stanard checking 0086 virtual size_type size() const = 0; 0087 virtual bool empty() const = 0; 0088 0089 virtual size_type bin_size(size_type bin) const = 0; 0090 virtual bool bin_empty(size_type bin) const = 0; 0091 0092 // these are for slower checking, default to returning normal size()/empty 0093 virtual size_type true_size() const { return size(); } 0094 virtual bool true_empty() const { return empty(); } 0095 0096 // a method of executing a specific function on all threads 0097 virtual void ExecuteOnAllThreads(ThreadPool* tp, function_type f) = 0; 0098 0099 virtual void ExecuteOnSpecificThreads(ThreadIdSet tid_set, ThreadPool* tp, 0100 function_type f) = 0; 0101 0102 intmax_t workers() const { return m_workers; } 0103 0104 virtual VUserTaskQueue* clone() = 0; 0105 0106 protected: 0107 intmax_t m_workers = 0; 0108 }; 0109 0110 } // namespace PTL
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|