diff --git a/starboard/common/log.cc b/starboard/common/log.cc index 68093d3146fa..1a4e0b10335a 100644 --- a/starboard/common/log.cc +++ b/starboard/common/log.cc @@ -170,7 +170,7 @@ void LogMessage::Init(const char* file, int line) { char name[128] = {0}; pthread_getname_np(pthread_self(), name, SB_ARRAY_SIZE_INT(name)); stream_ << '['; - stream_ << name << '/' << SbThreadGetId() << ':'; + stream_ << name << '/' << pthread_self() << ':'; EzTimeValue time_value; EzTimeValueGetNow(&time_value, NULL); EzTimeT t = time_value.tv_sec; diff --git a/starboard/common/mutex.cc b/starboard/common/mutex.cc index d152971229a1..da362cfec081 100644 --- a/starboard/common/mutex.cc +++ b/starboard/common/mutex.cc @@ -47,28 +47,28 @@ void Mutex::Release() const { void Mutex::DCheckAcquired() const { #ifdef _DEBUG - SB_DCHECK(current_thread_acquired_ == SbThreadGetCurrent()); + SB_DCHECK(pthread_equal(current_thread_acquired_, pthread_self())); #endif // _DEBUG } #ifdef _DEBUG void Mutex::debugInit() { - current_thread_acquired_ = kSbThreadInvalid; + current_thread_acquired_ = 0; } void Mutex::debugSetReleased() const { - SbThread current_thread = SbThreadGetCurrent(); - SB_DCHECK(current_thread_acquired_ == current_thread); - current_thread_acquired_ = kSbThreadInvalid; + pthread_t current_thread = pthread_self(); + SB_DCHECK(pthread_equal(current_thread_acquired_, current_thread)); + current_thread_acquired_ = 0; } void Mutex::debugPreAcquire() const { // Check that the mutex is not held by the current thread. - SbThread current_thread = SbThreadGetCurrent(); - SB_DCHECK(current_thread_acquired_ != current_thread); + pthread_t current_thread = pthread_self(); + SB_DCHECK(!pthread_equal(current_thread_acquired_, current_thread)); } void Mutex::debugSetAcquired() const { // Check that the thread has already not been held. - SB_DCHECK(current_thread_acquired_ == kSbThreadInvalid); - current_thread_acquired_ = SbThreadGetCurrent(); + SB_DCHECK(current_thread_acquired_ == 0); + current_thread_acquired_ = pthread_self(); } #else void Mutex::debugInit() {} diff --git a/starboard/common/mutex.h b/starboard/common/mutex.h index af6bd2e9a343..1f9ddfa187a8 100644 --- a/starboard/common/mutex.h +++ b/starboard/common/mutex.h @@ -18,6 +18,8 @@ #ifndef STARBOARD_COMMON_MUTEX_H_ #define STARBOARD_COMMON_MUTEX_H_ +#include + #include "starboard/mutex.h" namespace starboard { @@ -39,7 +41,7 @@ class Mutex { void debugSetReleased() const; void debugPreAcquire() const; void debugSetAcquired() const; - mutable SbThread current_thread_acquired_; + mutable pthread_t current_thread_acquired_; #else void debugInit(); void debugSetReleased() const; diff --git a/starboard/common/recursive_mutex.cc b/starboard/common/recursive_mutex.cc index 7b44bd0d42eb..d77457526601 100644 --- a/starboard/common/recursive_mutex.cc +++ b/starboard/common/recursive_mutex.cc @@ -17,14 +17,13 @@ namespace starboard { -RecursiveMutex::RecursiveMutex() - : owner_id_(kSbThreadInvalidId), recurse_count_(0) {} +RecursiveMutex::RecursiveMutex() : owner_id_(0), recurse_count_(0) {} RecursiveMutex::~RecursiveMutex() {} void RecursiveMutex::Acquire() { - SbThreadId current_thread = SbThreadGetId(); - if (owner_id_ == current_thread) { + pthread_t current_thread = pthread_self(); + if (pthread_equal(owner_id_, current_thread)) { recurse_count_++; SB_DCHECK(recurse_count_ > 0); return; @@ -35,20 +34,20 @@ void RecursiveMutex::Acquire() { } void RecursiveMutex::Release() { - SB_DCHECK(owner_id_ == SbThreadGetId()); - if (owner_id_ == SbThreadGetId()) { + SB_DCHECK(pthread_equal(owner_id_, pthread_self())); + if (pthread_equal(owner_id_, pthread_self())) { SB_DCHECK(0 < recurse_count_); recurse_count_--; if (recurse_count_ == 0) { - owner_id_ = kSbThreadInvalidId; + owner_id_ = 0; mutex_.Release(); } } } bool RecursiveMutex::AcquireTry() { - SbThreadId current_thread = SbThreadGetId(); - if (owner_id_ == current_thread) { + pthread_t current_thread = pthread_self(); + if (pthread_equal(owner_id_, current_thread)) { recurse_count_++; SB_DCHECK(recurse_count_ > 0); return true; diff --git a/starboard/common/recursive_mutex.h b/starboard/common/recursive_mutex.h index 6806858cea1c..f86d184870ad 100644 --- a/starboard/common/recursive_mutex.h +++ b/starboard/common/recursive_mutex.h @@ -44,7 +44,7 @@ class RecursiveMutex { private: Mutex mutex_; - SbThreadId owner_id_; + pthread_t owner_id_; // Only the owner is able to modify recurse_count_. size_t recurse_count_; diff --git a/starboard/common/thread_collision_warner.cc b/starboard/common/thread_collision_warner.cc index b1844234d648..94d7649056c8 100644 --- a/starboard/common/thread_collision_warner.cc +++ b/starboard/common/thread_collision_warner.cc @@ -4,6 +4,8 @@ #include "starboard/common/thread_collision_warner.h" +#include + #include "starboard/atomic.h" #include "starboard/common/log.h" #include "starboard/thread.h" @@ -34,7 +36,9 @@ ThreadCollisionWarner::Check::Check(ThreadCollisionWarner* warner) ThreadCollisionWarner::Check::~Check() {} static SbAtomic32 CurrentThread() { - const SbThreadId current_thread_id = SbThreadGetId(); + uintptr_t current_thread_id = + reinterpret_cast(reinterpret_cast(pthread_self())); + // We need to get the thread id into an atomic data type. This might be a // truncating conversion, but any loss-of-information just increases the // chance of a false negative, not a false positive.