darwin: abort on pthread_attr_init fail

`pthread_attr_init` is highly unlikely to fail on macOS. Removing the
fallback behavior here to be consistent with other parts of libuv (e.g.
`src/unix/thread.c`), which simply call `abort()`.

PR-URL: https://github.com/libuv/libuv/pull/3132
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
Brandon Cheng 2021-03-13 18:36:06 -05:00 committed by Santiago Gimeno
parent 608ac2e433
commit 3e76e47304
No known key found for this signature in database
GPG Key ID: F28C3C8DA33C03BE

View File

@ -595,8 +595,7 @@ out:
static int uv__fsevents_loop_init(uv_loop_t* loop) { static int uv__fsevents_loop_init(uv_loop_t* loop) {
CFRunLoopSourceContext ctx; CFRunLoopSourceContext ctx;
uv__cf_loop_state_t* state; uv__cf_loop_state_t* state;
pthread_attr_t attr_storage; pthread_attr_t attr;
pthread_attr_t* attr;
int err; int err;
if (loop->cf_state != NULL) if (loop->cf_state != NULL)
@ -641,25 +640,19 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) {
goto fail_signal_source_create; goto fail_signal_source_create;
} }
/* In the unlikely event that pthread_attr_init() fails, create the thread if (pthread_attr_init(&attr))
* with the default stack size. We'll likely use less address space but that abort();
* in itself is not a fatal error.
*/
attr = &attr_storage;
if (pthread_attr_init(attr))
attr = NULL;
if (attr != NULL) if (pthread_attr_setstacksize(&attr, uv__thread_stack_size()))
if (pthread_attr_setstacksize(attr, uv__thread_stack_size())) abort();
abort();
loop->cf_state = state; loop->cf_state = state;
/* uv_thread_t is an alias for pthread_t. */ /* uv_thread_t is an alias for pthread_t. */
err = UV__ERR(pthread_create(&loop->cf_thread, attr, uv__cf_loop_runner, loop)); err = UV__ERR(pthread_create(&loop->cf_thread, &attr, uv__cf_loop_runner, loop));
if (attr != NULL) if (pthread_attr_destroy(&attr))
pthread_attr_destroy(attr); abort();
if (err) if (err)
goto fail_thread_create; goto fail_thread_create;