Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXThread.h
1 /********************************************************************************
2 * *
3 * T h r e a d S u p p o r t *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2004,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXTHREAD_H
22 #define FXTHREAD_H
23 
24 #ifndef FXRUNNABLE_H
25 #include "FXRunnable.h"
26 #endif
27 
28 namespace FX {
29 
30 
60 class FXAPI FXThread : public FXRunnable {
61 private:
62  volatile FXThreadID tid;
63  volatile FXbool busy;
64 private:
65  static FXAutoThreadStorageKey selfKey;
66 private:
67  FXThread(const FXThread&);
68  FXThread &operator=(const FXThread&);
69 #if defined(WIN32)
70  static unsigned int CALLBACK function(void*);
71 #else
72  static void* function(void*);
73 #endif
74 protected:
75  static void self(FXThread* t);
76 public:
77 
79  enum Priority {
80  PriorityError=-1,
86  PriorityMaximum
87  };
88 
90  enum Policy {
91  PolicyError=-1,
94  PolicyRoundRobin
95  };
96 
97 public:
98 
100  FXThread();
101 
107  FXThreadID id() const;
108 
112  FXbool running() const;
113 
121  FXbool start(FXuval stacksize=0);
122 
127  FXbool join();
128 
135  FXbool join(FXint& code);
136 
145  FXbool cancel();
146 
152  FXbool detach();
153 
160  static void exit(FXint code=0);
161 
165  static void yield();
166 
170  static FXTime time();
171 
175  static void sleep(FXTime nsec);
176 
180  static void wakeat(FXTime nsec);
181 
187  static FXThread* self();
188 
192  static FXThreadID current();
193 
197  static FXint processors();
198 
203  static FXint processor();
204 
208  static FXThreadStorageKey createStorageKey();
209 
213  static void deleteStorageKey(FXThreadStorageKey key);
214 
218  static void* getStorage(FXThreadStorageKey key);
219 
223  static void setStorage(FXThreadStorageKey key,void* ptr);
224 
228  FXbool priority(Priority prio);
229 
233  Priority priority() const;
234 
238  FXbool policy(Policy plcy);
239 
243  Policy policy() const;
244 
249  FXbool affinity(FXulong mask);
250 
254  FXulong affinity() const;
255 
259  FXbool suspend();
260 
264  FXbool resume();
265 
271  virtual ~FXThread();
272  };
273 
274 }
275 
276 #endif

Copyright © 1997-2016 Jeroen van der Zijp