TPIE

2362a60
job.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
2 // vi:set ts=4 sts=4 sw=4 noet cino+=(0 :
3 // Copyright 2011, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #ifndef __TPIE_JOB_MANAGER_H__
21 #define __TPIE_JOB_MANAGER_H__
22 
26 
27 #include <stddef.h>
28 #include <condition_variable>
29 #include <tpie/types.h>
30 
31 namespace tpie {
32 
33 class job {
34 
35  enum job_state { job_idle, job_enqueued, job_running };
36 
37 public:
38 
42  job();
43 
47  virtual ~job() {}
48 
52  virtual void operator()() = 0;
53 
57  void join();
58 
62  bool is_done();
63 
69  void enqueue(job * parent = 0);
70 
76  void run();
77 
78 protected:
79 
83  virtual void on_done() {}
84 
85 private:
86 
87  size_t m_dependencies;
88  job * m_parent;
89  job_state m_state;
90 
94  std::condition_variable m_done;
95 
102  void done();
103 
107  friend class job_manager;
108 };
109 
120 memory_size_type default_worker_count();
121 
125 void init_job();
126 
130 void finish_job();
131 
132 } // namespace tpie
133 
134 #endif
job()
Default constructor.
Typesafe bitflags.
virtual ~job()
Default destructor.
Definition: job.h:47
virtual void on_done()
Called when this job and all subjobs are done.
Definition: job.h:83
bool is_done()
Return true if this job and its subjobs are done.
void finish_job()
Used by tpie_finish to deinitialize the job subsystem.
Definition: job.h:33
void run()
Run this job.
void init_job()
Used by tpie_init to initialize the job subsystem.
void join()
Wait for this job and its subjobs to complete.
memory_size_type default_worker_count()
Return the number of job threads initialized by the job framework in init_job().
virtual void operator()()=0
Called by the worker thread.
friend class job_manager
The job manager needs to invoke run() on us.
Definition: job.h:107
void enqueue(job *parent=0)
Add this job to the job pool.