rocr: Handle pthread_create returning errors
Rewriting logic to fix issue where pthread_create would return errors other than EINVAL, and these errors would be ignored. Change-Id: I573958724dcf886c20e8c14e6a9182303b3ffa06
这个提交包含在:
@@ -108,17 +108,18 @@ class os_thread {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MAKE_SCOPE_GUARD([&]() {
|
||||||
|
if (pthread_attr_destroy(&attrib))
|
||||||
|
fprintf(stderr, "pthread_attr_destroy failed: %s\n", strerror(err));
|
||||||
|
});
|
||||||
|
|
||||||
if (stackSize != 0) {
|
if (stackSize != 0) {
|
||||||
stackSize = Max(uint(PTHREAD_STACK_MIN), stackSize);
|
stackSize = Max(uint(PTHREAD_STACK_MIN), stackSize);
|
||||||
stackSize = AlignUp(stackSize, 4096);
|
stackSize = AlignUp(stackSize, 4096);
|
||||||
err = pthread_attr_setstacksize(&attrib, stackSize);
|
err = pthread_attr_setstacksize(&attrib, stackSize);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
fprintf(stderr, "pthread_attr_setstacksize failed: %s\n", strerror(err));
|
fprintf(stderr, "pthread_attr_setstacksize failed: %s\n", strerror(err));
|
||||||
err = pthread_attr_destroy(&attrib);
|
return;
|
||||||
if (err != 0) {
|
|
||||||
fprintf(stderr, "pthread_attr_destroy failed: %s\n", strerror(err));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,33 +145,27 @@ class os_thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get());
|
do {
|
||||||
|
err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get());
|
||||||
|
if (!err) break;
|
||||||
|
|
||||||
// Probably a stack size error since system limits can be different from PTHREAD_STACK_MIN
|
if (err != EINVAL || stackSize == 0) {
|
||||||
// Attempt to grow the stack within reason.
|
fprintf(stderr, "pthread_create failed %d (%s)\n", errno, strerror(errno));
|
||||||
if ((err == EINVAL) && stackSize != 0) {
|
thread = 0;
|
||||||
while (stackSize < 20 * 1024 * 1024) {
|
return;
|
||||||
stackSize *= 2;
|
|
||||||
err = pthread_attr_setstacksize(&attrib, stackSize);
|
|
||||||
if (err != 0) {
|
|
||||||
fprintf(stderr, "pthread_attr_setstacksize failed: %s\n", strerror(err));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get());
|
|
||||||
if (err != EINVAL) break;
|
|
||||||
debug_print("pthread_create returned EINVAL, doubling stack size\n");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (err == 0)
|
// Probably a stack size error since system limits can be different from PTHREAD_STACK_MIN
|
||||||
args.release();
|
// Attempt to grow the stack within reason.
|
||||||
else
|
stackSize *= 2;
|
||||||
thread = 0;
|
if (pthread_attr_setstacksize(&attrib, stackSize)) {
|
||||||
|
fprintf(stderr, "pthread_attr_setstacksize failed: %s\n", strerror(err));
|
||||||
|
thread = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} while (stackSize < 20 * 1024 * 1024);
|
||||||
|
|
||||||
err = pthread_attr_destroy(&attrib);
|
args.release();
|
||||||
if (err != 0) {
|
|
||||||
fprintf(stderr, "pthread_attr_destroy failed: %s\n", strerror(err));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os_thread(os_thread&& rhs) {
|
os_thread(os_thread&& rhs) {
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户