Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
VTask.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// Tasking class header file
20//
21// Class Description:
22//
23// This file creates an abstract base class for the thread-pool tasking
24// system
25//
26// ---------------------------------------------------------------
27// Author: Jonathan Madsen (Feb 13th 2018)
28// ---------------------------------------------------------------
29
30#pragma once
31
32#include <cstddef>
33#include <cstdint>
34#include <functional>
35#include <thread>
36
37namespace PTL
38{
39//======================================================================================//
40
41/// \brief VTask is the abstract class stored in thread_pool
42class VTask
43{
44public:
45 using tid_type = std::thread::id;
46 using size_type = size_t;
47 using void_func_t = std::function<void()>;
48
49public:
50 VTask(bool _is_native, intmax_t _depth)
51 : m_is_native{ _is_native }
52 , m_depth{ _depth }
53 {}
54
55 VTask() = default;
56 virtual ~VTask() = default;
57
58 VTask(const VTask&) = delete;
59 VTask& operator=(const VTask&) = delete;
60
61 VTask(VTask&&) = default;
62 VTask& operator=(VTask&&) = default;
63
64public:
65 // execution operator
66 virtual void operator()() = 0;
67
68public:
69 bool is_native_task() const { return m_is_native; }
70 intmax_t depth() const { return m_depth; }
71
72protected:
73 bool m_is_native = false;
74 intmax_t m_depth = 0;
76};
77
78//======================================================================================//
79
80} // namespace PTL
VTask is the abstract class stored in thread_pool.
Definition VTask.hh:43
bool is_native_task() const
Definition VTask.hh:69
VTask & operator=(const VTask &)=delete
std::function< void()> void_func_t
Definition VTask.hh:47
VTask(VTask &&)=default
void_func_t m_func
Definition VTask.hh:75
VTask()=default
virtual ~VTask()=default
VTask & operator=(VTask &&)=default
intmax_t depth() const
Definition VTask.hh:70
VTask(bool _is_native, intmax_t _depth)
Definition VTask.hh:50
bool m_is_native
Definition VTask.hh:73
virtual void operator()()=0
intmax_t m_depth
Definition VTask.hh:74
size_t size_type
Definition VTask.hh:46
VTask(const VTask &)=delete
std::thread::id tid_type
Definition VTask.hh:45