History

switch from pthread mutex to QMutex

Brad Hefta-Gaub committed 12 years ago

Commit 9bc4a3d1 parent 2c30b8b12 files · +111 −131Browse files

Showing the changes to libraries/shared/src/GenericThread.cpp (1 of 12 files). Show all

Unified · Split

libraries/shared/src/GenericThread.cpp+7−9
@@ -14,12 +14,10 @@ GenericThread::GenericThread() : · 13 unmodified lines
14 _stopThread(false),14 _stopThread(false),
15 _isThreaded(false) // assume non-threaded, must call initialize()15 _isThreaded(false) // assume non-threaded, must call initialize()
16{16{
17 pthread_mutex_init(&_mutex, 0);
18}17}
19 18
20GenericThread::~GenericThread() {19GenericThread::~GenericThread() {
21 terminate();20 terminate();
22 pthread_mutex_destroy(&_mutex);
23}21}
24 22
25void GenericThread::initialize(bool isThreaded) {23void GenericThread::initialize(bool isThreaded) {
@@ -32,30 +30,30 @@ void GenericThread::initialize(bool isThreaded) { · 6 unmodified lines
32void GenericThread::terminate() {30void GenericThread::terminate() {
33 if (_isThreaded) {31 if (_isThreaded) {
34 _stopThread = true;32 _stopThread = true;
35 pthread_join(_thread, NULL); 33 pthread_join(_thread, NULL);
36 _isThreaded = false;34 _isThreaded = false;
37 }35 }
38}36}
39 37
40void* GenericThread::threadRoutine() {38void* GenericThread::threadRoutine() {
41 while (!_stopThread) {39 while (!_stopThread) {
42 40
43 // override this function to do whatever your class actually does, return false to exit thread early41 // override this function to do whatever your class actually does, return false to exit thread early
44 if (!process()) {42 if (!process()) {
45 break;43 break;
46 }44 }
47 45
48 // In non-threaded mode, this will break each time you call it so it's the 46 // In non-threaded mode, this will break each time you call it so it's the
49 // callers responsibility to continuously call this method47 // callers responsibility to continuously call this method
50 if (!_isThreaded) {48 if (!_isThreaded) {
51 break;49 break;
52 }50 }
53 }51 }
54 52
55 if (_isThreaded) {53 if (_isThreaded) {
56 pthread_exit(0); 54 pthread_exit(0);
57 }55 }
58 return NULL; 56 return NULL;
59}57}
60 58
61extern "C" void* GenericThreadEntry(void* arg) {59extern "C" void* GenericThreadEntry(void* arg) {