~registry/codeblocks/trunk

« back to all changes in this revision

Viewing changes to src/include/cbthreadpool_extras.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 CBTHREADPOOL_EXTRAS_H
 
2
#define CBTHREADPOOL_EXTRAS_H
 
3
 
 
4
/// Josuttis' implementation of CountedPtr
 
5
template <typename T>
 
6
class CountedPtr
 
7
{
 
8
  private:
 
9
    T *ptr;
 
10
    long *count;
 
11
 
 
12
  public:
 
13
    explicit CountedPtr(T *p = 0);
 
14
    CountedPtr(const CountedPtr<T> &p) throw();
 
15
    ~CountedPtr() throw();
 
16
    CountedPtr<T> &operator = (const CountedPtr<T> &p) throw();
 
17
    T &operator * () const throw();
 
18
    T *operator -> () const throw();
 
19
 
 
20
  private:
 
21
    void dispose();
 
22
};
 
23
 
 
24
/** A Worker Thread class.
 
25
  *
 
26
  * These are the ones that execute the tasks.
 
27
  * You shouldn't worry about it since it's for "private" purposes of the Pool.
 
28
  */
 
29
class cbWorkerThread : public wxThread
 
30
{
 
31
  public:
 
32
    /** cbWorkerThread ctor
 
33
      *
 
34
      * @param pool Thread Pool this Worker Thread belongs to
 
35
      * @param semaphore Used to synchronise the Worker Threads
 
36
      */
 
37
    cbWorkerThread(cbThreadPool *pool, CountedPtr<wxSemaphore> &semaphore);
 
38
 
 
39
    /// Entry point of this thread. The magic happens here.
 
40
    ExitCode Entry();
 
41
 
 
42
    /// Tell the thread to abort. It will also tell the task to abort (if any)
 
43
    void Abort();
 
44
 
 
45
    /** Tells whether we should abort or not
 
46
      *
 
47
      * @return true if we should abort
 
48
      */
 
49
    bool Aborted() const;
 
50
 
 
51
    /// Aborts the running task (if any)
 
52
    void AbortTask();
 
53
 
 
54
  private:
 
55
    bool m_abort;
 
56
    cbThreadPool *m_pPool;
 
57
    CountedPtr<wxSemaphore> m_semaphore;
 
58
    cbThreadedTask *m_pTask;
 
59
    wxMutex m_taskMutex;
 
60
};
 
61
 
 
62
#endif