The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
FiberManager.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11
12#include "FiberManager.h"
13
15 m_schedAlgoList.resize( n_threads + 1 );
16 auto* main_algo_ptr = new SchedAlgo( true );
17 m_schedAlgoList.at( n_threads ) = main_algo_ptr;
18#if ( BOOST_VERSION >= 108400 )
19 boost::fibers::initialize_thread( main_algo_ptr,
20 boost::fibers::make_stack_allocator_wrapper<boost::fibers::default_stack>() );
21#else
22 boost::fibers::context::active()->get_scheduler()->set_algo( main_algo_ptr );
23#endif
24
25 for ( int i = 0; i < n_threads; ++i ) {
26 m_threads.emplace_back( std::thread( [this, i]() {
27 auto* algo_ptr = new SchedAlgo( true );
28 m_schedAlgoList.at( i ) = algo_ptr;
29#if ( BOOST_VERSION >= 108400 )
30 boost::fibers::initialize_thread( algo_ptr,
31 boost::fibers::make_stack_allocator_wrapper<boost::fibers::default_stack>() );
32#else
33 boost::fibers::context::active()->get_scheduler()->set_algo( algo_ptr );
34#endif
35 std::unique_lock lck{ m_shuttingDown_mtx };
36 m_shuttingDown_cv.wait( lck );
37 } ) );
38 }
39}
40
42 m_shuttingDown_cv.notify_all();
43 for ( std::thread& t : m_threads ) { t.join(); }
44}
boost::fibers::condition_variable m_shuttingDown_cv
boost::fibers::algo::shared_work SchedAlgo
std::vector< SchedAlgo * > m_schedAlgoList
boost::fibers::mutex m_shuttingDown_mtx
FiberManager(int n_threads)
FiberManager constructor.
std::vector< std::thread > m_threads