1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! \file CubitQtConcurrentApi.h
/*! \brief Api for concurrency based on Qt
 */ 

#ifndef CUBIT_QT_CONCURRENT_API_H_
#define CUBIT_QT_CONCURRENT_API_H_

#include "CubitConcurrentApi.h"
#include "CGMUtilConfigure.h"
#include <QMutex>
#include <QMap>
#include <QFuture>


// class to provide a way to run tasks concurrently
class CUBIT_UTIL_EXPORT CubitQtConcurrent : public CubitConcurrent
{
public:
  CubitQtConcurrent();
  virtual ~CubitQtConcurrent();
  
  const std::string& get_name() const;
  const char* get_type() const;

  //Mutex* create_mutex();
  //void destroy_mutex(Mutex* m);

  ThreadLocalStorageInterface* create_local_storage(void (*cleanup_function)(void*));<--- Function in derived class<--- Function in derived class
  void destroy_local_storage(ThreadLocalStorageInterface* i);<--- Function in derived class<--- Function in derived class

  // wait for a task to finish
  virtual void wait(Task* task);<--- Function in derived class<--- Function in derived class

  // wait for a task to finish, but do not take on the task if the thread pool hasn't taken it yet
  virtual void idle_wait(Task* task);<--- Function in derived class<--- Function in derived class

  // wait for a set of tasks to finish
  virtual void wait(const std::vector<Task*>& task);<--- Function in derived class<--- Function in derived class

  //wait for any of a set of tasks to finish
  void wait_for_any(const std::vector<Task*>& tasks,std::vector<Task*>& finished_tasks);<--- Function in derived class<--- Function in derived class

  // return whether a task is complete
  virtual bool is_completed(Task* task);<--- Function in derived class<--- Function in derived class
  
  // return whether a task is currently running (as opposed to waiting in the queue)
  virtual bool is_running(Task* task);<--- Function in derived class<--- Function in derived class
  
  // wait for a task group to complete
  virtual void wait(TaskGroup* task_group);<--- Function in derived class<--- Function in derived class
  
  // return whether a task group is complete
  virtual bool is_completed(TaskGroup* task_group);<--- Function in derived class<--- Function in derived class
  
  // return whether a task group is currently running (as opposed to waiting in the queue)
  virtual bool is_running(TaskGroup* task_group);<--- Function in derived class<--- Function in derived class
 
  // cancel a task group's execution
  // this only un-queues tasks that haven't started, and running tasks will run to completion
  // after canceling a task group, one still needs to call wait() for completion.
  virtual void cancel(TaskGroup* task_group);<--- Function in derived class<--- Function in derived class
  

protected: 
  // schedule a task for execution
  virtual void schedule(Task* task);<--- Function in derived class<--- Function in derived class
  
  // schedule a group of tasks for execution
  virtual void schedule(TaskGroup* task_group);<--- Function in derived class<--- Function in derived class
  
  static void execute(Task* t);
  
  QMap<TaskGroup*, QFuture<void> > taskgroupmap;
  QMutex m2;

  QMap<Task*, QFuture<void> > taskmap;
  QMutex m;
  
  std::string _name;
};


#endif // CUBIT_QT_CONCURRENT_API_H_