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,2024 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 void pause();
172 
176  static FXTime time();
177 
181  static FXTime steadytime();
182 
186  static FXTime ticks();
187 
191  static void sleep(FXTime nsec);
192 
196  static void wakeat(FXTime nsec);
197 
203  static FXThread* self();
204 
208  static FXThreadID current();
209 
213  static FXint processors();
214 
219  static FXint processor();
220 
224  static FXThreadStorageKey createStorageKey();
225 
229  static void deleteStorageKey(FXThreadStorageKey key);
230 
234  static void* getStorage(FXThreadStorageKey key);
235 
239  static void setStorage(FXThreadStorageKey key,void* ptr);
240 
244  FXbool priority(Priority prio);
245 
249  Priority priority() const;
250 
254  FXbool policy(Policy plcy);
255 
259  Policy policy() const;
260 
265  FXbool affinity(FXulong mask);
266 
270  FXulong affinity() const;
271 
275  FXbool description(const FXString& desc);
276 
280  FXString description() const;
281 
285  FXbool suspend();
286 
290  FXbool resume();
291 
297  virtual ~FXThread();
298  };
299 
300 }
301 
302 #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-2022 Jeroen van der Zijp