Geant4-11
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 "PTL/AutoLock.hh"
33#include "PTL/Globals.hh"
34#include "PTL/Threading.hh"
35
36#include <atomic>
37#include <cstddef>
38#include <cstdint>
39#include <functional>
40#include <future>
41#include <string>
42#include <thread>
43#include <tuple>
44#include <utility>
45
46namespace PTL
47{
48class ThreadPool;
49
50//======================================================================================//
51
53class VTask
54{
55public:
56 typedef std::thread::id tid_type;
57 typedef size_t size_type;
58 typedef std::function<void()> void_func_t;
59
60public:
61 VTask(bool _is_native, intmax_t _depth);
62
63 VTask() = default;
64 virtual ~VTask() = default;
65
66 VTask(const VTask&) = delete;
67 VTask& operator=(const VTask&) = delete;
68
69 VTask(VTask&&) = default;
70 VTask& operator=(VTask&&) = default;
71
72public:
73 // execution operator
74 virtual void operator()() = 0;
75
76public:
77 bool is_native_task() const { return m_is_native; }
78 intmax_t depth() const { return m_depth; }
79
80protected:
81 bool m_is_native = false;
82 intmax_t m_depth = 0;
84};
85
86//======================================================================================//
87
88} // namespace PTL
G4double(* function)(G4double)
VTask is the abstract class stored in thread_pool.
Definition: VTask.hh:54
bool is_native_task() const
Definition: VTask.hh:77
VTask & operator=(const VTask &)=delete
VTask(VTask &&)=default
void_func_t m_func
Definition: VTask.hh:83
VTask()=default
virtual ~VTask()=default
std::function< void()> void_func_t
Definition: VTask.hh:58
std::thread::id tid_type
Definition: VTask.hh:56
VTask & operator=(VTask &&)=default
intmax_t depth() const
Definition: VTask.hh:78
bool m_is_native
Definition: VTask.hh:81
size_t size_type
Definition: VTask.hh:57
virtual void operator()()=0
intmax_t m_depth
Definition: VTask.hh:82
VTask(const VTask &)=delete
Definition: AutoLock.hh:254