CMS 3D CMS Logo

include_first_syncWait.h
Go to the documentation of this file.
1 #ifndef FWCore_Concurrency_syncWait_h
2 #define FWCore_Concurrency_syncWait_h
3 //
4 // syncWait.h
5 //
6 // This file must be included before any other file that include tbb headers
7 //
8 // Created by Chris Jones on 2/24/21.
9 //
11 #include "tbb/task_group.h"
12 #include "tbb/task.h"
13 #include <exception>
14 
15 namespace edm {
16  template <typename F>
17  [[nodiscard]] std::exception_ptr syncWait(F&& iFunc) {
18  std::exception_ptr exceptPtr{};
19  //tbb::task::suspend can only be run from within a task running in this arena. For 1 thread,
20  // it is often (always?) the case where not such task is being run here. Therefore we need
21  // to use a temp task_group to start up such a task.
22  tbb::task_group group;
23  group.run([&]() {
24  tbb::task::suspend([&](tbb::task::suspend_point tag) {
25  auto waitTask = make_waiting_task([tag, &exceptPtr](std::exception_ptr const* iExcept) {
26  if (iExcept) {
27  exceptPtr = *iExcept;
28  }
29  tbb::task::resume(tag);
30  });
31  iFunc(WaitingTaskHolder(group, waitTask));
32  }); //suspend
33  }); //group.run
34 
35  group.wait();
36  return exceptPtr;
37  }
38 } // namespace edm
39 #endif /* FWCore_Concurrency_syncWait_h */
WaitingTaskHolder.h
edm
HLT enums.
Definition: AlignableModifier.h:19
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
edm::make_waiting_task
FunctorWaitingTask< F > * make_waiting_task(F f)
Definition: WaitingTask.h:101
edm::WaitingTaskHolder
Definition: WaitingTaskHolder.h:32
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
edm::syncWait
std::exception_ptr syncWait(F &&iFunc)
Definition: include_first_syncWait.h:17
watchdog.group
group
Definition: watchdog.py:82