"git@git.sphere.ly:matisse/android_kernel_samsung_matisse.git" did not exist on "0aa55e4d7db822059fe8132fe9f2b7773c48216c"
Commit cfa089df authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Extra logging in pthread_create.

pthread_create returns EAGAIN when it can't allocate a pthread_internal_t,
when it can't allocate a stack for the new thread, or when clone(2) fails
because there are too many threads. It's useful to be able to know why your
pthread_create just failed, so add some logging.

Bug: 8470684
Change-Id: I1bb4497d4f7528eacce0db35c2014771cba64569
parent 74b324ac
...@@ -153,6 +153,7 @@ int pthread_create(pthread_t* thread_out, pthread_attr_t const* attr, ...@@ -153,6 +153,7 @@ int pthread_create(pthread_t* thread_out, pthread_attr_t const* attr,
pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(calloc(sizeof(*thread), 1)); pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(calloc(sizeof(*thread), 1));
if (thread == NULL) { if (thread == NULL) {
__libc_format_log(ANDROID_LOG_WARN, "libc", "pthread_create failed: couldn't allocate thread");
return EAGAIN; return EAGAIN;
} }
thread->allocated_on_heap = true; thread->allocated_on_heap = true;
...@@ -172,6 +173,7 @@ int pthread_create(pthread_t* thread_out, pthread_attr_t const* attr, ...@@ -172,6 +173,7 @@ int pthread_create(pthread_t* thread_out, pthread_attr_t const* attr,
thread->attr.stack_base = __create_thread_stack(stack_size, thread->attr.guard_size); thread->attr.stack_base = __create_thread_stack(stack_size, thread->attr.guard_size);
if (thread->attr.stack_base == NULL) { if (thread->attr.stack_base == NULL) {
free(thread); free(thread);
__libc_format_log(ANDROID_LOG_WARN, "libc", "pthread_create failed: couldn't allocate %zd-byte stack", stack_size);
return EAGAIN; return EAGAIN;
} }
} else { } else {
...@@ -203,6 +205,7 @@ int pthread_create(pthread_t* thread_out, pthread_attr_t const* attr, ...@@ -203,6 +205,7 @@ int pthread_create(pthread_t* thread_out, pthread_attr_t const* attr,
munmap(thread->attr.stack_base, stack_size); munmap(thread->attr.stack_base, stack_size);
} }
free(thread); free(thread);
__libc_format_log(ANDROID_LOG_WARN, "libc", "pthread_create failed: clone failed: %s", strerror(errno));
return clone_errno; return clone_errno;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment