Migrate pthread to std::thread
Bug: 341997808 Test: atest --host libutils_test Change-Id: I4f435d5d85efcbcc351b7620811c172badc2276d
This commit is contained in:
parent
2d4d60cccb
commit
d41c0f4a9e
4 changed files with 3 additions and 84 deletions
|
|
@ -70,8 +70,7 @@ int SimpleLooperCallback::handleEvent(int fd, int events, void* data) {
|
|||
// Maximum number of file descriptors for which to retrieve poll events each iteration.
|
||||
static const int EPOLL_MAX_EVENTS = 16;
|
||||
|
||||
static pthread_once_t gTLSOnce = PTHREAD_ONCE_INIT;
|
||||
static pthread_key_t gTLSKey = 0;
|
||||
thread_local static sp<Looper> gThreadLocalLooper;
|
||||
|
||||
Looper::Looper(bool allowNonCallbacks)
|
||||
: mAllowNonCallbacks(allowNonCallbacks),
|
||||
|
|
@ -91,38 +90,12 @@ Looper::Looper(bool allowNonCallbacks)
|
|||
Looper::~Looper() {
|
||||
}
|
||||
|
||||
void Looper::initTLSKey() {
|
||||
int error = pthread_key_create(&gTLSKey, threadDestructor);
|
||||
LOG_ALWAYS_FATAL_IF(error != 0, "Could not allocate TLS key: %s", strerror(error));
|
||||
}
|
||||
|
||||
void Looper::threadDestructor(void *st) {
|
||||
Looper* const self = static_cast<Looper*>(st);
|
||||
if (self != nullptr) {
|
||||
self->decStrong((void*)threadDestructor);
|
||||
}
|
||||
}
|
||||
|
||||
void Looper::setForThread(const sp<Looper>& looper) {
|
||||
sp<Looper> old = getForThread(); // also has side-effect of initializing TLS
|
||||
|
||||
if (looper != nullptr) {
|
||||
looper->incStrong((void*)threadDestructor);
|
||||
}
|
||||
|
||||
pthread_setspecific(gTLSKey, looper.get());
|
||||
|
||||
if (old != nullptr) {
|
||||
old->decStrong((void*)threadDestructor);
|
||||
}
|
||||
gThreadLocalLooper = looper;
|
||||
}
|
||||
|
||||
sp<Looper> Looper::getForThread() {
|
||||
int result = pthread_once(& gTLSOnce, initTLSKey);
|
||||
LOG_ALWAYS_FATAL_IF(result != 0, "pthread_once failed");
|
||||
|
||||
Looper* looper = (Looper*)pthread_getspecific(gTLSKey);
|
||||
return sp<Looper>::fromExisting(looper);
|
||||
return gThreadLocalLooper;
|
||||
}
|
||||
|
||||
sp<Looper> Looper::prepare(int opts) {
|
||||
|
|
|
|||
|
|
@ -509,9 +509,6 @@
|
|||
{
|
||||
"name" : "_ZN7android47LightRefBase_reportIncStrongRequireStrongFailedEPKv"
|
||||
},
|
||||
{
|
||||
"name" : "_ZN7android6Looper10initTLSKeyEv"
|
||||
},
|
||||
{
|
||||
"name" : "_ZN7android6Looper11sendMessageERKNS_2spINS_14MessageHandlerEEERKNS_7MessageE"
|
||||
},
|
||||
|
|
@ -527,9 +524,6 @@
|
|||
{
|
||||
"name" : "_ZN7android6Looper14removeMessagesERKNS_2spINS_14MessageHandlerEEEi"
|
||||
},
|
||||
{
|
||||
"name" : "_ZN7android6Looper16threadDestructorEPv"
|
||||
},
|
||||
{
|
||||
"name" : "_ZN7android6Looper17sendMessageAtTimeElRKNS_2spINS_14MessageHandlerEEERKNS_7MessageE"
|
||||
},
|
||||
|
|
@ -6909,13 +6903,6 @@
|
|||
"return_type" : "_ZTIv",
|
||||
"source_file" : "system/core/libutils/include/utils/LightRefBase.h"
|
||||
},
|
||||
{
|
||||
"access" : "private",
|
||||
"function_name" : "android::Looper::initTLSKey",
|
||||
"linker_set_key" : "_ZN7android6Looper10initTLSKeyEv",
|
||||
"return_type" : "_ZTIv",
|
||||
"source_file" : "system/core/libutils/include/utils/Looper.h"
|
||||
},
|
||||
{
|
||||
"function_name" : "android::Looper::sendMessage",
|
||||
"linker_set_key" : "_ZN7android6Looper11sendMessageERKNS_2spINS_14MessageHandlerEEERKNS_7MessageE",
|
||||
|
|
@ -6988,19 +6975,6 @@
|
|||
"return_type" : "_ZTIv",
|
||||
"source_file" : "system/core/libutils/include/utils/Looper.h"
|
||||
},
|
||||
{
|
||||
"access" : "private",
|
||||
"function_name" : "android::Looper::threadDestructor",
|
||||
"linker_set_key" : "_ZN7android6Looper16threadDestructorEPv",
|
||||
"parameters" :
|
||||
[
|
||||
{
|
||||
"referenced_type" : "_ZTIPv"
|
||||
}
|
||||
],
|
||||
"return_type" : "_ZTIv",
|
||||
"source_file" : "system/core/libutils/include/utils/Looper.h"
|
||||
},
|
||||
{
|
||||
"function_name" : "android::Looper::sendMessageAtTime",
|
||||
"linker_set_key" : "_ZN7android6Looper17sendMessageAtTimeElRKNS_2spINS_14MessageHandlerEEERKNS_7MessageE",
|
||||
|
|
|
|||
|
|
@ -513,9 +513,6 @@
|
|||
{
|
||||
"name" : "_ZN7android47LightRefBase_reportIncStrongRequireStrongFailedEPKv"
|
||||
},
|
||||
{
|
||||
"name" : "_ZN7android6Looper10initTLSKeyEv"
|
||||
},
|
||||
{
|
||||
"name" : "_ZN7android6Looper11sendMessageERKNS_2spINS_14MessageHandlerEEERKNS_7MessageE"
|
||||
},
|
||||
|
|
@ -531,9 +528,6 @@
|
|||
{
|
||||
"name" : "_ZN7android6Looper14removeMessagesERKNS_2spINS_14MessageHandlerEEEi"
|
||||
},
|
||||
{
|
||||
"name" : "_ZN7android6Looper16threadDestructorEPv"
|
||||
},
|
||||
{
|
||||
"name" : "_ZN7android6Looper17sendMessageAtTimeExRKNS_2spINS_14MessageHandlerEEERKNS_7MessageE"
|
||||
},
|
||||
|
|
@ -6949,13 +6943,6 @@
|
|||
"return_type" : "_ZTIv",
|
||||
"source_file" : "system/core/libutils/include/utils/LightRefBase.h"
|
||||
},
|
||||
{
|
||||
"access" : "private",
|
||||
"function_name" : "android::Looper::initTLSKey",
|
||||
"linker_set_key" : "_ZN7android6Looper10initTLSKeyEv",
|
||||
"return_type" : "_ZTIv",
|
||||
"source_file" : "system/core/libutils/include/utils/Looper.h"
|
||||
},
|
||||
{
|
||||
"function_name" : "android::Looper::sendMessage",
|
||||
"linker_set_key" : "_ZN7android6Looper11sendMessageERKNS_2spINS_14MessageHandlerEEERKNS_7MessageE",
|
||||
|
|
@ -7028,19 +7015,6 @@
|
|||
"return_type" : "_ZTIv",
|
||||
"source_file" : "system/core/libutils/include/utils/Looper.h"
|
||||
},
|
||||
{
|
||||
"access" : "private",
|
||||
"function_name" : "android::Looper::threadDestructor",
|
||||
"linker_set_key" : "_ZN7android6Looper16threadDestructorEPv",
|
||||
"parameters" :
|
||||
[
|
||||
{
|
||||
"referenced_type" : "_ZTIPv"
|
||||
}
|
||||
],
|
||||
"return_type" : "_ZTIv",
|
||||
"source_file" : "system/core/libutils/include/utils/Looper.h"
|
||||
},
|
||||
{
|
||||
"function_name" : "android::Looper::sendMessageAtTime",
|
||||
"linker_set_key" : "_ZN7android6Looper17sendMessageAtTimeExRKNS_2spINS_14MessageHandlerEEERKNS_7MessageE",
|
||||
|
|
|
|||
|
|
@ -499,8 +499,6 @@ private:
|
|||
void rebuildEpollLocked();
|
||||
void scheduleEpollRebuildLocked();
|
||||
|
||||
static void initTLSKey();
|
||||
static void threadDestructor(void *st);
|
||||
static void initEpollEvent(struct epoll_event* eventItem);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue