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,2021 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; // Handle to thread
63  volatile FXbool busy; // Thread is running
64 public:
65 
67  enum Priority {
68  PriorityError=-1,
74  PriorityMaximum
75  };
76 
78  enum Policy {
79  PolicyError=-1,
82  PolicyRoundRobin
83  };
84 
85 private:
86  FXThread(const FXThread&);
87  FXThread &operator=(const FXThread&);
88 private:
89  static void self(FXThread* t);
90 private:
91  static FXAutoThreadStorageKey selfKey;
92 private:
93 #if defined(WIN32)
94  static unsigned int CALLBACK function(void*);
95 #else
96  static void* function(void*);
97 #endif
98 public:
99 
101  FXThread();
102 
108  FXThreadID id() const;
109 
113  FXbool running() const;
114 
122  FXbool start(FXuval stacksize=0);
123 
128  FXbool join();
129 
136  FXbool join(FXint& code);
137 
146  FXbool cancel();
147 
153  FXbool detach();
154 
161  static void exit(FXint code=0);
162 
166  static void yield();
167 
171  static FXTime time();
172 
176  FXTime steadytime();
177 
181  static void sleep(FXTime nsec);
182 
186  static void wakeat(FXTime nsec);
187 
193  static FXThread* self();
194 
198  static FXThreadID current();
199 
203  static FXint processors();
204 
209  static FXint processor();
210 
214  static FXThreadStorageKey createStorageKey();
215 
219  static void deleteStorageKey(FXThreadStorageKey key);
220 
224  static void* getStorage(FXThreadStorageKey key);
225 
229  static void setStorage(FXThreadStorageKey key,void* ptr);
230 
234  FXbool priority(Priority prio);
235 
239  Priority priority() const;
240 
244  FXbool policy(Policy plcy);
245 
249  Policy policy() const;
250 
255  FXbool affinity(FXulong mask);
256 
260  FXulong affinity() const;
261 
265  FXbool description(const FXString& desc);
266 
270  FXString description() const;
271 
275  FXbool suspend();
276 
280  FXbool resume();
281 
287  virtual ~FXThread();
288  };
289 
290 }
291 
292 #endif
Minimum scheduling priority.
Definition: FXThread.h:71
Medium priority.
Definition: FXThread.h:73
Default scheduling.
Definition: FXThread.h:81
Priority
Thread priority levels.
Definition: FXThread.h:67
FXThread provides system-independent support for threads.
Definition: FXThread.h:60
Policy
Thread scheduling policies.
Definition: FXThread.h:78
Default scheduling priority.
Definition: FXThread.h:70
Definition: FX4Splitter.h:28
Failed to get priority.
Definition: FXThread.h:69
Failed to get policy.
Definition: FXThread.h:80
Automatically generated thread-local storage key.
Definition: FXAutoThreadStorageKey.h:40
Lower scheduling priority.
Definition: FXThread.h:72
FXString provides essential string manipulation capabilities in FOX.
Definition: FXString.h:42
FXRunnable represents a generic runnable thing.
Definition: FXRunnable.h:33

Copyright © 1997-2020 Jeroen van der Zijp