All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WorkItem.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Tasks.h"
7 
8 namespace Eegeo
9 {
10  namespace Concurrency
11  {
12  namespace Tasks
13  {
14  class WorkItem : protected Eegeo::NonCopyable
15  {
16  public:
17  WorkItem(bool deleteAfterFinalize=true);
18  virtual ~WorkItem() {}
19  void Work();
20  void FinaliseOnMainThread();
21  void WorkCancelled();
22 
23  bool IsComplete() const;
24  bool IsFinalised() const;
25  bool IsCancelled();
26  bool ShouldDeleteAfterFinalize() const;
27  void Cancel();
28  virtual bool RequiresGlContext() const { return true; }
29 
30  const Priority::Values GetPriority() const { return m_priority; }
31 
32  protected:
33  virtual void DoWork() = 0;
34  virtual void DoFinalizeOnMainThread() = 0;
35  virtual void DoWorkCancelled() { };
36  virtual void SetPriority(Priority::Values priority) { m_priority = priority; }
37 
38  private:
39  bool m_complete;
40  bool m_finalized;
41  bool m_deleteAfterFinalize;
42  Priority::Values m_priority;
43  volatile s32 m_cancelled;
44  };
45  }
46  }
47 }
48 
49