The Gaudi Framework
master (9f3f8895)
Toggle main menu visibility
Loading...
Searching...
No Matches
FiberManager.h
Go to the documentation of this file.
1
2
/***********************************************************************************\
3
* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
4
* *
5
* This software is distributed under the terms of the Apache version 2 licence, *
6
* copied verbatim in the file "LICENSE". *
7
* *
8
* In applying this licence, CERN does not waive the privileges and immunities *
9
* granted to it by virtue of its status as an Intergovernmental Organization *
10
* or submit itself to any jurisdiction. *
11
\***********************************************************************************/
12
#pragma once
13
#include <boost/fiber/algo/shared_work.hpp>
14
#include <boost/fiber/condition_variable.hpp>
15
#include <boost/fiber/fiber.hpp>
16
#include <boost/fiber/fixedsize_stack.hpp>
17
#include <boost/fiber/mutex.hpp>
18
19
#include <thread>
32
33
class
FiberManager
{
34
35
public
:
47
FiberManager
(
int
n_threads, std::size_t stackSize = 16ULL * 1024 * 1024 );
48
~FiberManager
();
49
62
template
<
typename
F>
63
void
schedule
( F&& func ) {
64
// Add a new fiber invoking the function to the shared work queue, then notify the workers in case they were
65
// sleeping.
66
boost::fibers::fiber( boost::fibers::launch::post, std::allocator_arg,
StackAlloc
(
m_stackSize
),
67
std::forward<F>( func ) )
68
.detach();
69
for
(
auto
* p :
m_schedAlgoList
) { p->notify(); }
70
}
71
72
private
:
74
using
StackAlloc
= boost::fibers::fixedsize_stack;
75
using
SchedAlgo
= boost::fibers::algo::shared_work;
76
boost::fibers::condition_variable
m_shuttingDown_cv
{};
77
boost::fibers::mutex
m_shuttingDown_mtx
{};
78
std::vector<std::jthread>
m_threads
{};
79
std::vector<SchedAlgo*>
m_schedAlgoList
{};
80
82
std::size_t
m_stackSize
;
83
};
FiberManager::StackAlloc
boost::fibers::fixedsize_stack StackAlloc
Stack allocator used for fibers.
Definition
FiberManager.h:74
FiberManager::m_shuttingDown_cv
boost::fibers::condition_variable m_shuttingDown_cv
Definition
FiberManager.h:76
FiberManager::SchedAlgo
boost::fibers::algo::shared_work SchedAlgo
Definition
FiberManager.h:75
FiberManager::schedule
void schedule(F &&func)
Schedule work to run on the asynchronous pool.
Definition
FiberManager.h:63
FiberManager::m_schedAlgoList
std::vector< SchedAlgo * > m_schedAlgoList
Definition
FiberManager.h:79
FiberManager::m_shuttingDown_mtx
boost::fibers::mutex m_shuttingDown_mtx
Definition
FiberManager.h:77
FiberManager::m_stackSize
std::size_t m_stackSize
Stack size for fibers – virtual memory so this is not consume.
Definition
FiberManager.h:82
FiberManager::m_threads
std::vector< std::jthread > m_threads
Definition
FiberManager.h:78
FiberManager::FiberManager
FiberManager(int n_threads, std::size_t stackSize=16ULL *1024 *1024)
FiberManager constructor.
Definition
FiberManager.cpp:18
FiberManager::~FiberManager
~FiberManager()
Definition
FiberManager.cpp:49
GaudiHive
src
FiberManager.h
Generated on
for The Gaudi Framework by
1.17.0