Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
VTask.cc
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 implementation
21//
22// Class Description:
23//
24// This file creates an abstract base class for the thread-pool tasking
25// system
26//
27// ---------------------------------------------------------------
28// Author: Jonathan Madsen (Feb 13th 2018)
29// ---------------------------------------------------------------
30
31#include "PTL/VTask.hh"
32#include "PTL/ThreadData.hh"
33#include "PTL/ThreadPool.hh"
34#include "PTL/VTaskGroup.hh"
35
36using namespace PTL;
37
38//======================================================================================//
39
41: m_depth(0)
42, m_group(nullptr)
43, m_pool(nullptr)
44{}
45
46//======================================================================================//
47
49: m_depth(0)
50, m_group(task_group)
51, m_pool((m_group) ? task_group->pool() : nullptr)
52{}
53
54//======================================================================================//
55
57: m_depth(0)
58, m_group(nullptr)
59, m_pool(tp)
60{}
61
62//======================================================================================//
63
65
66//======================================================================================//
67
68void
70{
71 if(m_group)
72 {
73 intmax_t _count = --(*m_group);
74 if(_count < 2)
75 {
76 try
77 {
78 m_group->task_cond()->notify_all();
79 } catch(std::system_error& e)
80 {
82 AutoLock l(TypeMutex<decltype(std::cerr)>(), std::defer_lock);
83 if(!l.owns_lock())
84 l.lock();
85 std::cerr << "[" << tid << "] Caught system error: " << e.what()
86 << std::endl;
87 }
88 }
89 }
90}
91
92//======================================================================================//
93
94bool
96{
97 return (m_group) ? m_group->is_native_task_group() : false;
98}
99
100//======================================================================================//
101
104{
105 return (!m_pool && m_group) ? m_group->pool() : m_pool;
106}
107
108//======================================================================================//
static uintmax_t get_this_thread_id()
Definition: ThreadPool.cc:120
virtual bool is_native_task_group() const
Definition: VTaskGroup.hh:114
ThreadPool *& pool()
Definition: VTaskGroup.hh:110
std::shared_ptr< condition_t > task_cond()
Definition: VTaskGroup.hh:103
virtual bool is_native_task() const
Definition: VTask.cc:95
VTaskGroup * m_group
Definition: VTask.hh:101
ThreadPool * m_pool
Definition: VTask.hh:102
virtual ThreadPool * pool() const
Definition: VTask.cc:103
virtual ~VTask()
Definition: VTask.cc:64
VTask()
Definition: VTask.cc:40
void operator--()
Definition: VTask.cc:69
Definition: AutoLock.hh:254
Mutex & TypeMutex(const unsigned int &_n=0)
Definition: Threading.hh:118