17 #include <glog/logging.h> 28 void ThreadMain(
const std::string&
name, std::function<
void()> callback) {
29 #if defined(OS_MAC) || defined(OS_IOS) 30 pthread_setname_np(name.c_str());
31 #elif defined(OS_POSIX) 32 pthread_setname_np(pthread_self(), name.c_str());
34 # error "Not implemented for Windows" 37 #ifdef DEBUG_DEADLOCKS 38 util::Finally scope(&WaitingTracker::ThreadExit);
46 : name_(name), thread_(&ThreadMain, name,
std::move(callback)) {
47 DCHECK_LT(name.size(), 16u) <<
"Name too long: " << name;
48 #ifdef DEBUG_DEADLOCKS 49 original_id_ = thread_.get_id();
50 WaitingTracker::AddThread(
this);
55 DCHECK(!thread_.joinable());
56 #ifdef DEBUG_DEADLOCKS 57 WaitingTracker::RemoveThread(
this);
Thread(const std::string &name, std::function< void()> callback)