cgma
CubitQtConcurrentApi.h
Go to the documentation of this file.
00001 
00002 
00005 #ifndef CUBIT_QT_CONCURRENT_API_H_
00006 #define CUBIT_QT_CONCURRENT_API_H_
00007 
00008 #include "CubitConcurrentApi.h"
00009 #include "CGMUtilConfigure.h"
00010 #include <QMutex>
00011 #include <QMap>
00012 #include <QFuture>
00013 
00014 
00015 // class to provide a way to run tasks concurrently
00016 class CUBIT_UTIL_EXPORT CubitQtConcurrent : public CubitConcurrent
00017 {
00018 public:
00019   CubitQtConcurrent();
00020   virtual ~CubitQtConcurrent();
00021   
00022   const std::string& get_name() const;
00023   const char* get_type() const;
00024 
00025   //Mutex* create_mutex();
00026   //void destroy_mutex(Mutex* m);
00027 
00028   ThreadLocalStorageInterface* create_local_storage(void (*cleanup_function)(void*));
00029   void destroy_local_storage(ThreadLocalStorageInterface* i);
00030 
00031   // wait for a task to finish
00032   virtual void wait(Task* task);
00033 
00034   // wait for a task to finish, but do not take on the task if the thread pool hasn't taken it yet
00035   virtual void idle_wait(Task* task);
00036 
00037   // wait for a set of tasks to finish
00038   virtual void wait(const std::vector<Task*>& task);
00039 
00040   //wait for any of a set of tasks to finish
00041   void wait_for_any(const std::vector<Task*>& tasks,std::vector<Task*>& finished_tasks);
00042 
00043   // return whether a task is complete
00044   virtual bool is_completed(Task* task);
00045   
00046   // return whether a task is currently running (as opposed to waiting in the queue)
00047   virtual bool is_running(Task* task);
00048   
00049   // wait for a task group to complete
00050   virtual void wait(TaskGroup* task_group);
00051   
00052   // return whether a task group is complete
00053   virtual bool is_completed(TaskGroup* task_group);
00054   
00055   // return whether a task group is currently running (as opposed to waiting in the queue)
00056   virtual bool is_running(TaskGroup* task_group);
00057  
00058   // cancel a task group's execution
00059   // this only un-queues tasks that haven't started, and running tasks will run to completion
00060   // after canceling a task group, one still needs to call wait() for completion.
00061   virtual void cancel(TaskGroup* task_group);
00062   
00063 
00064 protected: 
00065   // schedule a task for execution
00066   virtual void schedule(Task* task);
00067   
00068   // schedule a group of tasks for execution
00069   virtual void schedule(TaskGroup* task_group);
00070   
00071   static void execute(Task* t);
00072   
00073   QMap<TaskGroup*, QFuture<void> > taskgroupmap;
00074   QMutex m2;
00075 
00076   QMap<Task*, QFuture<void> > taskmap;
00077   QMutex m;
00078   
00079   std::string _name;
00080 };
00081 
00082 
00083 #endif // CUBIT_QT_CONCURRENT_API_H_
00084 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines