3 This file is a part of the JThread package, which contains some object-
4 oriented thread wrappers for different thread implementations.
6 Copyright (c) 2000-2006 Jori Liesenborgs (jori.liesenborgs@gmail.com)
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 and/or sell copies of the Software, and to permit persons to whom the
13 Software is furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
31 #if __cplusplus >= 201103L
35 #include "jthread/jmutex.h"
37 #define ERR_JTHREAD_CANTINITMUTEX -1
38 #define ERR_JTHREAD_CANTSTARTTHREAD -2
39 #define ERR_JTHREAD_THREADFUNCNOTSET -3
40 #define ERR_JTHREAD_NOTRUNNING -4
41 #define ERR_JTHREAD_ALREADYRUNNING -5
50 { requeststop = true; }
52 virtual void *Thread() = 0;
53 inline bool IsRunning()
55 inline bool StopRequested()
56 { return requeststop; }
57 void *GetReturnValue();
61 * Wait for thread to finish
62 * Note: this does not stop a thread you have to do this on your own
63 * WARNING: never ever call this on a thread not started or already killed!
70 #if (defined(WIN32) || defined(_WIN32_WCE))
73 static DWORD WINAPI TheThread(void *param);
75 static UINT __stdcall TheThread(void *param);
79 #else // pthread type threads
80 static void *TheThread(void *param);
85 * reading and writing bool values is atomic on all relevant architectures
86 * ( x86 + arm ). No need to waste time for locking here.
87 * once C++11 is supported we can tell compiler to handle cpu caches correct
88 * too. This should cause additional improvement (and silence thread
89 * concurrency check tools.
91 #if __cplusplus >= 201103L
92 std::atomic_bool started;
99 * reading and writing bool values is atomic on all relevant architectures
100 * ( x86 + arm ). No need to waste time for locking here.
101 * once C++11 is supported we can tell compiler to handle cpu caches correct
102 * too. This should cause additional improvement (and silence thread
103 * concurrency check tools.
105 #if __cplusplus >= 201103L
106 std::atomic_bool running;
107 std::atomic_bool requeststop;
113 JMutex continuemutex,continuemutex2;