The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
FiberManager.h
Go to the documentation of this file.
1
2/***********************************************************************************\
3* (c) Copyright 1998-2024 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/mutex.hpp>
17#include <boost/version.hpp>
18#if ( BOOST_VERSION >= 108400 )
19# include <boost/fiber/stack_allocator_wrapper.hpp>
20#endif
33
35
36public:
42 FiberManager( int n_threads );
44
53 template <typename F>
54 void schedule( F&& func ) {
55 boost::fibers::fiber( boost::fibers::launch::post, std::forward<F>( func ) ).detach();
56 for ( auto* p : m_schedAlgoList ) { p->notify(); }
57 }
58
59private:
60 using SchedAlgo = boost::fibers::algo::shared_work;
61 boost::fibers::condition_variable m_shuttingDown_cv{};
62 boost::fibers::mutex m_shuttingDown_mtx{};
63 std::vector<std::thread> m_threads{};
64 std::vector<SchedAlgo*> m_schedAlgoList{};
65};
boost::fibers::condition_variable m_shuttingDown_cv
boost::fibers::algo::shared_work SchedAlgo
void schedule(F &&func)
Schedule work to run on the asynchronous pool.
std::vector< SchedAlgo * > m_schedAlgoList
boost::fibers::mutex m_shuttingDown_mtx
FiberManager(int n_threads)
FiberManager constructor.
std::vector< std::thread > m_threads