~ubuntu-branches/ubuntu/oneiric/codeblocks/oneiric

« back to all changes in this revision

Viewing changes to src/include/cbthreadedtask.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

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