/usr/include/fox-1.6/FXThread.h is in libfox-1.6-dev 1.6.50-1+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | /********************************************************************************
* *
* M u l i t h r e a d i n g S u p p o r t *
* *
*********************************************************************************
* Copyright (C) 2004,2006 by Jeroen van der Zijp. All Rights Reserved. *
*********************************************************************************
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*********************************************************************************
* $Id: FXThread.h,v 1.40.2.2 2006/07/26 15:25:53 fox Exp $ *
********************************************************************************/
#ifndef FXTHREAD_H
#define FXTHREAD_H
namespace FX {
// Thread ID type
#ifndef WIN32
typedef unsigned long FXThreadID;
#else
typedef void* FXThreadID;
#endif
class FXCondition;
/**
* FXMutex provides a mutex which can be used to enforce critical
* sections around updates of data shared by multiple threads.
*/
class FXAPI FXMutex {
friend class FXCondition;
private:
FXuval data[24];
private:
FXMutex(const FXMutex&);
FXMutex &operator=(const FXMutex&);
public:
/// Initialize the mutex
FXMutex(FXbool recursive=FALSE);
/// Lock the mutex
void lock();
/// Return TRUE if succeeded locking the mutex
FXbool trylock();
/// Return TRUE if mutex is already locked
FXbool locked();
/// Unlock mutex
void unlock();
/// Delete the mutex
~FXMutex();
};
/**
* An easy way to establish a correspondence between a C++ scope
* and a critical section is to simply declare an FXMutexLock
* at the beginning of the scope.
* The mutex will be automatically released when the scope is
* left (either by natural means or by means of an exception.
*/
class FXAPI FXMutexLock {
private:
FXMutex& mtx;
private:
FXMutexLock();
FXMutexLock(const FXMutexLock&);
FXMutexLock& operator=(const FXMutexLock&);
public:
/// Construct & lock associated mutex
FXMutexLock(FXMutex& m):mtx(m){ lock(); }
/// Return reference to associated mutex
FXMutex& mutex(){ return mtx; }
/// Lock mutex
void lock(){ mtx.lock(); }
/// Return TRUE if succeeded locking the mutex
FXbool trylock(){ return mtx.trylock(); }
/// Return TRUE if mutex is already locked
FXbool locked(){ return mtx.locked(); }
/// Unlock mutex
void unlock(){ mtx.unlock(); }
/// Destroy and unlock associated mutex
~FXMutexLock(){ unlock(); }
};
/**
* A condition allows one or more threads to synchronize
* to an event. When a thread calls wait, the associated
* mutex is unlocked while the thread is blocked. When the
* condition becomes signaled, the associated mutex is
* locked and the thread(s) are reawakened.
*/
class FXAPI FXCondition {
private:
FXuval data[12];
private:
FXCondition(const FXCondition&);
FXCondition& operator=(const FXCondition&);
public:
/// Initialize the condition
FXCondition();
/**
* Wait until condition becomes signalled, using given mutex,
* which must already have been locked prior to this call.
*/
void wait(FXMutex& mtx);
/**
* Wait until condition becomes signalled, using given mutex,
* which must already have been locked prior to this call.
* Returns TRUE if successful, FALSE if timeout occurred.
* Note that the wait-time is specified in nanoseconds
* since the Epoch (Jan 1, 1970).
*/
FXbool wait(FXMutex& mtx,FXlong nsec);
/**
* Wake or unblock a single blocked thread
*/
void signal();
/**
* Wake or unblock all blocked threads
*/
void broadcast();
/// Delete the condition
~FXCondition();
};
/**
* A semaphore allows for protection of a resource that can
* be accessed by a fixed number of simultaneous threads.
*/
class FXAPI FXSemaphore {
private:
FXuval data[16];
private:
FXSemaphore(const FXSemaphore&);
FXSemaphore& operator=(const FXSemaphore&);
public:
/// Initialize semaphore with given count
FXSemaphore(FXint initial=1);
/// Decrement semaphore
void wait();
/// Non-blocking semaphore decrement; return true if locked
FXbool trywait();
/// Increment semaphore
void post();
/// Delete semaphore
~FXSemaphore();
};
/**
* FXThread provides system-independent support for threads.
* Subclasses must implement the run() function do implement
* the desired functionality of the thread.
* The storage of the FXThread object is to be managed by the
* calling thread, not by the thread itself.
*/
class FXAPI FXThread {
private:
volatile FXThreadID tid;
private:
FXThread(const FXThread&);
FXThread &operator=(const FXThread&);
#ifdef WIN32
static unsigned int CALLBACK execute(void*);
#else
static void* execute(void*);
#endif
protected:
/**
* All threads execute by deriving the run method of FXThread.
* If an uncaught exception was thrown, this function returns -1.
*/
virtual FXint run() = 0;
public:
/// Initialize thread object.
FXThread();
/**
* Return handle of this thread object.
* This handle is valid in the context of the thread which
* called start().
*/
FXThreadID id() const;
/**
* Return TRUE if this thread is running.
*/
FXbool running() const;
/**
* Start thread; the thread is started as attached.
* The thread is given stacksize for its stack; a value of
* zero for stacksize will give it the default stack size.
*/
FXbool start(unsigned long stacksize=0);
/**
* Suspend calling thread until thread is done.
*/
FXbool join();
/**
* Suspend calling thread until thread is done, and set code to the
* return value of run() or the argument passed into exit().
* If an exception happened in the thread, return -1.
*/
FXbool join(FXint& code);
/**
* Cancel the thread, stopping it immediately, running or not.
* If the calling thread is this thread, nothing happens.
* It is probably better to wait until it is finished, in case the
* thread currently holds mutexes.
*/
FXbool cancel();
/**
* Detach thread, so that a no join() is necessary to harvest the
* resources of this thread.
*/
FXbool detach();
/**
* Exit the calling thread.
* No destructors are invoked for objects on thread's stack;
* to invoke destructors, throw an exception instead.
*/
static void exit(FXint code=0);
/**
* Make the thread yield its time quantum.
*/
static void yield();
/**
* Return time in nanoseconds since Epoch (Jan 1, 1970).
*/
static FXlong time();
/**
* Make the calling thread sleep for a number of nanoseconds.
*/
static void sleep(FXlong nsec);
/**
* Wake at appointed time specified in nanoseconds since Epoch.
*/
static void wakeat(FXlong nsec);
/**
* Return pointer to the FXThread instance associated
* with the calling thread; it returns NULL for the main
* thread and all threads not created by FOX.
*/
static FXThread* self();
/**
* Return thread id of calling thread.
*/
static FXThreadID current();
/**
* Set thread priority.
*/
void priority(FXint prio);
/**
* Return thread priority.
*/
FXint priority();
/**
* Destroy the thread immediately, running or not.
* It is probably better to wait until it is finished, in case
* the thread currently holds mutexes.
*/
virtual ~FXThread();
};
}
#endif
|