Skip to content

Commit

Permalink
Remove thread_local workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
jellefoks committed Feb 20, 2025
1 parent ba099b0 commit 08b32b3
Showing 1 changed file with 0 additions and 25 deletions.
25 changes: 0 additions & 25 deletions base/threading/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,11 @@ namespace base {
#if DCHECK_IS_ON()
namespace {

#if defined(STARBOARD)
ABSL_CONST_INIT pthread_once_t s_once_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT pthread_key_t s_thread_local_key = 0;

void InitThreadLocalKey() {
int res = pthread_key_create(&s_thread_local_key , NULL);
DCHECK(res == 0);
}

void EnsureThreadLocalKeyInited() {
pthread_once(&s_once_flag, InitThreadLocalKey);
}

bool GetWasQuitProperly() {
EnsureThreadLocalKeyInited();
void* was_quit_properly = pthread_getspecific(s_thread_local_key);
return !!was_quit_properly ? reinterpret_cast<intptr_t>(was_quit_properly) != 0 : false;
}
#else
// We use this thread-local variable to record whether or not a thread exited
// because its Stop method was called. This allows us to catch cases where
// MessageLoop::QuitWhenIdle() is called directly, which is unexpected when
// using a Thread to setup and run a MessageLoop.
ABSL_CONST_INIT thread_local bool was_quit_properly = false;
#endif

} // namespace
#endif
Expand Down Expand Up @@ -372,13 +352,8 @@ void Thread::Run(RunLoop* run_loop) {
// static
void Thread::SetThreadWasQuitProperly(bool flag) {
#if DCHECK_IS_ON()
#if defined(STARBOARD)
EnsureThreadLocalKeyInited();
pthread_setspecific(s_thread_local_key, reinterpret_cast<void*>(static_cast<intptr_t>(flag)));
#else
was_quit_properly = flag;
#endif
#endif
}

// static
Expand Down

0 comments on commit 08b32b3

Please sign in to comment.