1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* Copyright (C) 2007 - 2013 Christian Schoenebeck, Grigor Iliev * |
* Copyright (C) 2007 - 2020 Christian Schoenebeck * |
4 |
|
* Copyright (C) 2007 - 2013 Grigor Iliev * |
5 |
* * |
* * |
6 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
7 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
38 |
|
|
39 |
// Entry point for the worker thread. |
// Entry point for the worker thread. |
40 |
int WorkerThread::Main() { |
int WorkerThread::Main() { |
41 |
|
|
42 |
|
#if DEBUG |
43 |
|
Thread::setNameOfCaller("LSWorker"); |
44 |
|
#endif |
45 |
|
|
46 |
while (true) { |
while (true) { |
47 |
|
|
|
#if CONFIG_PTHREAD_TESTCANCEL |
|
48 |
TestCancel(); |
TestCancel(); |
49 |
#endif |
|
50 |
|
// prevent worker thread from being cancelled |
51 |
|
// (e.g. to prevent deadlocks while holding mutex lock(s)) |
52 |
|
pushCancelable(false); |
53 |
|
|
54 |
while (true) { |
while (true) { |
55 |
Runnable* pJob; |
Runnable* pJob; |
56 |
|
|
75 |
delete pJob; |
delete pJob; |
76 |
} |
} |
77 |
|
|
78 |
|
// now allow worker thread being cancelled again |
79 |
|
// (since all mutexes are now unlocked) |
80 |
|
popCancelable(); |
81 |
|
|
82 |
// nothing left to do, sleep until new jobs arrive |
// nothing left to do, sleep until new jobs arrive |
83 |
conditionJobsLeft.WaitIf(false); |
conditionJobsLeft.WaitIf(false); |
84 |
// reset flag |
// reset flag |