commore  1.0.6-SNAPSHOT
All Classes Namespaces Functions Variables Typedefs Enumerations Pages
Thread.h
1 //
2 // Copyright (c) 2006-2014 Raphael David / CANTOR
3 //
4 
5 #ifndef CMR_THREAD_INCLUDED
6 #define CMR_THREAD_INCLUDED
7 
8 #include "commore/Commore.h"
9 #include "commore/AutoRef.h"
10 
11 
12 namespace commore
13 {
14  class ThreadItem;
18  class CMREXD Thread
19  {
20  public:
21  struct Impl;
22  public:
23  Thread() : impl_(0) {}
24  virtual ~Thread();
25 
26  public:
30  bool start();
34  bool request_stop();
39  bool stop();
40 
44  bool is_to_stop();
45 
50  bool is_stopped();
55  bool is_running();
56 
57 
65  virtual void run();
66 
72  bool wait(TimePeriod timeout);
73 
77  bool trigger();
78 
85  virtual void run_item();
86 
87  private:
88  Impl* impl_;
89 
90 
91  };
92 
96  class CMREXD Event
97  {
98  public:
102  Event(bool create = true);
107  Event(const AChar* name);
108  ~Event();
109 
110  public:
117  bool create(const AChar* name = 0);
121  bool is_valid();
127  bool wait(const TimePeriod& timeout);
132  bool wait();
136  void signal();
140  void reset();
141 
146  void* get() const { return event_; }
147 
148  private:
149  Event(const Event&);
150  Event& operator = (const Event&);
151 
152  private:
153  void* event_;
154  };
155 
156 
161  class CMREXD ThreadContext
162  {
163  public:
164  ThreadContext();
165  ~ThreadContext();
166 
167  public:
172  void* get_value();
178  bool set_value(void* v);
179 
180  private:
181  unsigned long tls_;
182  //
183  // Ensure false at static init
184  //
185  bool is_valid_;
186  public:
190  bool is_valid() const;
194  bool isValid() const;
198  bool is_used() const;
202  bool isUsed() const;
203  };
204 };
205 
206 #endif
207 
Definition: Time.h:21
Definition: Thread.h:18
Definition: Thread.h:96
Definition: Thread.h:161