OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "tools/android/forwarder2/thread.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace forwarder2 { | |
10 | |
11 Thread::Thread() : thread_(static_cast<pthread_t>(-1)) {} | |
12 | |
13 Thread::~Thread() {} | |
14 | |
15 void Thread::Start() { | |
16 int ret = pthread_create(&thread_, NULL, &ThreadCallback, this); | |
17 CHECK_EQ(0, ret); | |
18 } | |
19 | |
20 void Thread::Detach() { | |
21 CHECK_NE(static_cast<pthread_t>(-1), thread_); | |
22 int ret = pthread_detach(thread_); | |
23 CHECK_EQ(0, ret); | |
24 } | |
25 | |
26 void Thread::Join() { | |
27 CHECK_NE(static_cast<pthread_t>(-1), thread_); | |
28 int ret = pthread_join(thread_, NULL); | |
29 CHECK_EQ(0, ret); | |
30 } | |
31 | |
32 // static | |
33 void* Thread::ThreadCallback(void* arg) { | |
34 CHECK(arg); | |
35 Thread* obj = reinterpret_cast<Thread*>(arg); | |
36 obj->Run(); | |
37 return NULL; | |
38 } | |
39 | |
40 } // namespace forwarder | |
OLD | NEW |