Skip to content

Commit

Permalink
Cherry pick PR #3069: Deprecate SbOnce (#3083)
Browse files Browse the repository at this point in the history
Refer to the original PR: #3069

b/302335657

Test-On-Device: true

Change-Id: Ib6447e3342dc7b2248c6bba219d0ce97b3cc8933

Co-authored-by: Yavor Goulishev <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and y4vor authored Apr 30, 2024
1 parent ec08531 commit b0aceb8
Show file tree
Hide file tree
Showing 97 changed files with 326 additions and 224 deletions.
6 changes: 3 additions & 3 deletions base/observer_list_threadsafe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "third_party/abseil-cpp/absl/base/attributes.h"

#if defined(STARBOARD)
#include "starboard/once.h"
#include <pthread.h>
#endif

namespace base {
Expand All @@ -17,7 +17,7 @@ namespace internal {

namespace {

ABSL_CONST_INIT SbOnceControl s_once_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid;

void InitThreadLocalKey() {
Expand All @@ -28,7 +28,7 @@ void InitThreadLocalKey() {
}

void ObserverListThreadSafeBase::EnsureThreadLocalKeyInited() {
SbOnce(&s_once_flag, InitThreadLocalKey);
pthread_once(&s_once_flag, InitThreadLocalKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));
}

Expand Down
11 changes: 6 additions & 5 deletions base/run_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#include "third_party/abseil-cpp/absl/base/attributes.h"

#if defined(STARBOARD)
#include "starboard/once.h"
#include <pthread.h>

#include "starboard/thread.h"
#endif

Expand All @@ -25,7 +26,7 @@ namespace base {
namespace {

#if defined(STARBOARD)
ABSL_CONST_INIT SbOnceControl s_once_delegate_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_delegate_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_delegate_key = kSbThreadLocalKeyInvalid;

void InitThreadLocalDelegateKey() {
Expand All @@ -34,7 +35,7 @@ void InitThreadLocalDelegateKey() {
}

void EnsureThreadLocalDelegateKeyInited() {
SbOnce(&s_once_delegate_flag, InitThreadLocalDelegateKey);
pthread_once(&s_once_delegate_flag, InitThreadLocalDelegateKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_delegate_key));
}

Expand All @@ -43,7 +44,7 @@ RunLoop::Delegate* GetDelegate() {
SbThreadGetLocalValue(s_thread_local_delegate_key));
}

ABSL_CONST_INIT SbOnceControl s_once_timeout_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_timeout_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_timeout_key = kSbThreadLocalKeyInvalid;

void InitThreadLocalTimeoutKey() {
Expand All @@ -52,7 +53,7 @@ void InitThreadLocalTimeoutKey() {
}

void EnsureThreadLocalTimeoutKeyInited() {
SbOnce(&s_once_timeout_flag, InitThreadLocalTimeoutKey);
pthread_once(&s_once_timeout_flag, InitThreadLocalTimeoutKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_timeout_key));
}

Expand Down
7 changes: 4 additions & 3 deletions base/sampling_heap_profiler/sampling_heap_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
#endif

#if defined(STARBOARD)
#include <pthread.h>

#include "base/check_op.h"
#include "starboard/once.h"
#include "starboard/thread.h"
#endif

Expand Down Expand Up @@ -95,15 +96,15 @@ const char* GetAndLeakThreadName() {

const char* UpdateAndGetThreadName(const char* name) {
#if defined(STARBOARD)
static SbOnceControl s_once_flag = SB_ONCE_INITIALIZER;
static pthread_once_t s_once_flag = PTHREAD_ONCE_INIT;
static SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid;

auto InitThreadLocalKey = [](){
s_thread_local_key = SbThreadCreateLocalKey(NULL);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));
};

SbOnce(&s_once_flag, InitThreadLocalKey);
pthread_once(&s_once_flag, InitThreadLocalKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));

const char* thread_name = static_cast<const char*>(SbThreadGetLocalValue(s_thread_local_key));
Expand Down
19 changes: 10 additions & 9 deletions base/sequence_token.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include "third_party/abseil-cpp/absl/base/attributes.h"

#if defined(STARBOARD)
#include <pthread.h>

#include "base/check_op.h"
#include "starboard/once.h"
#include "starboard/thread.h"
#include "base/logging.h"
#endif
Expand All @@ -23,7 +24,7 @@ base::AtomicSequenceNumber g_sequence_token_generator;
base::AtomicSequenceNumber g_task_token_generator;

#if defined(STARBOARD)
ABSL_CONST_INIT SbOnceControl s_once_sequence_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_sequence_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_sequence_key =
kSbThreadLocalKeyInvalid;

Expand All @@ -33,11 +34,11 @@ void InitThreadLocalSequenceKey() {
}

void EnsureThreadLocalSequenceKeyInited() {
SbOnce(&s_once_sequence_flag, InitThreadLocalSequenceKey);
pthread_once(&s_once_sequence_flag, InitThreadLocalSequenceKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_sequence_key));
}

ABSL_CONST_INIT SbOnceControl s_once_set_sequence_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_set_sequence_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_sequence_set_for_thread =
kSbThreadLocalKeyInvalid;
void InitThreadLocalSequenceBoolKey() {
Expand All @@ -46,7 +47,7 @@ void InitThreadLocalSequenceBoolKey() {
}

void EnsureThreadLocalSequenceBoolKeyInited() {
SbOnce(&s_once_set_sequence_flag, InitThreadLocalSequenceBoolKey);
pthread_once(&s_once_set_sequence_flag, InitThreadLocalSequenceBoolKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_sequence_set_for_thread));
}

Expand All @@ -57,7 +58,7 @@ bool IsSequenceSetForThread() {
: false;
}

ABSL_CONST_INIT SbOnceControl s_once_task_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_task_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_task_key =
kSbThreadLocalKeyInvalid;

Expand All @@ -67,11 +68,11 @@ void InitThreadLocalTaskKey() {
}

void EnsureThreadLocalTaskKeyInited() {
SbOnce(&s_once_task_flag, InitThreadLocalTaskKey);
pthread_once(&s_once_task_flag, InitThreadLocalTaskKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_task_key));
}

ABSL_CONST_INIT SbOnceControl s_once_set_task_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_set_task_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_task_set_for_thread =
kSbThreadLocalKeyInvalid;
void InitThreadLocalTaskBoolKey() {
Expand All @@ -80,7 +81,7 @@ void InitThreadLocalTaskBoolKey() {
}

void EnsureThreadLocalTaskBoolKeyInited() {
SbOnce(&s_once_set_task_flag, InitThreadLocalTaskBoolKey);
pthread_once(&s_once_set_task_flag, InitThreadLocalTaskBoolKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_task_set_for_thread));
}

Expand Down
7 changes: 4 additions & 3 deletions base/task/common/scoped_defer_task_posting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include "third_party/abseil-cpp/absl/base/attributes.h"

#if defined(STARBOARD)
#include <pthread.h>

#include "base/check_op.h"
#include "starboard/once.h"
#include "starboard/thread.h"
#endif

Expand All @@ -18,7 +19,7 @@ namespace base {
namespace {

#if defined(STARBOARD)
ABSL_CONST_INIT SbOnceControl s_once_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid;

void InitThreadLocalKey() {
Expand All @@ -27,7 +28,7 @@ void InitThreadLocalKey() {
}

void EnsureThreadLocalKeyInited() {
SbOnce(&s_once_flag, InitThreadLocalKey);
pthread_once(&s_once_flag, InitThreadLocalKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));
}

Expand Down
15 changes: 8 additions & 7 deletions base/task/common/task_annotator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
#endif

#if defined(STARBOARD)
#include <pthread.h>

#include "base/check_op.h"
#include "starboard/once.h"
#include "starboard/thread.h"
#endif

Expand All @@ -39,7 +40,7 @@ namespace {
TaskAnnotator::ObserverForTesting* g_task_annotator_observer = nullptr;

#if defined(STARBOARD)
ABSL_CONST_INIT SbOnceControl s_once_task_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_task_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_task_key =
kSbThreadLocalKeyInvalid;

Expand All @@ -49,7 +50,7 @@ void InitThreadLocalTaskKey() {
}

void EnsureThreadLocalTaskKeyInited() {
SbOnce(&s_once_task_flag, InitThreadLocalTaskKey);
pthread_once(&s_once_task_flag, InitThreadLocalTaskKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_task_key));
}

Expand All @@ -58,7 +59,7 @@ PendingTask* GetCurrentPendingTask() {
SbThreadGetLocalValue(s_thread_local_task_key));
}

ABSL_CONST_INIT SbOnceControl s_once_hash_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_hash_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_hash_key =
kSbThreadLocalKeyInvalid;

Expand All @@ -68,11 +69,11 @@ void InitThreadLocalHashKey() {
}

void EnsureThreadLocalHashKeyInited() {
SbOnce(&s_once_hash_flag, InitThreadLocalHashKey);
pthread_once(&s_once_hash_flag, InitThreadLocalHashKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_hash_key));
}

ABSL_CONST_INIT SbOnceControl s_once_tracker_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_tracker_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_tracker_key =
kSbThreadLocalKeyInvalid;

Expand All @@ -82,7 +83,7 @@ void InitThreadLocalTrackerKey() {
}

void EnsureThreadLocalTrackerKeyInited() {
SbOnce(&s_once_tracker_flag, InitThreadLocalTrackerKey);
pthread_once(&s_once_tracker_flag, InitThreadLocalTrackerKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_tracker_key));
}
#else
Expand Down
11 changes: 6 additions & 5 deletions base/task/scoped_set_task_priority_for_current_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#include "third_party/abseil-cpp/absl/base/attributes.h"

#if defined(STARBOARD)
#include <pthread.h>

#include "base/check_op.h"
#include "starboard/once.h"
#include "starboard/thread.h"
#endif

Expand All @@ -19,7 +20,7 @@ namespace internal {
namespace {

#if defined(STARBOARD)
ABSL_CONST_INIT SbOnceControl s_once_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid;

void InitThreadLocalKey() {
Expand All @@ -28,11 +29,11 @@ void InitThreadLocalKey() {
}

void EnsureThreadLocalKeyInited() {
SbOnce(&s_once_flag, InitThreadLocalKey);
pthread_once(&s_once_flag, InitThreadLocalKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));
}

ABSL_CONST_INIT SbOnceControl s_once_set_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_set_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_set_for_thread =
kSbThreadLocalKeyInvalid;
void InitThreadLocalBoolKey() {
Expand All @@ -41,7 +42,7 @@ void InitThreadLocalBoolKey() {
}

void EnsureThreadLocalBoolKeyInited() {
SbOnce(&s_once_set_flag, InitThreadLocalBoolKey);
pthread_once(&s_once_set_flag, InitThreadLocalBoolKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_set_for_thread));
}

Expand Down
7 changes: 4 additions & 3 deletions base/task/sequence_manager/sequence_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
#include "third_party/abseil-cpp/absl/types/optional.h"

#if defined(STARBOARD)
#include <pthread.h>

#include "base/check_op.h"
#include "starboard/once.h"
#include "starboard/thread.h"
#endif

Expand All @@ -49,7 +50,7 @@ namespace sequence_manager {
namespace {

#if defined(STARBOARD)
ABSL_CONST_INIT SbOnceControl s_once_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid;

void InitThreadLocalKey() {
Expand All @@ -58,7 +59,7 @@ void InitThreadLocalKey() {
}

void EnsureThreadLocalKeyInited() {
SbOnce(&s_once_flag, InitThreadLocalKey);
pthread_once(&s_once_flag, InitThreadLocalKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));
}

Expand Down
7 changes: 4 additions & 3 deletions base/task/sequenced_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
#include "third_party/abseil-cpp/absl/base/attributes.h"

#if defined(STARBOARD)
#include <pthread.h>

#include "base/check_op.h"
#include "starboard/once.h"
#include "starboard/thread.h"
#endif

Expand All @@ -22,7 +23,7 @@ namespace base {
namespace {

#if defined(STARBOARD)
ABSL_CONST_INIT SbOnceControl s_once_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid;

void InitThreadLocalKey() {
Expand All @@ -31,7 +32,7 @@ void InitThreadLocalKey() {
}

void EnsureThreadLocalKeyInited() {
SbOnce(&s_once_flag, InitThreadLocalKey);
pthread_once(&s_once_flag, InitThreadLocalKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));
}

Expand Down
7 changes: 4 additions & 3 deletions base/task/single_thread_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#include "third_party/abseil-cpp/absl/base/attributes.h"

#if defined(STARBOARD)
#include <pthread.h>

#include "base/check_op.h"
#include "starboard/once.h"
#include "starboard/thread.h"
#endif

Expand All @@ -27,7 +28,7 @@ namespace base {
namespace {

#if defined(STARBOARD)
ABSL_CONST_INIT SbOnceControl s_once_flag = SB_ONCE_INITIALIZER;
ABSL_CONST_INIT pthread_once_t s_once_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid;

void InitThreadLocalKey() {
Expand All @@ -36,7 +37,7 @@ void InitThreadLocalKey() {
}

void EnsureThreadLocalKeyInited() {
SbOnce(&s_once_flag, InitThreadLocalKey);
pthread_once(&s_once_flag, InitThreadLocalKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));
}
#else
Expand Down
Loading

0 comments on commit b0aceb8

Please sign in to comment.