Skip to content

Commit

Permalink
Make absl::synchronization more 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 de7e625
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 2 additions & 0 deletions third_party/abseil-cpp/absl/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ absl_source_set("spinlock_wait") {
"internal/spinlock_akaros.inc",
"internal/spinlock_linux.inc",
"internal/spinlock_posix.inc",
"internal/spinlock_starboard.inc",
"internal/spinlock_wait.cc",
"internal/spinlock_win32.inc",
]
Expand All @@ -54,6 +55,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
46 changes: 46 additions & 0 deletions third_party/abseil-cpp/absl/base/internal/spinlock_starboard.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// This file is a Posix-specific part of spinlock_wait.cc

#if defined(STARBOARD)
#include "starboard/thread.h"

#include <atomic>
#include <ctime>

#include "absl/base/internal/errno_saver.h"
#include "absl/base/internal/scheduling_mode.h"
#include "absl/base/port.h"

extern "C" {

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 (loop == 0) {
} else if (loop == 1) {
SbThreadYield();
} else {
SbThreadSleep(loop);
}
}

ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(AbslInternalSpinLockWake)(
std::atomic<uint32_t>* /* lock_word */, bool /* all */) {}

} // extern "C"

#endif
2 changes: 1 addition & 1 deletion third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "absl/base/internal/spinlock_wait.h"

#if defined(STARBOARD)
#include "absl/base/internal/spinlock_posix.inc"
#include "absl/base/internal/spinlock_starboard.inc"
#elif defined(_WIN32)
#include "absl/base/internal/spinlock_win32.inc"
#elif defined(__linux__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
// Bionic supports all the futex operations we need even when some of the futex
// definitions are missing.
#define ABSL_INTERNAL_HAVE_FUTEX
#elif defined(__linux__) && defined(FUTEX_CLOCK_REALTIME)
#elif defined(__linux__) && defined(FUTEX_CLOCK_REALTIME) && !defined(STARBOARD)
// FUTEX_CLOCK_REALTIME requires Linux >= 2.6.28.
#define ABSL_INTERNAL_HAVE_FUTEX
#endif
Expand Down

0 comments on commit de7e625

Please sign in to comment.