Fix type of android_thread_func typedef

Found the error with latest clang: https://android-build.corp.google.com/artifact/pending/P80448506/art-host-x86_64/latest/view/logs%2Fbuild_error.log

```
out/soong/.intermediates/system/core/libutils/libutils/linux_glibc_x86_64_static/obj/system/core/libutils/Threads.o system/core/libutils/Threads.cpp
system/core/libutils/Threads.cpp:149:21: error: cast from 'android_thread_func_t' (aka 'int (*)(void *)') to 'android_pthread_entry' (aka 'void *(*)(void *)') converts to incompatible function type [-Werror,-Wcast-function-type-mismatch]
  149 |                     (android_pthread_entry)entryFunction, userData);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```

Change-Id: Ie2423a568483c975a36a1fa0b06a3f93a27be5aa
This commit is contained in:
Aditya Kumar 2024-09-05 14:03:59 -07:00
parent f62078fa17
commit be2cc9f930

View file

@ -60,7 +60,7 @@ using namespace android;
* We create it "detached", so it cleans up after itself.
*/
typedef void* (*android_pthread_entry)(void*);
typedef int (*android_pthread_entry)(void*);
#if defined(__ANDROID__)
struct thread_data_t {
@ -88,6 +88,20 @@ struct thread_data_t {
};
#endif
// Adapted from bionic's implmenetation of trampoline to make C11 thrd_create
// work with pthread_create.
struct libutil_thread_data {
android_pthread_entry _Nonnull entry_func;
void* _Nullable entry_func_arg;
};
static void* _Nonnull libutil_thread_trampoline(void* _Nonnull arg) {
libutil_thread_data *data_ptr = static_cast<libutil_thread_data*>(arg);
int result = data_ptr->entry_func(data_ptr->entry_func_arg);
delete data_ptr;
return reinterpret_cast<void*>(static_cast<uintptr_t>(result));
}
void androidSetThreadName(const char* name) {
#if defined(__linux__)
// Mac OS doesn't have this, and we build libutil for the host too
@ -145,8 +159,13 @@ int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
errno = 0;
pthread_t thread;
libutil_thread_data* pthread_arg = new libutil_thread_data;
pthread_arg->entry_func = entryFunction;
pthread_arg->entry_func_arg = userData;
int result = pthread_create(&thread, &attr,
(android_pthread_entry)entryFunction, userData);
libutil_thread_trampoline, pthread_arg);
pthread_attr_destroy(&attr);
if (result != 0) {
ALOGE("androidCreateRawThreadEtc failed (entry=%p, res=%d, %s)\n"