Free Electron
WorkGang.h
Go to the documentation of this file.
1 
2 /* Copyright (C) 2003-2021 Free Electron Organization
3  Any use of this software requires a license. If a valid license
4  was not distributed with this file, visit freeelectron.org. */
5 
6 /** @file */
7 
8 #ifndef __thread_WorkGang_h__
9 #define __thread_WorkGang_h__
10 
11 namespace fe
12 {
13 namespace ext
14 {
15 
16 /**************************************************************************//**
17  @brief Execute a SpannedRange with a Gang
18 
19  @ingroup thread
20 *//***************************************************************************/
21 class FE_DL_EXPORT WorkGang: public WorkForceI,
22  public Initialize<WorkGang>
23 {
24  public:
25  WorkGang(void):
26  m_threadsAlive(0),
27  m_waitForJobs(FALSE) {}
28 virtual ~WorkGang(void);
29 
30  void initialize(void);
31 
32 virtual sp<WorkI> assignment(void) { return m_spWorkI; }
33 virtual void run(sp<WorkI> a_spWorkI,U32 a_threads,
34  sp<SpannedRange> a_spSpannedRange,String a_stage);
35 virtual void stop(void);
36 
37 virtual BWORD threadsAlive(void) const { return m_threadsAlive; }
38 
39 virtual BWORD willWaitForJobs(void) const { return m_waitForJobs; }
40 virtual void waitForJobs(BWORD a_wait) { m_waitForJobs=a_wait; }
41 
42  private:
43 
44  class Worker: public Thread::Functor
45  {
46  public:
47  Worker(sp< JobQueue< sp<SpannedRange> > > a_spJobQueue,
48  U32 a_id,String a_stage);
49  virtual ~Worker(void);
50 
51  virtual void operate(void);
52 
53  void setObject(sp<Counted> spObject)
54  { m_spWorkForceI=spObject; }
55 
56  private:
57  U32 m_id;
58  String m_stage;
59  sp< JobQueue< sp<SpannedRange> > > m_spJobQueue;
60  sp<WorkForceI> m_spWorkForceI;
61  };
62 
64 
65  sp<WorkI> m_spWorkI;
66  U32 m_threadsAlive;
67  BWORD m_waitForJobs;
68 };
69 
70 } /* namespace ext */
71 } /* namespace fe */
72 
73 #endif // __thread_WorkGang_h__
kernel
Definition: namespace.dox:3
Execute a SpannedRange with a Gang.
Definition: WorkGang.h:21
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
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
Queue of tasks.
Definition: JobQueue.h:29