mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-23 21:15:11 +00:00
workPool: handle thread init failures
This commit is contained in:
parent
1a520dbf3e
commit
157f3be253
2 changed files with 20 additions and 4 deletions
|
@ -100,9 +100,16 @@ void DivWorkThread::finish() {
|
||||||
thread->join();
|
thread->join();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivWorkThread::init(DivWorkPool* p) {
|
bool DivWorkThread::init(DivWorkPool* p) {
|
||||||
parent=p;
|
parent=p;
|
||||||
|
try {
|
||||||
thread=new std::thread(_workThread,this);
|
thread=new std::thread(_workThread,this);
|
||||||
|
} catch (std::system_error& e) {
|
||||||
|
logE("could not start thread! %s",e.what());
|
||||||
|
thread=NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivWorkPool::push(void (*what)(void*), void* arg) {
|
void DivWorkPool::push(void (*what)(void*), void* arg) {
|
||||||
|
@ -171,7 +178,16 @@ DivWorkPool::DivWorkPool(unsigned int threads):
|
||||||
if (threaded) {
|
if (threaded) {
|
||||||
workThreads=new DivWorkThread[threads];
|
workThreads=new DivWorkThread[threads];
|
||||||
for (unsigned int i=0; i<count; i++) {
|
for (unsigned int i=0; i<count; i++) {
|
||||||
workThreads[i].init(this);
|
if (!workThreads[i].init(this)) {
|
||||||
|
count=i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count<=0) {
|
||||||
|
logE("DivWorkPool: couldn't start any threads! falling back to non-threaded mode.");
|
||||||
|
delete[] workThreads;
|
||||||
|
threaded=false;
|
||||||
|
workThreads=NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
workThreads=NULL;
|
workThreads=NULL;
|
||||||
|
|
|
@ -57,7 +57,7 @@ struct DivWorkThread {
|
||||||
bool busy();
|
bool busy();
|
||||||
void finish();
|
void finish();
|
||||||
|
|
||||||
void init(DivWorkPool* p);
|
bool init(DivWorkPool* p);
|
||||||
DivWorkThread():
|
DivWorkThread():
|
||||||
parent(NULL),
|
parent(NULL),
|
||||||
isBusy(false),
|
isBusy(false),
|
||||||
|
|
Loading…
Reference in a new issue