Free Electron
WorkTbb.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __tbb_WorkTbb_h__
8 #define __tbb_WorkTbb_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief Execute a SpannedRange with TBB
17 
18  @ingroup tbb
19 *//***************************************************************************/
20 class FE_DL_EXPORT WorkTbb: public WorkForceI,
21  public Initialize<WorkTbb>
22 {
23  public:
24  WorkTbb(void) {}
25 virtual ~WorkTbb(void) {}
26 
27  void initialize(void);
28 
29 virtual sp<WorkI> assignment(void) { return m_spWorkI; }
30 virtual void run(sp<WorkI> a_spWorkI,U32 a_threads,
31  sp<SpannedRange> a_spSpannedRange,String a_stage);
32 virtual void stop(void) {}
33 
34 virtual BWORD threadsAlive(void) const { return 0; }
35 
36 virtual BWORD willWaitForJobs(void) const { return FALSE; }
37 virtual void waitForJobs(BWORD a_wait) {}
38 
39  private:
40 
41 
42  class Range
43  {
44  public:
45  Range(sp<SpannedRange> a_spSpannedRange,
46  I32 a_grain):
47  m_spSpannedRange(a_spSpannedRange),
48  m_grain(a_grain) {}
49 
50  Range(const Range& a_rRange):
51  m_spSpannedRange(
52  a_rRange.m_spSpannedRange),
53  m_grain(a_rRange.m_grain) {}
54 
55  Range(Range& a_rRange,tbb::split);
56 
57  ~Range() {}
58 
59  bool is_divisible(void) const
60  {
61  const I32 pieces=
62  m_spSpannedRange->atomicCount()+
63  m_spSpannedRange->nonAtomic()
64  .valueCount();
65  return (pieces>m_grain);
66  }
67 
68  bool empty(void) const
69  { return m_spSpannedRange->empty(); }
70 
71  sp<SpannedRange> spannedRange(void) const
72  { return m_spSpannedRange; }
73 
74  private:
75 
76  sp<SpannedRange> m_spSpannedRange;
77  I32 m_grain;
78  };
79 
80  class Body
81  {
82  public:
83  Body(sp<WorkI> a_spWorkI,String a_stage):
84  m_spWorkI(a_spWorkI),
85  m_stage(a_stage) {}
86 
87  Body(const Body& a_rBody):
88  m_spWorkI(a_rBody.m_spWorkI),
89  m_stage(a_rBody.m_stage) {}
90 
91  ~Body(void) {}
92 
93  void operator()(Range& a_rRange) const
94  {
95  const U32 id= -1; //* TODO
96 
97  m_spWorkI->run(id,a_rRange.spannedRange(),m_stage);
98  }
99 
100  private:
101  sp<WorkI> m_spWorkI;
102  String m_stage;
103  };
104 
105  sp<WorkI> m_spWorkI;
106 };
107 
108 } /* namespace ext */
109 } /* namespace fe */
110 
111 #endif // __tbb_WorkTbb_h__
kernel
Definition: namespace.dox:3
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
Execute a SpannedRange with TBB.
Definition: WorkTbb.h:20
Execute a Range.
Definition: WorkForceI.h:22
Automatically reference-counted string container.
Definition: String.h:128
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53