~registry/codeblocks/trunk

« back to all changes in this revision

Viewing changes to src/sdk/cbthreadedtask.h

  • Committer: mandrav
  • Date: 2007-02-12 14:55:28 UTC
  • Revision ID: svn-v4:98b59c6a-2706-0410-b7d6-d2fa1a1880c9:trunk:3594
* First part of directories layout re-organization: moved all sdk header files to a new dir named "include".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef CBTHREADEDTASK_H
2
 
#define CBTHREADEDTASK_H
3
 
 
4
 
/// This is what you have to use instead of wxThread to add tasks to the Thread Pool.
5
 
/// It has a reduced, but similar, interface like that of wxThread.
6
 
/// Just be sure to override Execute (like wxThread's Entry) and test every now and then
7
 
/// for TestDestroy.
8
 
class cbThreadedTask
9
 
{
10
 
  public:
11
 
    /// cbThreadedTask ctor
12
 
    cbThreadedTask();
13
 
 
14
 
    /// cbThreadedTask dtor
15
 
    virtual ~cbThreadedTask() = 0;
16
 
 
17
 
    /// This function is called to tell the task to abort (check cbThreadPool::AbortAllTasks)
18
 
    void Abort();
19
 
 
20
 
    /// Override this function with the task's job
21
 
    /// Return value doesn't matter
22
 
    virtual int Execute() = 0;
23
 
 
24
 
  protected:
25
 
    /// Be sure to call this function often. If it returns true, quit your task quickly
26
 
    bool TestDestroy() const;
27
 
 
28
 
    /// Same as TestDestroy()
29
 
    bool Aborted() const;
30
 
 
31
 
  private:
32
 
    bool m_abort;
33
 
};
34
 
 
35
 
/* ************************************************ */
36
 
/* **************** INLINE MEMBERS **************** */
37
 
/* ************************************************ */
38
 
 
39
 
inline cbThreadedTask::cbThreadedTask()
40
 
: m_abort(false)
41
 
{
42
 
  // empty
43
 
}
44
 
 
45
 
inline cbThreadedTask::~cbThreadedTask()
46
 
{
47
 
  // empty
48
 
}
49
 
 
50
 
inline bool cbThreadedTask::TestDestroy() const
51
 
{
52
 
  return m_abort;
53
 
}
54
 
 
55
 
inline bool cbThreadedTask::Aborted() const
56
 
{
57
 
  return m_abort;
58
 
}
59
 
 
60
 
inline void cbThreadedTask::Abort()
61
 
{
62
 
  m_abort = true;
63
 
}
64
 
 
65
 
#endif