| OLD | NEW |
| (Empty) |
| 1 // Copyright 2009 The RE2 Authors. All Rights Reserved. | |
| 2 // Use of this source code is governed by a BSD-style | |
| 3 // license that can be found in the LICENSE file. | |
| 4 | |
| 5 #include "util/thread.h" | |
| 6 #include "util/util.h" | |
| 7 | |
| 8 Thread::Thread() { | |
| 9 pid_ = 0; | |
| 10 running_ = 0; | |
| 11 joinable_ = 0; | |
| 12 } | |
| 13 | |
| 14 Thread::~Thread() { | |
| 15 } | |
| 16 | |
| 17 void *startThread(void *v) { | |
| 18 Thread* t = (Thread*)v; | |
| 19 t->Run(); | |
| 20 return 0; | |
| 21 } | |
| 22 | |
| 23 void Thread::Start() { | |
| 24 CHECK(!running_); | |
| 25 pthread_create(&pid_, 0, startThread, this); | |
| 26 running_ = true; | |
| 27 if (!joinable_) | |
| 28 pthread_detach(pid_); | |
| 29 } | |
| 30 | |
| 31 void Thread::Join() { | |
| 32 CHECK(running_); | |
| 33 CHECK(joinable_); | |
| 34 void *val; | |
| 35 pthread_join(pid_, &val); | |
| 36 running_ = 0; | |
| 37 } | |
| 38 | |
| 39 void Thread::SetJoinable(bool j) { | |
| 40 CHECK(!running_); | |
| 41 joinable_ = j; | |
| 42 } | |
| OLD | NEW |