Showing the changes to libraries/shared/src/GenericThread.cpp (1 of 12 files). Show all
Unified · Split
| @@ -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 | ||
| 20 | GenericThread::~GenericThread() { | 19 | GenericThread::~GenericThread() { |
| 21 | terminate(); | 20 | terminate(); |
| 22 | pthread_mutex_destroy(&_mutex); | ||
| 23 | } | 21 | } |
| 24 | 22 | ||
| 25 | void GenericThread::initialize(bool isThreaded) { | 23 | void GenericThread::initialize(bool isThreaded) { |
| @@ -32,30 +30,30 @@ void GenericThread::initialize(bool isThreaded) { · 6 unmodified lines | |||
| 32 | void GenericThread::terminate() { | 30 | void 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 | ||
| 40 | void* GenericThread::threadRoutine() { | 38 | void* 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 early | 41 | // 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 method | 47 | // 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 | ||
| 61 | extern "C" void* GenericThreadEntry(void* arg) { | 59 | extern "C" void* GenericThreadEntry(void* arg) { |