Skip to content

Commit

Permalink
Make spinlock compatible with Starboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jellefoks committed Jan 10, 2024
1 parent 054063f commit a639e06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions third_party/abseil-cpp/absl/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ absl_source_set("spinlock_wait") {
":base_internal",
":core_headers",
":errno_saver",
"//starboard:starboard_headers_only",
]
visibility = [ "//third_party/abseil-cpp/absl/base:*" ]
}
Expand Down
13 changes: 13 additions & 0 deletions third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
//
// This file is a Posix-specific part of spinlock_wait.cc

#if defined(STARBOARD)
#include "starboard/thread.h"
#else
#include <sched.h>
#endif

#include <atomic>
#include <ctime>
Expand All @@ -29,6 +33,14 @@ ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockDelay)(
std::atomic<uint32_t>* /* lock_word */, uint32_t /* value */, int loop,
absl::base_internal::SchedulingMode /* mode */) {
absl::base_internal::ErrnoSaver errno_saver;
#if defined(STARBOARD)
if (loop == 0) {
} else if (loop == 1) {
SbThreadYield();
} else {
SbThreadSleep(loop);
}
#else
if (loop == 0) {
} else if (loop == 1) {
sched_yield();
Expand All @@ -38,6 +50,7 @@ ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockDelay)(
tm.tv_nsec = absl::base_internal::SpinLockSuggestedDelayNS(loop);
nanosleep(&tm, nullptr);
}
#endif
}

ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockWake)(
Expand Down

0 comments on commit a639e06

Please sign in to comment.