Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXTaskGroup.h
1 /********************************************************************************
2 * *
3 * T a s k G r o u p C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2012,2022 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXTASKGROUP_H
22 #define FXTASKGROUP_H
23 
24 namespace FX {
25 
26 
27 class FXThreadPool;
28 
29 
48 class FXAPI FXTaskGroup {
49 private:
50  class Task : public FXRunnable {
51  private:
52  FXTaskGroup *taskgroup; // Backlink to taskgroup
53  FXRunnable *runnable; // Wrapped runnable
54  private:
55  Task(const Task&);
56  Task &operator=(const Task&);
57  public:
58  Task(FXTaskGroup* g,FXRunnable *r);
59  virtual FXint run();
60  virtual ~Task();
61  };
62 private:
63  FXThreadPool *threadpool; // Thread pool used by task group
64  FXCompletion completion; // Completion counter
65 private:
66  FXTaskGroup(const FXTaskGroup&);
67  FXTaskGroup &operator=(const FXTaskGroup&);
68 public:
69 
74  FXTaskGroup();
75 
80 
84  FXThreadPool* getThreadPool() const { return threadpool; }
85 
89  FXuint getRunningTasks() const { return completion.count(); }
90 
94  FXbool execute(FXRunnable* task);
95 
101  FXbool executeAndWait(FXRunnable* task);
102 
108  FXbool wait();
109 
113  virtual ~FXTaskGroup();
114  };
115 
116 }
117 
118 #endif
FXThreadPool * getThreadPool() const
Return threadpool.
Definition: FXTaskGroup.h:84
An FXTaskGroup manages a number of tasks, executing on the associated FXThreadPool.
Definition: FXTaskGroup.h:48
FXuint getRunningTasks() const
Return number of tasks.
Definition: FXTaskGroup.h:89
Definition: FX4Splitter.h:28
A completion counter allows a single thread to monitor a number of ongoing concurrent activities for ...
Definition: FXCompletion.h:41
FXuint count() const
Return current counter value.
Definition: FXCompletion.h:54
FXRunnable represents a generic runnable thing.
Definition: FXRunnable.h:33
A Thread Pool manages execution of tasks on a number of worker-threads.
Definition: FXThreadPool.h:68

Copyright © 1997-2022 Jeroen van der Zijp