diff options
Diffstat (limited to 'media/libaom/src/aom_util/aom_thread.c')
-rw-r--r-- | media/libaom/src/aom_util/aom_thread.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/media/libaom/src/aom_util/aom_thread.c b/media/libaom/src/aom_util/aom_thread.c index cae9f5e250..a749a22401 100644 --- a/media/libaom/src/aom_util/aom_thread.c +++ b/media/libaom/src/aom_util/aom_thread.c @@ -14,6 +14,12 @@ // Original source: // https://chromium.googlesource.com/webm/libwebp +// Enable GNU extensions in glibc so that we can call pthread_setname_np(). +// This must be before any #include statements. +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #include <assert.h> #include <string.h> // for memset() @@ -34,6 +40,28 @@ static void execute(AVxWorker *const worker); // Forward declaration. static THREADFN thread_loop(void *ptr) { AVxWorker *const worker = (AVxWorker *)ptr; +#ifdef __APPLE__ + if (worker->thread_name != NULL) { + // Apple's version of pthread_setname_np takes one argument and operates on + // the current thread only. The maximum size of the thread_name buffer was + // noted in the Chromium source code and was confirmed by experiments. If + // thread_name is too long, pthread_setname_np returns -1 with errno + // ENAMETOOLONG (63). + char thread_name[64]; + strncpy(thread_name, worker->thread_name, sizeof(thread_name) - 1); + thread_name[sizeof(thread_name) - 1] = '\0'; + pthread_setname_np(thread_name); + } +#elif defined(__GLIBC__) || defined(__BIONIC__) + if (worker->thread_name != NULL) { + // Linux and Android require names (with nul) fit in 16 chars, otherwise + // pthread_setname_np() returns ERANGE (34). + char thread_name[16]; + strncpy(thread_name, worker->thread_name, sizeof(thread_name) - 1); + thread_name[sizeof(thread_name) - 1] = '\0'; + pthread_setname_np(pthread_self(), thread_name); + } +#endif int done = 0; while (!done) { pthread_mutex_lock(&worker->impl_->mutex_); |