thread.cpp 873 Bytes
Newer Older
1
#include "pls/internal/base/thread.h"
2 3

namespace pls {
4 5 6
namespace internal {
namespace base {

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
thread::thread() :
    pthread_thread_{},
    running_{false} {}

thread::~thread() {
  if (running_) {
    join();
  }
}

thread::thread(thread &&other) noexcept :
    pthread_thread_{other.pthread_thread_},
    running_{other.running_} {
  other.running_ = false;
}

thread &thread::operator=(thread &&other) noexcept {
  this->pthread_thread_ = other.pthread_thread_;
  this->running_ = other.running_;

  other.running_ = false;

  return *this;
}

32
#ifdef PLS_THREAD_SPECIFIC_PTHREAD
33 34
pthread_key_t this_thread::local_storage_key_ = false;
bool this_thread::local_storage_key_initialized_;
35 36
#endif
#ifdef PLS_THREAD_SPECIFIC_COMPILER
37
__thread void *this_thread::local_state_;
38
#endif
39 40 41

void thread::join() {
  pthread_join(pthread_thread_, nullptr);
42
  running_ = false;
43
}
44 45 46

}
}
47
}