int __wrap_pthread_create(pthread_t* thread, const pthread_attr_t* attr, void *(*start_routine) (void *), void* arg) { int ret = __real_pthread_create(thread, attr, HPHP::start_routine_wrapper, arg); log_pthread_event(HPHP::PTHREAD_CREATE, thread, start_routine); return ret; }
void* start_routine_wrapper(void *arg) { pthread_t self = pthread_self(); auto& info = *reinterpret_cast<PthreadInfo*>(arg); MemoryManager::TlsWrapper::getCheck(); info.mm = &MM(); assert(info.mm); info.mm->resetExternalStats(); #ifdef __linux__ info.tid = syscall(SYS_gettid); #else info.tid = getpid(); #endif auto ret = info.start_routine(info.start_routine_arg); log_pthread_event(PTHREAD_EXIT, &self); return ret; }
void* start_routine_wrapper(void *arg) { pthread_t self = pthread_self(); start_routine_t start_routine; retry: { Lock lock(m_threadmap_lock); auto it = threadMap.find(self); if (it == threadMap.end()) { goto sleep_wait; } auto& info = it->second; MemoryManager::TlsWrapper::getCheck(); info.mm = &MM(); assert(info.mm); info.mm->resetExternalStats(); #ifdef __linux__ info.tid = syscall(SYS_gettid); #else info.tid = getpid(); #endif info.pid = getpid(); start_routine = info.start_routine; goto done; } sleep_wait: usleep(100); goto retry; done: auto ret = start_routine(arg); log_pthread_event(PTHREAD_EXIT, &self); return ret; }
int __wrap_pthread_join(pthread_t thread, void **retval) { log_pthread_event(HPHP::PTHREAD_JOIN, &thread); return __real_pthread_join(thread, retval); }
void __wrap_pthread_exit(void* retval) { pthread_t self = pthread_self(); log_pthread_event(HPHP::PTHREAD_EXIT, &self); __real_pthread_exit(retval); }