Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
ThreadData.hh
Go to the documentation of this file.
1//
2// MIT License
3// Copyright (c) 2020 Jonathan R. Madsen
4// Permission is hereby granted, free of charge, to any person obtaining a copy
5// of this software and associated documentation files (the "Software"), to deal
6// in the Software without restriction, including without limitation the rights
7// to use, copy, modify, merge, publish, distribute, sublicense, and
8// copies of the Software, and to permit persons to whom the Software is
9// furnished to do so, subject to the following conditions:
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
12// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
13// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
15// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
17// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18//
19// ---------------------------------------------------------------
20// Tasking class header
21// Class Description:
22// ---------------------------------------------------------------
23// Author: Jonathan Madsen
24// ---------------------------------------------------------------
25
26#pragma once
27
28#include <cstddef>
29#include <cstdint>
30#include <deque>
31
32#if defined(PTL_USE_TBB)
33# include <tbb/global_control.h>
34# include <tbb/task_group.h>
35# include <tbb/task_scheduler_init.h>
36#endif
37
38namespace PTL
39{
40//--------------------------------------------------------------------------------------//
41
42#if defined(PTL_USE_TBB)
43
44using tbb_global_control_t = ::tbb::global_control;
45using tbb_task_group_t = ::tbb::task_group;
46#else
47
48namespace tbb
49{
51{
52public:
53 // dummy constructor
55 // dummy wait
56 inline void wait() {}
57 // run function
58 template <typename FuncT>
59 inline void run(FuncT f)
60 {
61 f();
62 }
63 // run and wait
64 template <typename FuncT>
65 inline void run_and_wait(FuncT f)
66 {
67 f();
68 }
69};
70
72{
73public:
75 {
78 };
79
80 global_control(parameter p, size_t value);
82 static size_t active_value(parameter param);
83};
84
85} // namespace tbb
86
89
90#endif
91
92//--------------------------------------------------------------------------------------//
93
94class ThreadPool;
95class VUserTaskQueue;
96
97//--------------------------------------------------------------------------------------//
98
100{
101public:
102 template <typename Tp>
103 using TaskStack = std::deque<Tp>;
104
106 ~ThreadData();
107
108 void update();
109
110public:
113 intmax_t task_depth;
117
118public:
119 // Public functions
120 static ThreadData*& GetInstance();
121};
122
123//--------------------------------------------------------------------------------------//
124
125} // namespace PTL
static ThreadData *& GetInstance()
Definition: ThreadData.cc:35
VUserTaskQueue * current_queue
Definition: ThreadData.hh:115
std::deque< Tp > TaskStack
Definition: ThreadData.hh:103
TaskStack< VUserTaskQueue * > queue_stack
Definition: ThreadData.hh:116
ThreadPool * thread_pool
Definition: ThreadData.hh:114
intmax_t task_depth
Definition: ThreadData.hh:113
global_control(parameter p, size_t value)
static size_t active_value(parameter param)
void run_and_wait(FuncT f)
Definition: ThreadData.hh:65
void run(FuncT f)
Definition: ThreadData.hh:59
Definition: AutoLock.hh:254
tbb::task_group tbb_task_group_t
Definition: ThreadData.hh:88
tbb::global_control tbb_global_control_t
Definition: ThreadData.hh:87