thread_posix.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2015 The Crashpad Authors. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "util/thread/thread.h"
  15. #include <errno.h>
  16. #include "base/logging.h"
  17. namespace crashpad {
  18. void Thread::Start() {
  19. DCHECK(!platform_thread_);
  20. errno = pthread_create(&platform_thread_, nullptr, ThreadEntryThunk, this);
  21. PCHECK(errno == 0) << "pthread_create";
  22. }
  23. void Thread::Join() {
  24. DCHECK(platform_thread_);
  25. errno = pthread_join(platform_thread_, nullptr);
  26. PCHECK(errno == 0) << "pthread_join";
  27. platform_thread_ = 0;
  28. }
  29. // static
  30. void* Thread::ThreadEntryThunk(void* argument) {
  31. Thread* self = reinterpret_cast<Thread*>(argument);
  32. self->ThreadMain();
  33. return nullptr;
  34. }
  35. } // namespace crashpad