//! \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_