Codebase list mozc / ea122ac
Set thread name Thread name was identical before this CL so bug investigation was sometimes hard. This is basically an internal change for debugging. No user-visible behavior change is intended. BUG= TEST= REF_BUG= REF_CL=113236557,113256654,113322951,113357056 REF_TIME=2016-01-28T17:36:56+09:00 REF_TIME_RAW=1453970216 +0900 Tsuyoshi Matsuzaki 8 years ago
23 changed file(s) with 56 addition(s) and 46 deletion(s). Raw diff Collapse all Expand all
6666 if (FLAGS_dummy_threads_size > 0) {
6767 threads.reset(new DummyThread[FLAGS_dummy_threads_size]);
6868 for (int i = 0; i < FLAGS_dummy_threads_size; ++i) {
69 threads[i].Start();
69 threads[i].Start("CpuStatsMain");
7070 }
7171 }
7272
8181 g_counter = 0;
8282 Mutex mutex;
8383 MutexTestThread t(&mutex, 1, 1000);
84 t.Start();
84 t.Start("MutextBasicTest");
8585
8686 Util::Sleep(100); // still g_counter is locked
8787 scoped_lock lockA(&mutex); // get mutex 2nd
100100 MutexTestSleepThread t(&mutex, 1);
101101
102102 EXPECT_TRUE(mutex.TryLock());
103 t.Start();
103 t.Start("TryLockTest");
104104 Util::Sleep(100);
105105 EXPECT_EQ(0, g_counter);
106106 mutex.Unlock();
110110 {
111111 scoped_try_lock lock(&mutex);
112112 EXPECT_TRUE(lock.locked());
113 t.Start();
113 t.Start("TryLockTest");
114114 Util::Sleep(100);
115115 EXPECT_EQ(1, g_counter);
116116 }
133133 uint64 start_sec;
134134 uint32 start_usec;
135135 Clock::GetTimeOfDay(&start_sec, &start_usec);
136 t.Start();
136 t.Start("TryLockTest");
137137
138138 Util::Sleep(100);
139139 EXPECT_EQ(1, g_counter);
164164 }
165165
166166 for (int i = 0; i < kThreadsSize; ++i) {
167 threads[i]->Start();
167 threads[i]->Start("MutextBatchTest");
168168 }
169169
170170 for (int i = 0; i < kThreadsSize; ++i) {
227227 }
228228
229229 for (size_t i = 0; i < kThreadsSize; ++i) {
230 threads[i]->Start();
230 threads[i]->Start("ReaderWriterTest");
231231 }
232232
233233 const uint32 kSleepTime = 500; // 500 msec
117117 }
118118
119119 void Start() {
120 timer_thread_.Start();
120 timer_thread_.Start("QueueTimer");
121121 }
122122
123123 private:
9595 ThreadTest test3;
9696
9797 // Create the ThreadInstance simultaneously.
98 test1.Start();
99 test2.Start();
100 test3.Start();
98 test1.Start("ThreadTest");
99 test2.Start("ThreadTest");
100 test3.Start("ThreadTest");
101101
102102 test1.Join();
103103 test2.Join();
6464 bool joinable_;
6565 };
6666
67 void Thread::Start() {
67 void Thread::Start(const string &thread_name) {
68 // TODO(mozc-dev): Set thread name.
6869 if (IsRunning()) {
6970 return;
7071 }
126127 bool joinable_;
127128 };
128129
129 void Thread::Start() {
130 void Thread::Start(const string &thread_name) {
130131 if (IsRunning()) {
131132 return;
132133 }
138139 static_cast<void *>(this))) {
139140 state_->is_running_ = false;
140141 state_->handle_.reset();
142 } else {
143 #if defined(OS_NACL)
144 // NaCl doesn't support setname.
145 #elif defined(OS_MACOSX)
146 pthread_setname_np(thread_name.c_str());
147 #else // !(OS_NACL | OS_MACOSX)
148 pthread_setname_np(*state_->handle_, thread_name.c_str());
149 #endif // !(OS_NACL | OS_MACOSX)
141150 }
142151 }
143152
3030 #define MOZC_BASE_THREAD_H_
3131
3232 #include <memory>
33 #include <string>
3334
3435 #include "base/port.h"
3536
4445
4546 virtual void Run() = 0;
4647
47 void Start();
48 void Start(const string &thread_name);
4849 bool IsRunning() const;
4950 void SetJoinable(bool joinable);
5051 void Join();
6161 TEST(ThreadTest, BasicThreadTest) {
6262 {
6363 TestThread t(1000);
64 t.Start();
64 t.Start("BasicThreadTest");
6565 EXPECT_TRUE(t.IsRunning());
6666 t.Join();
6767 EXPECT_FALSE(t.IsRunning());
7171 {
7272 TestThread t(1000);
7373 t.clear_invoked();
74 t.Start();
74 t.Start("BasicThreadTest");
7575
7676 Util::Sleep(3000);
7777 EXPECT_FALSE(t.IsRunning());
8181
8282 {
8383 TestThread t(3000);
84 t.Start();
84 t.Start("BasicThreadTest");
8585 Util::Sleep(1000);
8686 t.Terminate();
8787 Util::Sleep(100);
9393 {
9494 TestThread t(1000);
9595 t.clear_invoked();
96 t.Start();
96 t.Start("RestartTest");
9797 EXPECT_TRUE(t.IsRunning());
9898 t.Join();
9999 EXPECT_TRUE(t.invoked());
100100 EXPECT_FALSE(t.IsRunning());
101101 t.clear_invoked();
102 t.Start();
102 t.Start("RestartTest");
103103 EXPECT_TRUE(t.IsRunning());
104104 t.Join();
105105 EXPECT_TRUE(t.invoked());
106106 EXPECT_FALSE(t.IsRunning());
107107 t.clear_invoked();
108 t.Start();
108 t.Start("RestartTest");
109109 EXPECT_TRUE(t.IsRunning());
110110 t.Join();
111111 EXPECT_TRUE(t.invoked());
6161 UnnamedEvent event;
6262 EXPECT_TRUE(event.IsAvailable());
6363 UnnamedEventNotifierThread t(&event, 400);
64 t.Start();
64 t.Start("UnnamedEventTest");
6565 EXPECT_FALSE(event.Wait(100));
6666 EXPECT_FALSE(event.Wait(100));
6767 EXPECT_TRUE(event.Wait(800));
7272 UnnamedEvent event;
7373 EXPECT_TRUE(event.IsAvailable());
7474 UnnamedEventNotifierThread t(&event, 100);
75 t.Start();
75 t.Start("UnnamedEventTest");
7676 EXPECT_TRUE(event.Wait(2000));
7777 t.Join();
7878 }
8181 UnnamedEvent event;
8282 EXPECT_TRUE(event.IsAvailable());
8383 UnnamedEventNotifierThread t(&event, 3000);
84 t.Start();
84 t.Start("UnnamedEventTest");
8585 EXPECT_FALSE(event.Wait(100));
8686 EXPECT_FALSE(event.Wait(1000));
8787 EXPECT_FALSE(event.Wait(1000));
9292 UnnamedEvent event;
9393 EXPECT_TRUE(event.IsAvailable());
9494 UnnamedEventNotifierThread t(&event, 2000);
95 t.Start();
95 t.Start("UnnamedEventTest");
9696 EXPECT_FALSE(event.Wait(500));
9797 EXPECT_FALSE(event.Wait(500));
9898 EXPECT_TRUE(event.Wait(5000));
437437 NaclSessionHandlerInstance::NaclSessionHandlerInstance(PP_Instance instance)
438438 : pp::Instance(instance) {
439439 mozc_thread_.reset(new MozcSessionHandlerThread(this, &message_queue_));
440 mozc_thread_->Start();
440 mozc_thread_->Start("NaclSessionHandler");
441441 }
442442
443443 void NaclSessionHandlerInstance::HandleMessage(const pp::Var &var_message) {
127127 DictionaryLoaderThread thread;
128128
129129 // Load dictionary in another thread.
130 thread.Start();
130 thread.Start("SuppressionDictionaryTest");
131131
132132 for (int i = 0; i < 100; ++i) {
133133 const string key = "key" + NumberUtil::SimpleItoa(i);
225225 value_ = value;
226226 pos_ = pos;
227227 }
228 Start();
228 Start("UserDictionaryReloader");
229229 }
230230
231231 // When the user dictionary exists AND the modification time has been updated,
245245 return;
246246 }
247247 modified_at_ = modification_time;
248 Start();
248 Start("UserDictionaryReloader");
249249 }
250250
251251 virtual void Run() {
7171 if (server_thread_.get() == NULL) {
7272 server_thread_.reset(new IPCServerThread(this));
7373 server_thread_->SetJoinable(true);
74 server_thread_->Start();
74 server_thread_->Start("IPCServer");
7575 } else {
7676 LOG(WARNING) << "Another thead is already running";
7777 }
101101 mozc::EchoServer con(FLAGS_server_address, 10, 1000);
102102 mozc::EchoServerThread server_thread_main(&con);
103103 server_thread_main.SetJoinable(true);
104 server_thread_main.Start();
104 server_thread_main.Start("IpcMain");
105105
106106 vector<mozc::MultiConnections> cons(FLAGS_num_threads);
107107 for (size_t i = 0; i < cons.size(); ++i) {
108108 cons[i].SetJoinable(true);
109 cons[i].Start();
109 cons[i].Start("MultiConnections");
110110 }
111111 for (size_t i = 0; i < cons.size(); ++i) {
112112 cons[i].Join();
9696
9797 TEST_F(IPCPathManagerTest, IPCPathManagerTest) {
9898 CreateThread t;
99 t.Start();
99 t.Start("IPCPathManagerTest");
100100 Util::Sleep(1000);
101101 IPCPathManager *manager =
102102 IPCPathManager::GetIPCPathManager("test");
123123 vector<BatchGetPathNameThread *> threads(64);
124124 for (size_t i = 0; i < threads.size(); ++i) {
125125 threads[i] = new BatchGetPathNameThread;
126 threads[i]->Start();
126 threads[i]->Start("IPCPathManagerBatchTest");
127127 }
128128 for (size_t i = 0; i < threads.size(); ++i) {
129129 threads[i]->Join();
143143 cons[i]->SetMachPortManager(&manager);
144144 #endif
145145 cons[i]->SetJoinable(true);
146 cons[i]->Start();
146 cons[i]->Start("IPCTest");
147147 }
148148 for (size_t i = 0; i < cons.size(); ++i) {
149149 cons[i]->Join();
104104
105105 TEST_F(NamedEventTest, NamedEventBasicTest) {
106106 NamedEventListenerThread listner(kName, 0, 50, 100);
107 listner.Start();
107 listner.Start("NamedEventBasicTest");
108108 Util::Sleep(200);
109109 NamedEventNotifier notifier(kName);
110110 ASSERT_TRUE(notifier.IsAvailable());
150150 vector<std::unique_ptr<NamedEventListenerThread>> listeners(kNumRequests);
151151 for (size_t i = 0; i < kNumRequests; ++i) {
152152 listeners[i].reset(new NamedEventListenerThread(kName, 33 * i, 50, 100));
153 listeners[i]->Start();
153 listeners[i]->Start("NamedEventMultipleListenerTest");
154154 }
155155
156156 Util::Sleep(200);
5555 LOG(ERROR) << "::CreateEvent() failed.";
5656 return;
5757 }
58 Thread::Start(); // start
58 Thread::Start("WatchDog"); // start
5959 }
6060
6161 ProcessWatchDog::~ProcessWatchDog() {
219219 thread_id_(UnknownProcessID),
220220 is_finished_(false),
221221 mutex_(new Mutex) {
222 Thread::Start();
222 Thread::Start("WatchDog");
223223 }
224224
225225 ProcessWatchDog::~ProcessWatchDog() {
00 MAJOR=2
11 MINOR=17
2 BUILD=2425
2 BUILD=2426
33 REVISION=102
44 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
55 # downloaded by NaCl Mozc.
469469 syncer_.reset(new UserHistoryPredictorSyncer(
470470 this,
471471 UserHistoryPredictorSyncer::LOAD));
472 syncer_->Start();
472 syncer_->Start("UserHistoryPredictor:Load");
473473
474474 return true;
475475 }
486486 syncer_.reset(new UserHistoryPredictorSyncer(
487487 this,
488488 UserHistoryPredictorSyncer::SAVE));
489 syncer_->Start();
489 syncer_->Start("UserHistoryPredictor:Save");
490490
491491 return true;
492492 }
124124 path_ = path;
125125 disable_renderer_path_check_ = disable_renderer_path_check;
126126 ipc_client_factory_interface_ = ipc_client_factory_interface;
127 Thread::Start();
127 Thread::Start("Renderer");
128128 }
129129
130130 void Run() {
215215 bool SessionHandler::StartWatchDog() {
216216 #ifndef MOZC_DISABLE_SESSION_WATCHDOG
217217 if (!session_watch_dog_->IsRunning()) {
218 session_watch_dog_->Start();
218 session_watch_dog_->Start("WatchDog");
219219 }
220220 return session_watch_dog_->IsRunning();
221221 #else // MOZC_DISABLE_SESSION_WATCHDOG
105105
106106 EXPECT_EQ(0, client.GetFunctionCallCount("Cleanup"));
107107
108 watchdog.Start(); // start
108 watchdog.Start("SessionWatchDogTest"); // start
109109
110110 mozc::Util::Sleep(100);
111111 EXPECT_TRUE(watchdog.IsRunning());
144144
145145 EXPECT_EQ(0, client.GetFunctionCallCount("Cleanup"));
146146
147 watchdog.Start(); // start
147 watchdog.Start("SessionWatchDogCPUStatsTest"); // start
148148
149149 mozc::Util::Sleep(100);
150150 EXPECT_TRUE(watchdog.IsRunning());
547547
548548 // Implements SelectionMonitorInterface::StartMonitoring.
549549 virtual void StartMonitoring() {
550 Thread::Start();
550 Thread::Start("SelectionMonitor");
551551 }
552552
553553 // Implements SelectionMonitorInterface::QueryQuit.