diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 2132af2c83c4..b6a1f84338c0 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -21,6 +21,7 @@ permissions: {} jobs: lint: runs-on: ubuntu-latest + timeout-minutes: 15 steps: - name: Install clang-format Dependencies run: | diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d5e1c15b2bac..71b6278e1de0 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -74,6 +74,7 @@ jobs: github.event.label.name == 'runtest' || github.event.label.name == 'on_device' ) + timeout-minutes: 10 steps: - id: checkout uses: kaidokert/checkout@v3.5.999 @@ -148,6 +149,7 @@ jobs: runs-on: [self-hosted, linux-runner] permissions: packages: write + timeout-minutes: 30 steps: - name: Checkout files uses: kaidokert/checkout@v3.5.999 @@ -184,6 +186,7 @@ jobs: permissions: packages: write runs-on: [self-hosted, linux-runner] + timeout-minutes: 30 steps: - name: Checkout files uses: kaidokert/checkout@v3.5.999 @@ -231,6 +234,7 @@ jobs: # However, dind container ends up having / folder mounted on overlay # filesystem, whereas /__w which contains Cobalt source code is on tmpfs. TMPDIR: /__w/_temp + timeout-minutes: 60 steps: - name: Checkout uses: kaidokert/checkout@v3.5.999 @@ -367,6 +371,7 @@ jobs: HOME: /root COBALT_EVERGREEN_LOADER: ${{needs.initialize.outputs.evergreen_loader}} MODULAR_BUILD: ${{ inputs.modular && 1 || 0 }} + timeout-minutes: 90 steps: - name: Checkout uses: kaidokert/checkout@v3.5.999 diff --git a/.github/workflows/main_win.yaml b/.github/workflows/main_win.yaml index 146424bc2b74..d3ac0cfcb17e 100644 --- a/.github/workflows/main_win.yaml +++ b/.github/workflows/main_win.yaml @@ -61,6 +61,7 @@ jobs: github.event.label.name == 'runtest' || github.event.label.name == 'on_device' ) + timeout-minutes: 10 steps: - id: Checkout uses: kaidokert/checkout@v3.5.999 # Temporary version @@ -133,6 +134,7 @@ jobs: permissions: packages: write runs-on: windows-2019 + timeout-minutes: 120 steps: - name: Checkout files uses: kaidokert/checkout@v3.5.999 @@ -167,6 +169,7 @@ jobs: platform: ${{ fromJson(needs.initialize.outputs.platforms) }} include: ${{ fromJson(needs.initialize.outputs.includes) }} config: [devel, debug, qa, gold] + timeout-minutes: 90 steps: - name: Checkout uses: kaidokert/checkout@v3.5.999 @@ -204,6 +207,7 @@ jobs: include: ${{ fromJson(needs.initialize.outputs.includes) }} env: MODULAR_BUILD: ${{ inputs.modular && 1 || 0 }} + timeout-minutes: 90 steps: - name: Checkout uses: kaidokert/checkout@v3.5.999 diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 1b282e407929..9f4382462b0a 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -21,6 +21,7 @@ jobs: python-version: ['3.8', '3.11'] fail-fast: false runs-on: ${{ matrix.os }} + timeout-minutes: 15 steps: - name: Checkout uses: kaidokert/checkout@v3.5.999 diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index 4514e18291e0..0a4419ee8afc 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -29,6 +29,7 @@ jobs: # Needed to publish results and get a badge (see publish_results below). id-token: write + timeout-minutes: 15 steps: - name: "Checkout code" uses: actions/checkout@v3 diff --git a/base/logging.cc b/base/logging.cc index 7bf2c8cc1da6..7a42524f1ac7 100644 --- a/base/logging.cc +++ b/base/logging.cc @@ -49,7 +49,7 @@ #include "starboard/file.h" #include "starboard/system.h" typedef SbFile FileHandle; -typedef SbMutex MutexHandle; +typedef pthread_mutex_t MutexHandle; #else #if BUILDFLAG(IS_WIN) #include diff --git a/base/synchronization/condition_variable.h b/base/synchronization/condition_variable.h index 789427ebd8da..4c84bc200b25 100644 --- a/base/synchronization/condition_variable.h +++ b/base/synchronization/condition_variable.h @@ -70,8 +70,12 @@ #include "base/synchronization/lock.h" #if defined(STARBOARD) +#if SB_API_VERSION < 16 #include "starboard/condition_variable.h" #else +#include +#endif // SB_API_VERSION < 16 +#else #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) #include #endif @@ -118,8 +122,13 @@ class BASE_EXPORT ConditionVariable { private: #if defined(STARBOARD) +#if SB_API_VERSION < 16 SbConditionVariable condition_; SbMutex* user_mutex_; +#else + pthread_cond_t condition_; + pthread_mutex_t* user_mutex_; +#endif // SB_API_VERSION < 16 #elif BUILDFLAG(IS_WIN) CHROME_CONDITION_VARIABLE cv_; const raw_ptr srwlock_; diff --git a/base/synchronization/condition_variable_starboard.cc b/base/synchronization/condition_variable_starboard.cc index e8b243992c46..c46217e0490d 100644 --- a/base/synchronization/condition_variable_starboard.cc +++ b/base/synchronization/condition_variable_starboard.cc @@ -30,13 +30,34 @@ ConditionVariable::ConditionVariable(Lock* user_lock) user_lock_(user_lock) #endif { +#if SB_API_VERSION < 16 bool result = SbConditionVariableCreate(&condition_, user_mutex_); DCHECK(result); +#else +#if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) + pthread_condattr_t attribute; + pthread_condattr_init(&attribute); + pthread_condattr_setclock(&attribute, CLOCK_MONOTONIC); + + int result = pthread_cond_init(&condition_, &attribute); + DCHECK(result == 0); + + pthread_condattr_destroy(&attribute); +#else + int result = pthread_cond_init(&condition_, nullptr); + DCHECK(result == 0); +#endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) +#endif // SB_API_VERSION < 16 } ConditionVariable::~ConditionVariable() { +#if SB_API_VERSION < 16 bool result = SbConditionVariableDestroy(&condition_); DCHECK(result); +#else + int result = pthread_cond_destroy(&condition_); + DCHECK(result == 0); +#endif // SB_API_VERSION < 16 } void ConditionVariable::Wait() { @@ -48,9 +69,14 @@ void ConditionVariable::Wait() { #if DCHECK_IS_ON() user_lock_->CheckHeldAndUnmark(); #endif - SbConditionVariableResult result = +#if SB_API_VERSION < 16 + SbConditionVariableResult result = SbConditionVariableWait(&condition_, user_mutex_); DCHECK(SbConditionVariableIsSignaled(result)); +#else + int result = pthread_cond_wait(&condition_, user_mutex_); + DCHECK(result == 0); +#endif // SB_API_VERSION < 16 #if DCHECK_IS_ON() user_lock_->CheckUnheldAndMark(); #endif @@ -66,22 +92,48 @@ void ConditionVariable::TimedWait(const TimeDelta& max_time) { #if DCHECK_IS_ON() user_lock_->CheckHeldAndUnmark(); #endif +#if SB_API_VERSION < 16 SbConditionVariableResult result = SbConditionVariableWaitTimed(&condition_, user_mutex_, duration); DCHECK_NE(kSbConditionVariableFailed, result); +#else +#if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) + int64_t timeout_time_usec = starboard::CurrentMonotonicTime(); +#else + int64_t timeout_time_usec = starboard::CurrentPosixTime(); +#endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) + timeout_time_usec += max_time.InMicroseconds(); + + struct timespec timeout; + timeout.tv_sec = timeout_time_usec / 1000'000; + timeout.tv_nsec = (timeout_time_usec % 1000'000) * 1000; + + int result = pthread_cond_timedwait(&condition_, user_mutex_, &timeout); + DCHECK(result == 0 || result == ETIMEDOUT); +#endif #if DCHECK_IS_ON() user_lock_->CheckUnheldAndMark(); #endif } void ConditionVariable::Broadcast() { +#if SB_API_VERSION < 16 bool result = SbConditionVariableBroadcast(&condition_); DCHECK(result); +#else + int result = pthread_cond_broadcast(&condition_); + DCHECK(result == 0); +#endif // SB_API_VERSION < 16 } void ConditionVariable::Signal() { +#if SB_API_VERSION < 16 bool result = SbConditionVariableSignal(&condition_); DCHECK(result); +#else + int result = pthread_cond_signal(&condition_); + DCHECK(result == 0); +#endif // SB_API_VERSION < 16 } } // namespace base diff --git a/base/synchronization/lock_impl.h b/base/synchronization/lock_impl.h index 815e3add9d0a..76b692a80d4c 100644 --- a/base/synchronization/lock_impl.h +++ b/base/synchronization/lock_impl.h @@ -12,7 +12,11 @@ #include "build/build_config.h" #if defined(STARBOARD) +#if SB_API_VERSION < 16 #include "starboard/common/mutex.h" +#else +#include +#endif #include "base/check_op.h" #elif BUILDFLAG(IS_WIN) #include "base/win/windows_types.h" @@ -49,7 +53,11 @@ class BASE_EXPORT LockImpl { friend class base::win::internal::ScopedHandleVerifier; #if defined(STARBOARD) +#if SB_API_VERSION < 16 using NativeHandle = SbMutex; +#else + using NativeHandle = pthread_mutex_t; +#endif // SB_API_VERSION < 16 #elif BUILDFLAG(IS_WIN) using NativeHandle = CHROME_SRWLOCK; #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) @@ -100,14 +108,24 @@ void LockImpl::Lock() { #if defined(STARBOARD) bool LockImpl::Try() { +#if SB_API_VERSION < 16 SbMutexResult result = SbMutexAcquireTry(&native_handle_); DCHECK_NE(kSbMutexDestroyed, result); return SbMutexIsSuccess(result); +#else + int result = pthread_mutex_trylock(&native_handle_); + return result == 0; +#endif // SB_API_VERSION < 16 } void LockImpl::Unlock() { +#if SB_API_VERSION < 16 bool result = SbMutexRelease(&native_handle_); DCHECK(result); +#else + int result = pthread_mutex_unlock(&native_handle_); + DCHECK(result == 0); +#endif //SB_API_VERSION < 16 } #elif BUILDFLAG(IS_WIN) bool LockImpl::Try() { diff --git a/base/synchronization/lock_impl_starboard.cc b/base/synchronization/lock_impl_starboard.cc index feba3f9fcb44..545ba4c9646b 100644 --- a/base/synchronization/lock_impl_starboard.cc +++ b/base/synchronization/lock_impl_starboard.cc @@ -15,24 +15,42 @@ #include "base/synchronization/lock_impl.h" #include "base/check_op.h" -#include "starboard/common/mutex.h" + +#if SB_API_VERSION < 16 +#include "starboard/mutex.h" +#endif // SB_API_VERSION < 16 namespace base { namespace internal { LockImpl::LockImpl() { +#if SB_API_VERSION < 16 bool result = SbMutexCreate(&native_handle_); DCHECK(result); +#else + int result = pthread_mutex_init(&native_handle_, nullptr); + DCHECK_EQ(result, 0); +#endif // SB_API_VERSION < 16 } LockImpl::~LockImpl() { +#if SB_API_VERSION < 16 bool result = SbMutexDestroy(&native_handle_); DCHECK(result); +#else + int result = pthread_mutex_destroy(&native_handle_); + DCHECK_EQ(result, 0); +#endif // SB_API_VERSION < 16 } void LockImpl::LockInternal() { +#if SB_API_VERSION < 16 SbMutexResult result = SbMutexAcquire(&native_handle_); DCHECK_NE(kSbMutexDestroyed, result); +#else + int result = pthread_mutex_lock(&native_handle_); + DCHECK_EQ(result, 0); +#endif // SB_API_VERSION < 16 } } // namespace internal diff --git a/chrome/updater/unzipper.cc b/chrome/updater/unzipper.cc index 1614606481ea..f3c735fe6708 100644 --- a/chrome/updater/unzipper.cc +++ b/chrome/updater/unzipper.cc @@ -10,7 +10,6 @@ #include "base/files/file_path.h" #include "base/logging.h" #include "base/time/time.h" -#include "starboard/common/time.h" #include "third_party/zlib/google/zip.h" namespace cobalt { @@ -25,10 +24,10 @@ class UnzipperImpl : public update_client::Unzipper { void Unzip(const base::FilePath& zip_path, const base::FilePath& output_path, UnzipCompleteCallback callback) override { - int64_t time_before_unzip = starboard::CurrentMonotonicTime(); + int64_t time_before_unzip = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); std::move(callback).Run(zip::Unzip(zip_path, output_path)); int64_t time_unzip_took_usec = - starboard::CurrentMonotonicTime() - time_before_unzip; + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - time_before_unzip; LOG(INFO) << "Unzip file path = " << zip_path; LOG(INFO) << "output_path = " << output_path; LOG(INFO) << "Unzip took " @@ -39,10 +38,10 @@ class UnzipperImpl : public update_client::Unzipper { #if defined(IN_MEMORY_UPDATES) void Unzip(const std::string& zip_str, const base::FilePath& output_path, UnzipCompleteCallback callback) override { - int64_t time_before_unzip = starboard::CurrentMonotonicTime(); + int64_t time_before_unzip = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); std::move(callback).Run(zip::Unzip(zip_str, output_path)); int64_t time_unzip_took_usec = - starboard::CurrentMonotonicTime() - time_before_unzip; + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - time_before_unzip; LOG(INFO) << "Unzip from string"; LOG(INFO) << "output_path = " << output_path; LOG(INFO) << "Unzip took " diff --git a/cobalt/base/localized_strings.cc b/cobalt/base/localized_strings.cc index c07abb3911b1..46f7bff56305 100644 --- a/cobalt/base/localized_strings.cc +++ b/cobalt/base/localized_strings.cc @@ -20,7 +20,6 @@ #include "base/files/file_util.h" #include "base/logging.h" #include "base/optional.h" -#include "starboard/common/file.h" #include "starboard/system.h" #include "starboard/types.h" diff --git a/cobalt/bindings/testing/date_bindings_test.cc b/cobalt/bindings/testing/date_bindings_test.cc index d96ddbfadbed..86683eedfdf1 100644 --- a/cobalt/bindings/testing/date_bindings_test.cc +++ b/cobalt/bindings/testing/date_bindings_test.cc @@ -17,7 +17,6 @@ #include "cobalt/bindings/testing/bindings_test_base.h" #include "cobalt/bindings/testing/interface_with_date.h" #include "starboard/client_porting/eztime/eztime.h" -#include "starboard/common/time.h" #include "starboard/time_zone.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -79,7 +78,7 @@ TEST_F(DateBindingsTest, PosixEpoch) { EvaluateScript("Date.now();", &result); auto js_now_ms = std::stoll(result); auto posix_now_ms = - starboard::CurrentPosixTime() / base::Time::kMicrosecondsPerMillisecond; + (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds(); EXPECT_LT(std::abs(posix_now_ms - js_now_ms), 1000); } @@ -106,8 +105,8 @@ TEST_F(DateBindingsTest, StarboardTimeZone) { } TEST_F(DateBindingsTest, TimezoneOffset) { - EzTimeT ezttnow = static_cast(starboard::CurrentPosixTime() / - base::Time::kMicrosecondsPerSecond); + EzTimeT ezttnow = static_cast( + (base::Time::Now() - base::Time::UnixEpoch()).InSeconds()); EzTimeExploded ez_exploded_local; EzTimeTExplodeLocal(&ezttnow, &ez_exploded_local); // ez_exploded_local is already local time, use UTC method to convert to diff --git a/cobalt/browser/browser_module.cc b/cobalt/browser/browser_module.cc index 235c955924c7..b7e86fcf9baf 100644 --- a/cobalt/browser/browser_module.cc +++ b/cobalt/browser/browser_module.cc @@ -61,7 +61,6 @@ #include "cobalt/web/navigator_ua_data.h" #include "starboard/atomic.h" #include "starboard/common/string.h" -#include "starboard/common/time.h" #include "starboard/configuration.h" #include "starboard/extension/graphics.h" #include "starboard/system.h" @@ -89,7 +88,7 @@ NonTrivialGlobalVariables::NonTrivialGlobalVariables() { SbAtomicNoBarrier_Exchange64( last_render_timestamp, static_cast( - starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime()))); + base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds(); } base::LazyInstance::DestructorAtExit diff --git a/cobalt/browser/loader_app_metrics.cc b/cobalt/browser/loader_app_metrics.cc index fcff39305fe6..cee78353f713 100644 --- a/cobalt/browser/loader_app_metrics.cc +++ b/cobalt/browser/loader_app_metrics.cc @@ -103,6 +103,13 @@ void RecordLoaderAppMetrics( RecordLoaderAppTimeMetrics(metrics_extension); RecordLoaderAppSpaceMetrics(metrics_extension); } + if (metrics_extension->version >= 3) { + base::UmaHistogramEnumeration( + "Cobalt.LoaderApp.SlotSelectionStatus", + metrics_extension->GetSlotSelectionStatus()); + LOG(INFO) << "Recorded sample for " + << "Cobalt.LoaderApp.SlotSelectionStatus"; + } } } diff --git a/cobalt/browser/web_module.h b/cobalt/browser/web_module.h index 82aa422acd7d..c42f71edf7f7 100644 --- a/cobalt/browser/web_module.h +++ b/cobalt/browser/web_module.h @@ -59,7 +59,6 @@ #include "cobalt/web/environment_settings.h" #include "cobalt/web/user_agent_platform_info.h" #include "cobalt/webdriver/session_driver.h" -#include "starboard/common/atomic.h" #include "url/gurl.h" #if defined(ENABLE_DEBUGGER) diff --git a/cobalt/build/cobalt_configuration.py b/cobalt/build/cobalt_configuration.py index 0926b610b98b..3a820e4334c8 100644 --- a/cobalt/build/cobalt_configuration.py +++ b/cobalt/build/cobalt_configuration.py @@ -32,6 +32,7 @@ 'All/SequenceManagerTest.DelayedTasksDontBadlyStarveNonDelayedWork_SameQueue/WithMockTaskRunner', # pylint: disable=line-too-long 'All/SequenceManagerTest.SweepCanceledDelayedTasks_ManyTasks/WithMessagePump', # pylint: disable=line-too-long 'All/SequenceManagerTest.SweepCanceledDelayedTasks_ManyTasks/WithMessagePumpAlignedWakeUps', # pylint: disable=line-too-long + 'All/SequenceManagerTest.SweepCanceledDelayedTasks_ManyTasks/WithMockTaskRunner', # pylint: disable=line-too-long # TODO: b/329507754 - Flaky after recent rebase. 'ScopedBlockingCallIOJankMonitoringTest.MultiThreadedOverlappedWindows', 'TaskEnvironmentTest.MultiThreadedMockTimeAndThreadPoolQueuedMode' diff --git a/cobalt/dom/html_element.cc b/cobalt/dom/html_element.cc index 58b124b988bb..1d9d335c8f14 100644 --- a/cobalt/dom/html_element.cc +++ b/cobalt/dom/html_element.cc @@ -65,7 +65,6 @@ #include "cobalt/loader/resource_cache.h" #include "cobalt/math/clamp.h" #include "cobalt/web/csp_delegate.h" -#include "starboard/common/time.h" #include "third_party/icu/source/common/unicode/uchar.h" #include "third_party/icu/source/common/unicode/utf8.h" @@ -94,7 +93,10 @@ const char* kPerformanceResourceTimingInitiatorType = "img"; void UiNavCallbackHelper(scoped_refptr task_runner, base::Callback callback) { task_runner->PostTask( - FROM_HERE, base::Bind(callback, starboard::CurrentMonotonicTime())); + FROM_HERE, + base::Bind( + callback, + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())); } struct NonTrivialStaticFields { @@ -1498,7 +1500,8 @@ void HTMLElement::UpdateUiNavigationFocus() { // Focus call for this HTMLElement as a result of OnUiNavBlur / OnUiNavFocus // callbacks that result from initiating the UI navigation focus change. if (node_document()->TrySetUiNavFocusElement( - html_element, starboard::CurrentMonotonicTime())) { + html_element, + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) { html_element->ui_nav_item_->Focus(); } break; @@ -2300,7 +2303,8 @@ void HTMLElement::ReleaseUiNavigationItem() { node_document()->set_ui_nav_needs_layout(true); if (node_document()->ui_nav_focus_element() == this) { if (node_document()->TrySetUiNavFocusElement( - nullptr, starboard::CurrentMonotonicTime())) { + nullptr, (base::TimeTicks::Now() - base::TimeTicks()) + .InMicroseconds())) { ui_nav_item_->UnfocusAll(); } } diff --git a/cobalt/dom/html_link_element.cc b/cobalt/dom/html_link_element.cc index 70dbca13bf7e..04bc36c24a98 100644 --- a/cobalt/dom/html_link_element.cc +++ b/cobalt/dom/html_link_element.cc @@ -32,7 +32,6 @@ #include "cobalt/dom/window.h" #include "cobalt/network/disk_cache/resource_type.h" #include "cobalt/web/csp_delegate.h" -#include "starboard/common/time.h" #include "url/gurl.h" namespace cobalt { @@ -319,11 +318,13 @@ void HTMLLinkElement::OnSplashscreenLoaded(Document* document, void HTMLLinkElement::OnStylesheetLoaded(Document* document, const std::string& content) { - auto before_parse_micros = starboard::CurrentMonotonicTime(); + auto before_parse_micros = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); scoped_refptr css_style_sheet = document->html_element_context()->css_parser()->ParseStyleSheet( content, base::SourceLocation(href(), 1, 1)); - auto after_parse_micros = starboard::CurrentMonotonicTime(); + auto after_parse_micros = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); auto css_kb = content.length() / 1000; // Only measure non-trivial CSS sizes and ignore non-HTTP schemes (e.g., // file://), which are primarily used for debug purposes. diff --git a/cobalt/dom/html_style_element.cc b/cobalt/dom/html_style_element.cc index cfeb76d91ef6..2dd705f06865 100644 --- a/cobalt/dom/html_style_element.cc +++ b/cobalt/dom/html_style_element.cc @@ -22,7 +22,6 @@ #include "cobalt/dom/document.h" #include "cobalt/dom/html_element_context.h" #include "cobalt/web/csp_delegate.h" -#include "starboard/common/time.h" namespace cobalt { namespace dom { @@ -92,11 +91,13 @@ void HTMLStyleElement::Process() { const std::string& text = content.value_or(base::EmptyString()); if (bypass_csp || csp_delegate->AllowInline(web::CspDelegate::kStyle, inline_style_location_, text)) { - auto before_parse_micros = starboard::CurrentMonotonicTime(); + auto before_parse_micros = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); scoped_refptr css_style_sheet = document->html_element_context()->css_parser()->ParseStyleSheet( text, inline_style_location_); - auto after_parse_micros = starboard::CurrentMonotonicTime(); + auto after_parse_micros = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); auto css_kb = text.length() / 1000; // Only measure non-trivial css sizes and inlined HTML style elements. if (css_kb > 0 && diff --git a/cobalt/dom/performance_lifecycle_timing.cc b/cobalt/dom/performance_lifecycle_timing.cc index 779e69af1535..14d7f7753180 100644 --- a/cobalt/dom/performance_lifecycle_timing.cc +++ b/cobalt/dom/performance_lifecycle_timing.cc @@ -16,7 +16,6 @@ #include "cobalt/dom/performance_lifecycle_timing.h" #include "cobalt/dom/performance.h" -#include "starboard/common/time.h" namespace cobalt { namespace dom { @@ -45,8 +44,8 @@ DOMHighResTimeStamp ConvertMonotonicTimestampToDOMHiResTimeStamp( const DOMHighResTimeStamp time_origin, int64_t monotonic_time) { // Current delta from Windows epoch. int64_t time_delta = - starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime()) - - starboard::CurrentMonotonicTime(); + base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds() - + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); base::Time base_time = base::Time::FromDeltaSinceWindowsEpoch( base::TimeDelta::FromMicroseconds(time_delta + monotonic_time)); return ClampTimeStampMinimumResolution( diff --git a/cobalt/dom/serialized_algorithm_runner.h b/cobalt/dom/serialized_algorithm_runner.h index d1e00276fe6b..c9fafc3bac1d 100644 --- a/cobalt/dom/serialized_algorithm_runner.h +++ b/cobalt/dom/serialized_algorithm_runner.h @@ -31,7 +31,6 @@ #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" #include "base/trace_event/trace_event.h" -#include "starboard/common/time.h" namespace cobalt { namespace dom { @@ -92,7 +91,8 @@ class SerializedAlgorithmRunner { // Crash if we are trying to re-acquire again on the same thread. CHECK(!pthread_equal(acquired_thread_id_, pthread_self())); - int64_t start_usec = starboard::CurrentMonotonicTime(); + int64_t start_usec = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); int64_t wait_interval_usec = 1 * base::Time::kMicrosecondsPerMillisecond; constexpr int64_t kMaxWaitIntervalUsec = @@ -108,8 +108,10 @@ class SerializedAlgorithmRunner { wait_interval_usec = std::min(wait_interval_usec * 2, kMaxWaitIntervalUsec); // Crash if we've been waiting for too long (1 second). - CHECK_LT(starboard::CurrentMonotonicTime() - start_usec, - 1 * base::Time::kMicrosecondsPerSecond); + CHECK_LT( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - + start_usec, + 1 * base::Time::kMicrosecondsPerSecond); } acquired_thread_id_ = pthread_self(); } diff --git a/cobalt/dom/source_buffer_metrics.cc b/cobalt/dom/source_buffer_metrics.cc index a8f9e209fd6c..3587cd537457 100644 --- a/cobalt/dom/source_buffer_metrics.cc +++ b/cobalt/dom/source_buffer_metrics.cc @@ -22,7 +22,6 @@ #include "cobalt/base/statistics.h" #include "starboard/common/once.h" #include "starboard/common/string.h" -#include "starboard/common/time.h" #include "starboard/types.h" namespace cobalt { @@ -79,7 +78,8 @@ void SourceBufferMetrics::StartTracking(SourceBufferMetricsAction action) { wall_start_time_ = clock_->NowTicks(); #if !defined(COBALT_BUILD_TYPE_GOLD) - thread_start_time_ = starboard::CurrentMonotonicThreadTime(); + thread_start_time_ = + (base::ThreadTicks::Now() - base::ThreadTicks()).InMicroseconds(); #endif // !defined(COBALT_BUILD_TYPE_GOLD) } @@ -101,7 +101,8 @@ void SourceBufferMetrics::EndTracking(SourceBufferMetricsAction action, #if !defined(COBALT_BUILD_TYPE_GOLD) int64_t thread_duration = - starboard::CurrentMonotonicThreadTime() - thread_start_time_; + (base::ThreadTicks::Now() - base::ThreadTicks()).InMicroseconds() - + thread_start_time_; total_wall_time_ += wall_duration.InMicroseconds(); total_thread_time_ += thread_duration; diff --git a/cobalt/loader/net_fetcher.h b/cobalt/loader/net_fetcher.h index e159ebfd5038..8daa055be390 100644 --- a/cobalt/loader/net_fetcher.h +++ b/cobalt/loader/net_fetcher.h @@ -31,7 +31,6 @@ #include "cobalt/network/disk_cache/resource_type.h" #include "cobalt/network/network_module.h" #include "net/http/http_request_headers.h" -#include "starboard/common/atomic.h" #include "url/gurl.h" namespace cobalt { diff --git a/cobalt/media/decoder_buffer_allocator.h b/cobalt/media/decoder_buffer_allocator.h index c1dfd85cca4c..e205a59f0e5f 100644 --- a/cobalt/media/decoder_buffer_allocator.h +++ b/cobalt/media/decoder_buffer_allocator.h @@ -26,7 +26,6 @@ #include "cobalt/media/starboard_memory_allocator.h" #include "media/base/decoder_buffer.h" #include "media/base/video_decoder_config.h" -#include "starboard/common/atomic.h" #include "starboard/media.h" namespace cobalt { diff --git a/cobalt/media/sandbox/format_guesstimator.cc b/cobalt/media/sandbox/format_guesstimator.cc index b92512a33aca..72a2923ba633 100644 --- a/cobalt/media/sandbox/format_guesstimator.cc +++ b/cobalt/media/sandbox/format_guesstimator.cc @@ -37,7 +37,6 @@ #include "media/filters/chunk_demuxer.h" #include "net/base/filename_util.h" #include "net/base/url_util.h" -#include "starboard/common/file.h" #include "starboard/common/string.h" #include "starboard/memory.h" #include "starboard/types.h" diff --git a/cobalt/media/sandbox/web_media_player_sandbox.cc b/cobalt/media/sandbox/web_media_player_sandbox.cc index 71cefdbd106b..246c2764dc1c 100644 --- a/cobalt/media/sandbox/web_media_player_sandbox.cc +++ b/cobalt/media/sandbox/web_media_player_sandbox.cc @@ -34,7 +34,6 @@ #include "cobalt/render_tree/image.h" #include "media/base/timestamp_constants.h" #include "media/filters/chunk_demuxer.h" -#include "starboard/common/file.h" #include "starboard/event.h" #include "starboard/log.h" #include "starboard/system.h" diff --git a/cobalt/media_session/media_session.h b/cobalt/media_session/media_session.h index ec9598fb3dc4..33d7b6dfd8b8 100644 --- a/cobalt/media_session/media_session.h +++ b/cobalt/media_session/media_session.h @@ -31,7 +31,6 @@ #include "cobalt/script/callback_function.h" #include "cobalt/script/script_value.h" #include "cobalt/script/wrappable.h" -#include "starboard/common/time.h" namespace cobalt { namespace media_session { @@ -97,7 +96,7 @@ class MediaSession : public script::Wrappable { // Returns a time representing right now - may be overridden for testing. virtual int64_t GetMonotonicNow() const { - return starboard::CurrentMonotonicTime(); + return (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); } ActionMap action_map_; diff --git a/cobalt/media_session/media_session_client.cc b/cobalt/media_session/media_session_client.cc index ad93e31de6af..5babc10a60c6 100644 --- a/cobalt/media_session/media_session_client.cc +++ b/cobalt/media_session/media_session_client.cc @@ -22,7 +22,6 @@ #include "base/logging.h" #include "cobalt/media_session/media_image.h" #include "cobalt/script/sequence.h" -#include "starboard/common/time.h" namespace cobalt { namespace media_session { @@ -70,7 +69,8 @@ void GuessMediaPositionState(MediaSessionState* session_state, position_state.set_position((*guess_player)->GetCurrentTime()); *session_state = MediaSessionState( - session_state->metadata(), starboard::CurrentMonotonicTime(), + session_state->metadata(), + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(), position_state, session_state->actual_playback_state(), session_state->available_actions()); } diff --git a/cobalt/media_session/media_session_state.h b/cobalt/media_session/media_session_state.h index 09b48aa57a08..bcab1565a1e4 100644 --- a/cobalt/media_session/media_session_state.h +++ b/cobalt/media_session/media_session_state.h @@ -23,7 +23,6 @@ #include "cobalt/media_session/media_position_state.h" #include "cobalt/media_session/media_session_action.h" #include "cobalt/media_session/media_session_playback_state.h" -#include "starboard/common/time.h" namespace cobalt { namespace media_session { @@ -61,11 +60,12 @@ class MediaSessionState { // https://wicg.github.io/mediasession/#current-playback-position // Returns the position int64_t current_playback_position() const { - return GetCurrentPlaybackPosition(starboard::CurrentMonotonicTime()); + return GetCurrentPlaybackPosition( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds()); } // Returns the position of the current playback, given the current time. - // This may be used for testing without calling |CurrentMonotonicTime|. + // This may be used for testing without calling |base::TimeTicks::Now|. int64_t GetCurrentPlaybackPosition(int64_t monotonic_now) const; // Returns a coefficient of the current playback rate. e.g. 1.0 is normal diff --git a/cobalt/media_session/media_session_test.cc b/cobalt/media_session/media_session_test.cc index ba3f56d9730f..a672f69a2592 100644 --- a/cobalt/media_session/media_session_test.cc +++ b/cobalt/media_session/media_session_test.cc @@ -29,7 +29,6 @@ #include "cobalt/script/script_value.h" #include "cobalt/script/testing/fake_script_value.h" #include "cobalt/script/wrappable.h" -#include "starboard/common/time.h" #include "starboard/extension/media_session.h" #include "starboard/thread.h" #include "testing/gmock/include/gmock/gmock.h" diff --git a/cobalt/network/custom/url_fetcher_core.cc b/cobalt/network/custom/url_fetcher_core.cc index 6cebf8565548..b10656ed6834 100644 --- a/cobalt/network/custom/url_fetcher_core.cc +++ b/cobalt/network/custom/url_fetcher_core.cc @@ -30,7 +30,6 @@ #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_throttler_manager.h" -#include "starboard/common/time.h" #include "starboard/types.h" #include "url/origin.h" @@ -546,13 +545,14 @@ void URLFetcherCore::OnReadCompleted(URLRequest* request, int bytes_read) { #if defined(STARBOARD) // Prime it to the current time so it is only called after the loop, or every // time when the loop takes |kInformDownloadProgressIntervalUsec|. - int64_t download_progress_informed_at = starboard::CurrentMonotonicTime(); + int64_t download_progress_informed_at = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); bool did_read_after_inform_download_progress = false; while (bytes_read > 0) { current_response_bytes_ += bytes_read; did_read_after_inform_download_progress = true; - auto now = starboard::CurrentMonotonicTime(); + auto now = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); if (now - download_progress_informed_at > kInformDownloadProgressIntervalUsec) { InformDelegateDownloadProgress(); diff --git a/cobalt/network/dial/dial_system_config_starboard.cc b/cobalt/network/dial/dial_system_config_starboard.cc index 35d20f745213..c0fa89cea05c 100644 --- a/cobalt/network/dial/dial_system_config_starboard.cc +++ b/cobalt/network/dial/dial_system_config_starboard.cc @@ -14,9 +14,9 @@ #include +#include "base/files/file.h" #include "base/logging.h" #include "cobalt/network/dial/dial_system_config.h" -#include "starboard/common/file.h" #include "starboard/configuration_constants.h" #include "starboard/system.h" @@ -80,28 +80,26 @@ std::string DialSystemConfig::GeneratePlatformUuid() { path.append(kSbFileSepString); path.append(kInAppDialUuidFilename); - bool created; - SbFileError error; - starboard::ScopedFile file(path.c_str(), - kSbFileOpenAlways | kSbFileRead | kSbFileWrite, - &created, &error); - if (error != kSbFileOk) { + base::File file(base::FilePath(path), base::File::FLAG_OPEN_ALWAYS | + base::File::FLAG_READ | + base::File::FLAG_WRITE); + if (!file.IsValid()) { LOG(ERROR) << "Unable to open or create " << path; return GenerateRandomUuid(); } char uuid_buffer[kUuidSizeBytes]; - int bytes_read = file.ReadAll(uuid_buffer, kUuidSizeBytes); + int bytes_read = file.ReadAtCurrentPos(uuid_buffer, kUuidSizeBytes); if (bytes_read == kUuidSizeBytes) { return std::string(uuid_buffer, bytes_read); } - file.Truncate(0); + file.SetLength(0); std::string uuid = GenerateRandomUuid(); - int bytes_written = file.WriteAll(uuid.data(), uuid.size()); + int bytes_written = file.WriteAtCurrentPos(uuid.data(), uuid.size()); if (bytes_written != uuid.size()) { LOG(ERROR) << "Unable to store device UUID to " << path; diff --git a/cobalt/network/disk_cache/resource_type.h b/cobalt/network/disk_cache/resource_type.h index d3283c86bbe3..37b2bd7b38ff 100644 --- a/cobalt/network/disk_cache/resource_type.h +++ b/cobalt/network/disk_cache/resource_type.h @@ -17,7 +17,6 @@ #include -#include "starboard/common/atomic.h" #include "starboard/types.h" namespace cobalt { diff --git a/cobalt/network/network_module.h b/cobalt/network/network_module.h index a989f15b31f5..20e65e09c827 100644 --- a/cobalt/network/network_module.h +++ b/cobalt/network/network_module.h @@ -36,7 +36,6 @@ // don't have StreamListenSocket. #include "cobalt/network/dial/dial_service.h" #endif -#include "starboard/common/atomic.h" namespace base { class WaitableEvent; diff --git a/cobalt/persistent_storage/persistent_settings_test.cc b/cobalt/persistent_storage/persistent_settings_test.cc index ad05d125fcfa..94026ba072cd 100644 --- a/cobalt/persistent_storage/persistent_settings_test.cc +++ b/cobalt/persistent_storage/persistent_settings_test.cc @@ -17,9 +17,9 @@ #include #include +#include "base/files/file_util.h" #include "base/test/task_environment.h" #include "base/values.h" -#include "starboard/common/file.h" #include "starboard/configuration_constants.h" #include "testing/gtest/include/gtest/gtest.h" @@ -46,13 +46,15 @@ class PersistentSettingTest : public testing::Test { } void SetUp() final { - starboard::SbFileDeleteRecursive(persistent_settings_file_.c_str(), true); + base::DeletePathRecursively( + base::FilePath(persistent_settings_file_.c_str())); persistent_settings_ = std::make_unique(kPersistentSettingsJson); } void TearDown() final { - starboard::SbFileDeleteRecursive(persistent_settings_file_.c_str(), true); + base::DeletePathRecursively( + base::FilePath(persistent_settings_file_.c_str())); } void Fence(const base::Location& location) { diff --git a/cobalt/renderer/backend/graphics_system_test.cc b/cobalt/renderer/backend/graphics_system_test.cc index 62297535c097..0823b720f8de 100644 --- a/cobalt/renderer/backend/graphics_system_test.cc +++ b/cobalt/renderer/backend/graphics_system_test.cc @@ -22,7 +22,6 @@ #include "base/time/time.h" #include "cobalt/renderer/backend/default_graphics_system.h" #include "cobalt/renderer/backend/graphics_context.h" -#include "starboard/common/time.h" #include "starboard/log.h" #include "testing/gtest/include/gtest/gtest.h" @@ -45,13 +44,14 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsSystemCanBeInitializedOften) { graphics_system = CreateDefaultGraphicsSystem(); graphics_system.reset(); - int64_t start = starboard::CurrentMonotonicTime(); + int64_t start = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); for (int i = 0; i < kReferenceCount; ++i) { graphics_system = CreateDefaultGraphicsSystem(); graphics_system.reset(); } int64_t time_per_initialization_usec = - (starboard::CurrentMonotonicTime() - start) / kReferenceCount; + ((base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - start) / + kReferenceCount; LOG(INFO) << "Measured duration " << time_per_initialization_usec / base::Time::kMicrosecondsPerMillisecond @@ -63,11 +63,11 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsSystemCanBeInitializedOften) { std::max(3 * time_per_initialization_usec, 250 * base::Time::kMicrosecondsPerMillisecond); - int64_t last = starboard::CurrentMonotonicTime(); + int64_t last = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); for (int i = 0; i < 20; ++i) { graphics_system = CreateDefaultGraphicsSystem(); graphics_system.reset(); - int64_t now = starboard::CurrentMonotonicTime(); + int64_t now = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); int64_t elapsed_time_usec = now - last; LOG(INFO) << "Test duration " << elapsed_time_usec / base::Time::kMicrosecondsPerMillisecond @@ -90,7 +90,7 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) { graphics_context.reset(); graphics_system.reset(); - int64_t start = starboard::CurrentMonotonicTime(); + int64_t start = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); for (int i = 0; i < kReferenceCount; ++i) { graphics_system = CreateDefaultGraphicsSystem(); graphics_context = graphics_system->CreateGraphicsContext(); @@ -100,7 +100,8 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) { } int64_t time_per_initialization_usec = base::Time::kMicrosecondsPerMillisecond + - (starboard::CurrentMonotonicTime() - start) / kReferenceCount; + ((base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - start) / + kReferenceCount; LOG(INFO) << "Measured duration " << time_per_initialization_usec / base::Time::kMicrosecondsPerMillisecond @@ -112,7 +113,7 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) { std::max(3 * time_per_initialization_usec, 250 * base::Time::kMicrosecondsPerMillisecond); - int64_t last = starboard::CurrentMonotonicTime(); + int64_t last = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); for (int i = 0; i < 20; ++i) { graphics_system = CreateDefaultGraphicsSystem(); graphics_context = graphics_system->CreateGraphicsContext(); @@ -120,7 +121,7 @@ TEST(GraphicsSystemTest, FLAKY_GraphicsContextCanBeInitializedOften) { graphics_context.reset(); graphics_system.reset(); - int64_t now = starboard::CurrentMonotonicTime(); + int64_t now = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); int64_t elapsed_time_usec = now - last; LOG(INFO) << "Test duration " << elapsed_time_usec / base::Time::kMicrosecondsPerMillisecond diff --git a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkMutex_starboard.h b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkMutex_starboard.h index cb285f19340e..af9d1018ecf8 100644 --- a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkMutex_starboard.h +++ b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkMutex_starboard.h @@ -87,8 +87,7 @@ class SkMutex : public SkBaseMutex { ~SkMutex() { pthread_mutex_destroy(&mutex_); } }; -#define SK_BASE_MUTEX_INIT \ - { SB_MUTEX_INITIALIZER } +#define SK_BASE_MUTEX_INIT {PTHREAD_MUTEX_INITIALIZER} // Using POD-style initialization prevents the generation of a static // initializer. diff --git a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc index 1e11ae0bbbf7..1ac140e2884b 100644 --- a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc +++ b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkTime_cobalt.cc @@ -16,7 +16,6 @@ #include "SkTime.h" #include "SkTypes.h" #include "base/time/time.h" -#include "starboard/common/time.h" // Taken from SkTime.cpp. void SkTime::DateTime::toISO8601(SkString* dst) const { @@ -52,6 +51,6 @@ void SkTime::GetDateTime(DateTime* dt) { } double SkTime::GetNSecs() { - return starboard::CurrentMonotonicTime() * + return (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() * base::Time::kNanosecondsPerMicrosecond; } diff --git a/cobalt/speech/microphone_fake.cc b/cobalt/speech/microphone_fake.cc index 66f0c27556f6..62f744af29ee 100644 --- a/cobalt/speech/microphone_fake.cc +++ b/cobalt/speech/microphone_fake.cc @@ -24,7 +24,6 @@ #include "base/path_service.h" #include "base/rand_util.h" #include "cobalt/audio/audio_file_reader.h" -#include "starboard/common/file.h" #include "starboard/memory.h" namespace cobalt { diff --git a/cobalt/system_window/system_window.cc b/cobalt/system_window/system_window.cc index 37e5961c25f4..9c62f222b8a1 100644 --- a/cobalt/system_window/system_window.cc +++ b/cobalt/system_window/system_window.cc @@ -20,9 +20,9 @@ #include "base/logging.h" #include "base/strings/stringprintf.h" +#include "base/time/time.h" #include "cobalt/base/event_dispatcher.h" #include "cobalt/system_window/input_event.h" -#include "starboard/common/time.h" #include "starboard/system.h" namespace cobalt { @@ -123,7 +123,7 @@ void SystemWindow::DispatchInputEvent(const SbEvent* event, // Use the current time unless it was overridden. int64_t timestamp = event->timestamp; if (timestamp == 0) { - timestamp = starboard::CurrentMonotonicTime(); + timestamp = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); } // Starboard handily uses the Microsoft key mapping, which is also what Cobalt // uses. diff --git a/cobalt/watchdog/instrumentation_log_test.cc b/cobalt/watchdog/instrumentation_log_test.cc index 02ece73041ad..0cfa139ae742 100644 --- a/cobalt/watchdog/instrumentation_log_test.cc +++ b/cobalt/watchdog/instrumentation_log_test.cc @@ -19,7 +19,6 @@ #include "base/json/json_reader.h" #include "base/json/json_writer.h" -#include "starboard/common/file.h" #include "testing/gtest/include/gtest/gtest.h" namespace cobalt { diff --git a/cobalt/watchdog/watchdog.cc b/cobalt/watchdog/watchdog.cc index 7a67dd4a16c2..458ff320f08e 100644 --- a/cobalt/watchdog/watchdog.cc +++ b/cobalt/watchdog/watchdog.cc @@ -22,12 +22,12 @@ #include #include "base/command_line.h" +#include "base/files/file.h" +#include "base/files/file_path.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/logging.h" #include "base/time/time.h" -#include "starboard/common/file.h" -#include "starboard/common/time.h" #include "starboard/configuration_constants.h" #if defined(_DEBUG) @@ -132,12 +132,13 @@ std::shared_ptr Watchdog::GetViolationsMap() { // previous Watchdog violations file containing violations before app start, // if it exists. if (violations_map_ == nullptr) { - starboard::ScopedFile read_file(GetWatchdogFilePath().c_str(), - kSbFileOpenOnly | kSbFileRead); + base::FilePath file_path(GetWatchdogFilePath()); + base::File read_file( + file_path, base::File::Flags::FLAG_OPEN | base::File::Flags::FLAG_READ); if (read_file.IsValid()) { - int64_t kFileSize = read_file.GetSize(); + int64_t kFileSize = read_file.GetLength(); std::vector buffer(kFileSize + 1, 0); - read_file.ReadAll(buffer.data(), kFileSize); + read_file.ReadAtCurrentPos(buffer.data(), kFileSize); violations_map_ = base::Value::ToUniquePtrValue( base::JSONReader::Read(std::string(buffer.data())) .value_or(base::Value(base::Value::Type::DICT))); @@ -196,14 +197,16 @@ void Watchdog::WriteWatchdogViolations() { watchdog_file.WriteAll(watchdog_json.c_str(), static_cast(watchdog_json.size())); pending_write_ = false; - time_last_written_microseconds_ = starboard::CurrentMonotonicTime(); + time_last_written_microseconds_ = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); } void* Watchdog::Monitor(void* context) { pthread_setname_np(pthread_self(), "Watchdog"); base::AutoLock scoped_lock(static_cast(context)->mutex_); while (1) { - int64_t current_monotonic_time = starboard::CurrentMonotonicTime(); + int64_t current_monotonic_time = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); bool watchdog_violation = false; // Iterates through client map to monitor all name registered clients. @@ -310,7 +313,8 @@ void Watchdog::UpdateViolationsMap(void* context, Client* client, violation.SetKey("timestampLastPingedMilliseconds", base::Value(std::to_string( client->time_last_pinged_microseconds / 1000))); - int64_t current_timestamp_millis = starboard::CurrentPosixTime() / 1000; + int64_t current_timestamp_millis = + (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds(); violation.SetKey("timestampViolationMilliseconds", base::Value(std::to_string(current_timestamp_millis))); violation.SetKey( @@ -444,7 +448,7 @@ void Watchdog::EvictWatchdogViolation(void* context) { } void Watchdog::MaybeWriteWatchdogViolations(void* context) { - if (starboard::CurrentMonotonicTime() > + if ((base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() > static_cast(context)->time_last_written_microseconds_ + static_cast(context)->write_wait_time_microseconds_) { static_cast(context)->WriteWatchdogViolations(); @@ -468,8 +472,10 @@ bool Watchdog::Register(std::string name, std::string description, base::AutoLock scoped_lock(mutex_); - int64_t current_time = starboard::CurrentPosixTime(); - int64_t current_monotonic_time = starboard::CurrentMonotonicTime(); + int64_t current_time = + (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); + int64_t current_monotonic_time = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); // If replace is PING or ALL, handles already registered cases. if (replace != NONE) { @@ -512,8 +518,10 @@ std::shared_ptr Watchdog::RegisterByClient( base::AutoLock scoped_lock(mutex_); - int64_t current_time = starboard::CurrentPosixTime(); - int64_t current_monotonic_time = starboard::CurrentMonotonicTime(); + int64_t current_time = + (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); + int64_t current_monotonic_time = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); // Creates new client. std::shared_ptr client = CreateClient( @@ -652,8 +660,10 @@ bool Watchdog::PingHelper(Client* client, const std::string& name, return false; } - int64_t current_time = starboard::CurrentPosixTime(); - int64_t current_monotonic_time = starboard::CurrentMonotonicTime(); + int64_t current_time = + (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); + int64_t current_monotonic_time = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); // Updates last ping. client->time_last_pinged_microseconds = current_time; @@ -719,7 +729,8 @@ std::string Watchdog::GetWatchdogViolations( } void Watchdog::EvictOldWatchdogViolations() { - int64_t current_timestamp_millis = starboard::CurrentPosixTime() / 1000; + int64_t current_timestamp_millis = + (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds(); int64_t cutoff_timestamp_millis = current_timestamp_millis - kWatchdogMaxViolationsAge; std::vector empty_violations; @@ -848,10 +859,11 @@ void Watchdog::MaybeInjectDebugDelay(const std::string& name) { if (name != delay_name_) return; - if (starboard::CurrentMonotonicTime() > + if ((base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() > time_last_delayed_microseconds_ + delay_wait_time_microseconds_) { usleep(delay_sleep_time_microseconds_); - time_last_delayed_microseconds_ = starboard::CurrentMonotonicTime(); + time_last_delayed_microseconds_ = + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); } } #endif // defined(_DEBUG) diff --git a/cobalt/watchdog/watchdog.h b/cobalt/watchdog/watchdog.h index 33287b25525f..632739428636 100644 --- a/cobalt/watchdog/watchdog.h +++ b/cobalt/watchdog/watchdog.h @@ -30,7 +30,6 @@ #include "cobalt/persistent_storage/persistent_settings.h" #include "cobalt/watchdog/instrumentation_log.h" #include "cobalt/watchdog/singleton.h" -#include "starboard/common/atomic.h" #include "starboard/common/condition_variable.h" namespace cobalt { diff --git a/cobalt/watchdog/watchdog_test.cc b/cobalt/watchdog/watchdog_test.cc index 07c160d9d867..3b0b429faabc 100644 --- a/cobalt/watchdog/watchdog_test.cc +++ b/cobalt/watchdog/watchdog_test.cc @@ -20,10 +20,10 @@ #include #include +#include "base/files/file_util.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/test/task_environment.h" -#include "starboard/common/file.h" #include "testing/gtest/include/gtest/gtest.h" namespace cobalt { @@ -96,7 +96,7 @@ class WatchdogTest : public testing::Test { std::string path = std::string(storage_dir.data()) + kSbFileSepString + kSettingsFileName; - starboard::SbFileDeleteRecursive(path.c_str(), true); + base::DeletePathRecursively(base::FilePath(path)); } void Fence(PersistentSettings* persistent_settings, @@ -418,9 +418,9 @@ TEST_F(WatchdogTest, ViolationsAreEvictedAfterMax) { CreateDummyViolationDict("test-desc-2", 1, 102)); std::string json; base::JSONWriter::Write(*dummy_map, &json); - starboard::ScopedFile file(watchdog_->GetWatchdogFilePath().c_str(), - kSbFileCreateAlways | kSbFileWrite); - file.WriteAll(json.c_str(), static_cast(json.size())); + base::File file(base::FilePath(watchdog_->GetWatchdogFilePath().c_str()), + base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); + file.WriteAtCurrentPos(json.c_str(), static_cast(json.size())); TearDown(); watchdog_ = new watchdog::Watchdog(); watchdog_->InitializeCustom(nullptr, std::string(kWatchdogViolationsJson), @@ -589,12 +589,12 @@ TEST_F(WatchdogTest, FrequentConsecutiveViolationsShouldNotWrite) { kWatchdogMonitorFrequency)); usleep(kWatchdogSleepDuration); std::string write_json = ""; - starboard::ScopedFile read_file(watchdog_->GetWatchdogFilePath().c_str(), - kSbFileOpenOnly | kSbFileRead); + base::File read_file(base::FilePath(watchdog_->GetWatchdogFilePath().c_str()), + base::File::FLAG_OPEN | base::File::FLAG_READ); if (read_file.IsValid()) { - int64_t kFileSize = read_file.GetSize(); + int64_t kFileSize = read_file.GetLength(); std::vector buffer(kFileSize + 1, 0); - read_file.ReadAll(buffer.data(), kFileSize); + read_file.ReadAtCurrentPos(buffer.data(), kFileSize); write_json = std::string(buffer.data()); } ASSERT_NE(write_json, ""); @@ -602,12 +602,13 @@ TEST_F(WatchdogTest, FrequentConsecutiveViolationsShouldNotWrite) { usleep(kWatchdogSleepDuration); ASSERT_TRUE(watchdog_->Unregister("test-name")); std::string no_write_json = ""; - starboard::ScopedFile read_file_again( - watchdog_->GetWatchdogFilePath().c_str(), kSbFileOpenOnly | kSbFileRead); + base::File read_file_again( + base::FilePath(watchdog_->GetWatchdogFilePath().c_str()), + base::File::FLAG_OPEN | base::File::FLAG_READ); if (read_file_again.IsValid()) { - int64_t kFileSize = read_file_again.GetSize(); + int64_t kFileSize = read_file_again.GetLength(); std::vector buffer(kFileSize + 1, 0); - read_file_again.ReadAll(buffer.data(), kFileSize); + read_file_again.ReadAtCurrentPos(buffer.data(), kFileSize); no_write_json = std::string(buffer.data()); } ASSERT_NE(no_write_json, ""); @@ -673,10 +674,10 @@ TEST_F(WatchdogTest, EvictOldWatchdogViolations) { CreateDummyViolationDict("test-desc-old", 0, 1)); std::string json; base::JSONWriter::Write(*dummy_map, &json); - starboard::ScopedFile file(watchdog_->GetWatchdogFilePath().c_str(), - kSbFileCreateAlways | kSbFileWrite); + base::File file(base::FilePath(watchdog_->GetWatchdogFilePath().c_str()), + base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); TearDown(); - file.WriteAll(json.c_str(), static_cast(json.size())); + file.WriteAtCurrentPos(json.c_str(), static_cast(json.size())); watchdog_ = new watchdog::Watchdog(); watchdog_->InitializeCustom(nullptr, std::string(kWatchdogViolationsJson), kWatchdogMonitorFrequency); diff --git a/cobalt/web/event.cc b/cobalt/web/event.cc index 4a530c6675a8..6d8ec96324b6 100644 --- a/cobalt/web/event.cc +++ b/cobalt/web/event.cc @@ -17,14 +17,14 @@ #include "base/compiler_specific.h" #include "base/time/time.h" #include "cobalt/web/event_target.h" -#include "starboard/common/time.h" namespace cobalt { namespace web { Event::Event(UninitializedFlag uninitialized_flag) : event_phase_(kNone), - time_stamp_(GetEventTime(starboard::CurrentMonotonicTime())) { + time_stamp_(GetEventTime( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) { InitEventInternal(base_token::Token(), false, false); } @@ -32,20 +32,23 @@ Event::Event(const char* type) : Event(base_token::Token(type)) {} Event::Event(const std::string& type) : Event(base_token::Token(type)) {} Event::Event(base_token::Token type) : event_phase_(kNone), - time_stamp_(GetEventTime(starboard::CurrentMonotonicTime())) { + time_stamp_(GetEventTime( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) { InitEventInternal(type, false, false); } Event::Event(const std::string& type, const EventInit& init_dict) : Event(base_token::Token(type), init_dict) {} Event::Event(base_token::Token type, Bubbles bubbles, Cancelable cancelable) : event_phase_(kNone), - time_stamp_(GetEventTime(starboard::CurrentMonotonicTime())) { + time_stamp_(GetEventTime( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) { InitEventInternal(type, bubbles == kBubbles, cancelable == kCancelable); } Event::Event(base_token::Token type, const EventInit& init_dict) : event_phase_(kNone), - time_stamp_(GetEventTime(starboard::CurrentMonotonicTime())) { + time_stamp_(GetEventTime( + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds())) { SB_DCHECK(init_dict.has_bubbles()); SB_DCHECK(init_dict.has_cancelable()); if (init_dict.time_stamp() != 0) { @@ -101,8 +104,8 @@ void Event::TraceMembers(script::Tracer* tracer) { uint64 Event::GetEventTime(int64_t monotonic_time) { // Current delta from Windows epoch. int64_t time_delta = - starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime()) - - starboard::CurrentMonotonicTime(); + base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds() - + (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds(); base::Time base_time = base::Time::FromDeltaSinceWindowsEpoch( base::TimeDelta::FromMicroseconds(time_delta + monotonic_time)); // For now, continue using the old specification which specifies real time diff --git a/cobalt/webdriver/BUILD.gn b/cobalt/webdriver/BUILD.gn index 5cf3bfe2abff..a43cd40dfde1 100644 --- a/cobalt/webdriver/BUILD.gn +++ b/cobalt/webdriver/BUILD.gn @@ -134,6 +134,7 @@ target(gtest_target_type, "webdriver_test") { testonly = true sources = [ + "dispatcher_test.cc", "execute_test.cc", "get_element_text_test.cc", "is_displayed_test.cc", diff --git a/cobalt/webdriver/dispatcher.cc b/cobalt/webdriver/dispatcher.cc index c04f40d26bbf..f7dac62bd4e7 100644 --- a/cobalt/webdriver/dispatcher.cc +++ b/cobalt/webdriver/dispatcher.cc @@ -48,6 +48,7 @@ class CommandResultHandlerImpl if (status_code == protocol::Response::kSuccess) { response_handler_->Success(std::move(response)); } else { + LOG(ERROR) << "SendResult status code:" << status_code; response_handler_->FailedCommand(std::move(response)); } } @@ -58,6 +59,8 @@ class CommandResultHandlerImpl if (status_code == protocol::Response::kSuccess) { response_handler_->SuccessData(content_type, data, len); } else { + LOG(ERROR) << "SendResultWithContentType :" << content_type + << "status code:" << status_code << " [" << data << "]"; std::unique_ptr response = protocol::Response::CreateResponse(base::nullopt, status_code, NULL); response_handler_->FailedCommand(std::move(response)); @@ -68,9 +71,13 @@ class CommandResultHandlerImpl const std::string& error_string) override { switch (error) { case kInvalidParameters: + LOG(ERROR) << "SendInvalidRequestResponse::kInvalidParameters (" + << error_string << ")"; response_handler_->MissingCommandParameters(error_string); break; case kInvalidPathVariable: + LOG(ERROR) << "SendInvalidRequestResponse::kInvalidPathVariabl (" + << error_string << ")"; response_handler_->VariableResourceNotFound(error_string); break; } diff --git a/cobalt/webdriver/dispatcher_test.cc b/cobalt/webdriver/dispatcher_test.cc new file mode 100644 index 000000000000..0e0b654ce840 --- /dev/null +++ b/cobalt/webdriver/dispatcher_test.cc @@ -0,0 +1,61 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// 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 +// +// http://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. + +#include "cobalt/webdriver/dispatcher.h" + +#include + +#include "base/optional.h" +#include "base/values.h" +#include "cobalt/webdriver/protocol/log_type.h" +#include "cobalt/webdriver/protocol/window_id.h" +#include "cobalt/webdriver/session_driver.h" +#include "cobalt/webdriver/util/command_result.h" +#include "cobalt/webdriver/util/dispatch_command_factory.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace cobalt { +namespace webdriver { + +TEST(FromValueTest, WindowID) { + base::Value::Dict dict; + dict.Set("name", "foo"); + base::Value value(std::move(dict)); + auto result = util::internal::FromValue(&value); + EXPECT_EQ(result->id(), "foo"); +} + +TEST(FromValueTest, WindowID_Fail) { + base::Value empty; + auto result = util::internal::FromValue(&empty); + EXPECT_EQ(result, base::nullopt); +} + +TEST(FromValueTest, LogType) { + base::Value::Dict dict; + dict.Set("type", "foo"); + base::Value value(std::move(dict)); + auto result = util::internal::FromValue(&value); + EXPECT_EQ(result->type(), "foo"); +} + +TEST(FromValueTest, LogType_Fail) { + base::Value empty; + auto result = util::internal::FromValue(&empty); + EXPECT_EQ(result, base::nullopt); +} + +} // namespace webdriver +} // namespace cobalt diff --git a/cobalt/webdriver/protocol/cookie.cc b/cobalt/webdriver/protocol/cookie.cc index 553902b138b8..364c3938caf1 100644 --- a/cobalt/webdriver/protocol/cookie.cc +++ b/cobalt/webdriver/protocol/cookie.cc @@ -51,14 +51,14 @@ base::Optional Cookie::FromValue(const base::Value* value) { // error, but the current implementation will return "invalid parameter". const base::Value::Dict* dictionary_value = value->GetIfDict(); if (!dictionary_value) { - DLOG(INFO) << "Parameter is not a dictionary."; + LOG(ERROR) << "Parameter is not a dictionary."; return base::nullopt; } const base::Value::Dict* cookie_dictionary_value = dictionary_value->FindDict(kCookieKey); if (!cookie_dictionary_value) { - DLOG(INFO) << base::StringPrintf("Value of key [%s] is not a JSON object.", + LOG(ERROR) << base::StringPrintf("Value of key [%s] is not a JSON object.", kCookieKey); return base::nullopt; } @@ -69,7 +69,7 @@ base::Optional Cookie::FromValue(const base::Value* value) { cookie_dictionary_value->FindString(kValueKey); // Name and value are required. if (!cookie_name || !cookie_value) { - DLOG(INFO) << base::StringPrintf( + LOG(ERROR) << base::StringPrintf( "cookie.%s or cookie.%s either does not exist or is not a string", kNameKey, kValueKey); return base::nullopt; @@ -82,7 +82,7 @@ base::Optional Cookie::FromValue(const base::Value* value) { if (domain_value) { new_cookie.domain_ = *domain_value; } else if (cookie_dictionary_value->contains(kDomainKey)) { - DLOG(INFO) << base::StringPrintf("cookie.%s is not a string", kDomainKey); + LOG(ERROR) << base::StringPrintf("cookie.%s is not a string", kDomainKey); return base::nullopt; } @@ -90,7 +90,7 @@ base::Optional Cookie::FromValue(const base::Value* value) { if (path_value) { new_cookie.path_ = *path_value; } else if (cookie_dictionary_value->contains(kPathKey)) { - DLOG(INFO) << base::StringPrintf("cookie.%s is not a string", kPathKey); + LOG(ERROR) << base::StringPrintf("cookie.%s is not a string", kPathKey); return base::nullopt; } @@ -99,7 +99,7 @@ base::Optional Cookie::FromValue(const base::Value* value) { if (secure_value.has_value()) { new_cookie.secure_ = secure_value.value(); } else if (cookie_dictionary_value->contains(kSecureKey)) { - DLOG(INFO) << base::StringPrintf("cookie.%s is not a boolean", kSecureKey); + LOG(ERROR) << base::StringPrintf("cookie.%s is not a boolean", kSecureKey); return base::nullopt; } @@ -108,7 +108,7 @@ base::Optional Cookie::FromValue(const base::Value* value) { if (http_only_value.has_value()) { new_cookie.http_only_ = http_only_value.value(); } else if (cookie_dictionary_value->contains(kHttpOnlyKey)) { - DLOG(INFO) << base::StringPrintf("cookie.%s is not a boolean", + LOG(ERROR) << base::StringPrintf("cookie.%s is not a boolean", kHttpOnlyKey); return base::nullopt; } @@ -119,7 +119,7 @@ base::Optional Cookie::FromValue(const base::Value* value) { base::TimeDelta seconds_since_epoch = base::Seconds(expiry_value.value()); new_cookie.expiry_time_ = base::Time::UnixEpoch() + seconds_since_epoch; } else if (cookie_dictionary_value->contains(kExpiryKey)) { - DLOG(INFO) << base::StringPrintf("cookie.%s is not an integer", kExpiryKey); + LOG(ERROR) << base::StringPrintf("cookie.%s is not an integer", kExpiryKey); return base::nullopt; } return new_cookie; diff --git a/cobalt/webdriver/protocol/log_type.cc b/cobalt/webdriver/protocol/log_type.cc index 6bcc7d87a440..38fe6cbbead6 100644 --- a/cobalt/webdriver/protocol/log_type.cc +++ b/cobalt/webdriver/protocol/log_type.cc @@ -18,12 +18,21 @@ namespace cobalt { namespace webdriver { namespace protocol { +namespace { +const char kLogTypeKey[] = "type"; +} + + base::Optional LogType::FromValue(const base::Value* value) { const base::Value::Dict* dictionary_value = value->GetIfDict(); if (!dictionary_value) { return absl::nullopt; } - return base::nullopt; + auto type = dictionary_value->FindString(kLogTypeKey); + if (!type) { + return absl::nullopt; + } + return LogType(*type); } } // namespace protocol diff --git a/cobalt/webdriver/protocol/proxy.cc b/cobalt/webdriver/protocol/proxy.cc index 3c82506cc932..8e53d725b56e 100644 --- a/cobalt/webdriver/protocol/proxy.cc +++ b/cobalt/webdriver/protocol/proxy.cc @@ -62,7 +62,7 @@ base::Optional Proxy::FromValue(const base::Value* value) { } } else { // Only manual proxy type is supported. - DLOG(INFO) << "Unsupported proxy type: " << proxy_type_string; + LOG(ERROR) << "Unsupported proxy type: " << proxy_type_string; } return base::nullopt; } diff --git a/cobalt/webdriver/protocol/window_id.cc b/cobalt/webdriver/protocol/window_id.cc index b63667956cbb..17bec6d4feb7 100644 --- a/cobalt/webdriver/protocol/window_id.cc +++ b/cobalt/webdriver/protocol/window_id.cc @@ -26,7 +26,11 @@ base::Optional WindowId::FromValue(const base::Value* value) { if (!dictionary_value) { return absl::nullopt; } - return base::nullopt; + auto window_id = dictionary_value->FindString(kWindowNameKey); + if (!window_id) { + return absl::nullopt; + } + return WindowId(*window_id); } } // namespace protocol diff --git a/cobalt/webdriver/script_executor_params.cc b/cobalt/webdriver/script_executor_params.cc index f6a865692679..18c7720a0aee 100644 --- a/cobalt/webdriver/script_executor_params.cc +++ b/cobalt/webdriver/script_executor_params.cc @@ -45,7 +45,7 @@ ScriptExecutorParams::GCPreventedParams ScriptExecutorParams::Create( if (!global_environment->EvaluateScript(function_source, params.get(), ¶ms->function_object_)) { - DLOG(ERROR) << "Failed to create Function object"; + LOG(ERROR) << "Failed to create Function object"; } return {params, global_environment.get()}; } diff --git a/cobalt/webdriver/server.cc b/cobalt/webdriver/server.cc index 7ff38b3bf546..51e5709c89bd 100644 --- a/cobalt/webdriver/server.cc +++ b/cobalt/webdriver/server.cc @@ -111,14 +111,14 @@ class ResponseHandlerImpl : public WebDriverServer::ResponseHandler { // The command request is not mapped to anything. void UnknownCommand(const std::string& path) override { - LOG(INFO) << "Unknown command: " << path; + LOG(WARNING) << "Unknown command: " << path; SendInternal(net::HTTP_NOT_FOUND, "Unknown command", kTextPlainContentType); } // The command request is mapped to a valid command, but this WebDriver // implementation has not implemented it. void UnimplementedCommand(const std::string& path) override { - LOG(INFO) << "Unimplemented command: " << path; + LOG(ERROR) << "Unimplemented command: " << path; SendInternal(net::HTTP_NOT_IMPLEMENTED, "Unimplemented command", kTextPlainContentType); } @@ -126,6 +126,7 @@ class ResponseHandlerImpl : public WebDriverServer::ResponseHandler { // The request maps to a valid command, but the variable part of the path // does not map to a valid instance. void VariableResourceNotFound(const std::string& variable_name) override { + LOG(ERROR) << "VariableResourceNotFound : " << variable_name; SendInternal(net::HTTP_NOT_FOUND, "Unknown variable resource: " + variable_name, kTextPlainContentType); @@ -143,6 +144,7 @@ class ResponseHandlerImpl : public WebDriverServer::ResponseHandler { net::HttpServerResponseInfo response_info; response_info.AddHeader("Allow", base::JoinString(allowed_method_strings, ", ")); + LOG(ERROR) << "InvalidCommandMethod (" << requested_method << ")"; SendInternal(net::HTTP_METHOD_NOT_ALLOWED, "Invalid method: " + HttpMethodToString(requested_method), kTextPlainContentType, response_info); @@ -151,6 +153,7 @@ class ResponseHandlerImpl : public WebDriverServer::ResponseHandler { // The POST command's JSON request body does not contain the required // parameters. void MissingCommandParameters(const std::string& message) override { + LOG(ERROR) << "MissingCommandParameters (" << message << ")"; SendInternal(net::HTTP_BAD_REQUEST, message, kTextPlainContentType); } @@ -225,7 +228,7 @@ void WebDriverServer::OnHttpRequest(int connection_id, path.resize(query_position); } - DLOG(INFO) << "Got request: " << path; + LOG(INFO) << "Got request: " << path; // Create a new ResponseHandler that will send a response to this connection. std::unique_ptr response_handler( new ResponseHandlerImpl(server_.get(), connection_id)); diff --git a/cobalt/webdriver/util/dispatch_command_factory.h b/cobalt/webdriver/util/dispatch_command_factory.h index 6cf6a7bf865d..e7e8b7c2ecd0 100644 --- a/cobalt/webdriver/util/dispatch_command_factory.h +++ b/cobalt/webdriver/util/dispatch_command_factory.h @@ -92,13 +92,13 @@ std::unique_ptr ToValue(const base::Optional& value) { // Template specialization for std::string. template <> -std::unique_ptr ToValue(const std::string& value) { +inline std::unique_ptr ToValue(const std::string& value) { return std::unique_ptr(new base::Value(value)); } // Template specialization for bool. template <> -std::unique_ptr ToValue(const bool& value) { +inline std::unique_ptr ToValue(const bool& value) { return std::unique_ptr(new base::Value(value)); } @@ -108,7 +108,7 @@ std::unique_ptr ToValue(const CommandResult& command_result) { } template <> -std::unique_ptr ToValue( +inline std::unique_ptr ToValue( const CommandResult& command_result) { return std::make_unique(); } @@ -121,7 +121,7 @@ base::Optional FromValue(const base::Value* value) { } template <> -base::Optional FromValue(const base::Value* value) { +inline base::Optional FromValue(const base::Value* value) { const char kUrlKey[] = "url"; const base::Value::Dict* dictionary_value = value->GetIfDict(); diff --git a/cobalt/webdriver/window_driver.cc b/cobalt/webdriver/window_driver.cc index 293e971d80fc..bfa67ee24e72 100644 --- a/cobalt/webdriver/window_driver.cc +++ b/cobalt/webdriver/window_driver.cc @@ -480,7 +480,7 @@ util::CommandResult WindowDriver::ExecuteScriptInternal( scoped_refptr script_executor = ScriptExecutor::Create(this, global_environment); if (!script_executor) { - DLOG(INFO) << "Failed to create ScriptExecutor."; + LOG(ERROR) << "Failed to create ScriptExecutor."; return CommandResult(protocol::Response::kUnknownError); } script_executor_ = base::AsWeakPtr(script_executor.get()); diff --git a/cobalt/worker/service_worker_jobs.h b/cobalt/worker/service_worker_jobs.h index 0fb9530549e8..f9d0ff33fdaa 100644 --- a/cobalt/worker/service_worker_jobs.h +++ b/cobalt/worker/service_worker_jobs.h @@ -39,7 +39,6 @@ #include "cobalt/worker/service_worker_object.h" #include "cobalt/worker/service_worker_registration_object.h" #include "cobalt/worker/service_worker_update_via_cache.h" -#include "starboard/common/atomic.h" #include "url/gurl.h" #include "url/origin.h" diff --git a/cobalt/worker/service_worker_object.h b/cobalt/worker/service_worker_object.h index 7f4d579671c5..6026b2f9b219 100644 --- a/cobalt/worker/service_worker_object.h +++ b/cobalt/worker/service_worker_object.h @@ -31,7 +31,6 @@ #include "cobalt/web/web_settings.h" #include "cobalt/worker/service_worker_state.h" #include "cobalt/worker/worker_global_scope.h" -#include "starboard/common/atomic.h" #include "url/gurl.h" #if defined(ENABLE_DEBUGGER) diff --git a/cobalt/xhr/xml_http_request.h b/cobalt/xhr/xml_http_request.h index b6cbf651926e..f86f202bb1e3 100644 --- a/cobalt/xhr/xml_http_request.h +++ b/cobalt/xhr/xml_http_request.h @@ -47,7 +47,6 @@ #include "net/base/load_timing_info.h" #include "net/http/http_request_headers.h" #include "net/http/http_response_headers.h" -#include "starboard/common/atomic.h" #include "url/gurl.h" namespace cobalt { diff --git a/components/update_client/cobalt_slot_management_test.cc b/components/update_client/cobalt_slot_management_test.cc index 6790005827a3..47e3434be6b6 100644 --- a/components/update_client/cobalt_slot_management_test.cc +++ b/components/update_client/cobalt_slot_management_test.cc @@ -20,8 +20,8 @@ #include #include "base/strings/string_util.h" +#include "base/time/time.h" #include "starboard/common/file.h" -#include "starboard/common/time.h" #include "starboard/extension/free_space.h" #include "starboard/loader_app/app_key_files.h" #include "starboard/loader_app/drain_file.h" @@ -206,7 +206,7 @@ TEST_F(CobaltSlotManagementTest, ConfirmSlotBailsIfOtherAppStartedDrainFirst) { // In order to be higher ranked, the other app's drain file needs to be older // but not expired. int64_t current_time_us = - starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime()); + base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds(); starboard::loader_app::ScopedDrainFile racing_drain_file( slot_path, kTestAppKey2, current_time_us - (kDrainFileMaximumAgeUsec / 2)); diff --git a/media/base/media_util.cc b/media/base/media_util.cc index 34ee95dfead4..fe4b1982397a 100644 --- a/media/base/media_util.cc +++ b/media/base/media_util.cc @@ -31,12 +31,8 @@ AudioParameters::Format ConvertAudioCodecToBitstreamFormat(AudioCodec codec) { } bool MediaTraceIsEnabled() { -#if defined(STARBOARD) - return true; -#else // defined(STARBOARD) bool enable_decode_traces = false; TRACE_EVENT_CATEGORY_GROUP_ENABLED("media", &enable_decode_traces); return enable_decode_traces; -#endif // defined(STARBOARD) } } // namespace media diff --git a/starboard/CHANGELOG.md b/starboard/CHANGELOG.md index f3642c128251..b26f2bd8a334 100644 --- a/starboard/CHANGELOG.md +++ b/starboard/CHANGELOG.md @@ -9,6 +9,10 @@ since the version previous to it. ## Version 16 +### Deprecated `SbMutex`, `SbConditionVariable` and `SbThread`. +The standard POSIX `pthread` APIs replace the Starboard concurrency +primitives. + ### Migrate the `SbThreadSampler` to use `pthread`. Switched the `SbThreadSampler` API to use `pthread` instead of `SbThread`. diff --git a/starboard/android/apk/apk_sources.gni b/starboard/android/apk/apk_sources.gni index 7f85c40f50df..29a454cbfd9f 100644 --- a/starboard/android/apk/apk_sources.gni +++ b/starboard/android/apk/apk_sources.gni @@ -30,7 +30,6 @@ apk_sources = [ "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltTextToSpeechHelper.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CrashContextUpdateHandler.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/ErrorDialog.java", - "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/MediaPlaybackService.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/NetworkStatus.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/NullCobaltFactory.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/PlatformError.java", diff --git a/starboard/android/apk/app/src/app/AndroidManifest.xml b/starboard/android/apk/app/src/app/AndroidManifest.xml index 279494d88773..4c17fd1910a7 100644 --- a/starboard/android/apk/app/src/app/AndroidManifest.xml +++ b/starboard/android/apk/app/src/app/AndroidManifest.xml @@ -72,11 +72,6 @@ - - diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/coat/MediaPlaybackService.java b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/MediaPlaybackService.java deleted file mode 100644 index 8f7742bf9f99..000000000000 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/coat/MediaPlaybackService.java +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2020 The Cobalt Authors. All Rights Reserved. -// -// 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 -// -// http://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. - -package dev.cobalt.coat; - -import static dev.cobalt.media.Log.TAG; - -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.app.Service; -import android.content.Context; -import android.content.Intent; -import android.content.pm.ServiceInfo; -import android.os.Build.VERSION; -import android.os.IBinder; -import android.os.RemoteException; -import androidx.annotation.RequiresApi; -import androidx.core.app.NotificationCompat; -import dev.cobalt.util.Log; -import dev.cobalt.util.UsedByNative; - -/** Implementation of the MediaPlaybackService used for Background mode media playing. */ -public class MediaPlaybackService extends Service { - - private static final int NOTIFICATION_ID = 193266736; // CL number for uniqueness. - private static final String NOTIFICATION_CHANNEL_ID = "dev.cobalt.coat media playback service"; - private static final String NOTIFICATION_CHANNEL_NAME = "Media playback service"; - private boolean channelCreated = true; - private NotificationManager notificationManager = null; - - @Override - public void onCreate() { - Log.i(TAG, "Creating a Media playback foreground service."); - super.onCreate(); - if (getStarboardBridge() != null) { - getStarboardBridge().onServiceStart(this); - } - this.notificationManager = - (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); - this.channelCreated = createNotificationChannel(); - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - Log.i(TAG, "Cold start - Starting the service."); - startService(); - // It is better for background media playback service. - return START_STICKY; - } - - @Override - public IBinder onBind(Intent intent) { - // Do not support binding. - return null; - } - - @Override - public void onDestroy() { - Log.i(TAG, "Destroying the Media playback service."); - - if (VERSION.SDK_INT >= 26 && this.channelCreated) { - this.notificationManager.deleteNotificationChannel(NOTIFICATION_CHANNEL_ID); - } - - if (getStarboardBridge() != null) { - getStarboardBridge().onServiceDestroy(this); - } - super.onDestroy(); - } - - public void startService() { - if (this.channelCreated) { - try { - if (VERSION.SDK_INT >= 29) { - startForeground( - NOTIFICATION_ID, buildNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST); - } else { - startForeground(NOTIFICATION_ID, buildNotification()); - } - } catch (IllegalStateException e) { - Log.e(TAG, "Failed to start Foreground Service", e); - } - } - } - - public void stopService() { - // Let service itself handle notification deletion. - if (this.channelCreated) { - stopForeground(true); - } - stopSelf(); - } - - private boolean createNotificationChannel() { - if (VERSION.SDK_INT >= 26) { - try { - createNotificationChannelInternalV26(); - } catch (RemoteException e) { - Log.e(TAG, "Failed to create Notification Channel.", e); - return false; - } - } - return true; - } - - @RequiresApi(26) - private void createNotificationChannelInternalV26() throws RemoteException { - NotificationChannel channel = - new NotificationChannel( - NOTIFICATION_CHANNEL_ID, - NOTIFICATION_CHANNEL_NAME, - notificationManager.IMPORTANCE_DEFAULT); - channel.setDescription("Channel for showing persistent notification"); - this.notificationManager.createNotificationChannel(channel); - } - - Notification buildNotification() { - String channelId = ""; - if (VERSION.SDK_INT >= 26) { - // Channel with ID=NOTIFICATION_CHANNEL_ID is created for version >= 26 - channelId = NOTIFICATION_CHANNEL_ID; - } - - NotificationCompat.Builder builder = - new NotificationCompat.Builder(this, channelId) - .setShowWhen(false) - .setPriority(NotificationCompat.PRIORITY_MIN) - .setSmallIcon(android.R.drawable.stat_sys_warning) - .setContentTitle("Media playback service") - .setContentText("Media playback service is running"); - - return builder.build(); - } - - @UsedByNative - protected StarboardBridge getStarboardBridge() { - if (getApplication() == null) { - Log.e(TAG, "Application already destroyed."); - return null; - } - return ((StarboardBridge.HostApplication) getApplication()).getStarboardBridge(); - } -} diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java index d730b15d52a7..a6114598794f 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java @@ -31,7 +31,6 @@ import android.net.Network; import android.net.NetworkCapabilities; import android.os.Build; -import android.os.Build.VERSION; import android.util.Pair; import android.util.Size; import android.util.SizeF; @@ -184,48 +183,6 @@ protected void onServiceDestroy(Service service) { } } - @SuppressWarnings("unused") - @UsedByNative - protected void startMediaPlaybackService() { - if (cobaltMediaSession == null || !cobaltMediaSession.isActive()) { - Log.w(TAG, "Do not start a MediaPlaybackService when the MediSsession is null or inactive."); - return; - } - - Service service = serviceHolder.get(); - if (service == null) { - if (appContext == null) { - Log.w(TAG, "Activiy already destroyed."); - return; - } - Log.i(TAG, "Cold start - Instantiating a MediaPlaybackService."); - Intent intent = new Intent(appContext, MediaPlaybackService.class); - try { - if (VERSION.SDK_INT >= 26) { - appContext.startForegroundService(intent); - } else { - appContext.startService(intent); - } - } catch (SecurityException e) { - Log.e(TAG, "Failed to start MediaPlaybackService with intent.", e); - return; - } - } else { - Log.i(TAG, "Warm start - Restarting the MediaPlaybackService."); - ((MediaPlaybackService) service).startService(); - } - } - - @SuppressWarnings("unused") - @UsedByNative - protected void stopMediaPlaybackService() { - Service service = serviceHolder.get(); - if (service != null) { - Log.i(TAG, "Stopping the MediaPlaybackService."); - ((MediaPlaybackService) service).stopService(); - } - } - @SuppressWarnings("unused") @UsedByNative protected void beforeStartOrResume() { @@ -253,9 +210,6 @@ protected void beforeSuspend() { for (CobaltService service : cobaltServices.values()) { service.beforeSuspend(); } - // We need to stop MediaPlaybackService before suspending so that this foreground service - // would not prevent releasing activity's memory consumption. - stopMediaPlaybackService(); } catch (Throwable e) { Log.i(TAG, "Caught exception in beforeSuspend: " + e.getMessage()); } diff --git a/starboard/android/shared/android_main.cc b/starboard/android/shared/android_main.cc index e303604ac0b6..4de29227a1d9 100644 --- a/starboard/android/shared/android_main.cc +++ b/starboard/android/shared/android_main.cc @@ -270,20 +270,12 @@ void OnStart(GameActivity* activity) { void OnResume(GameActivity* activity) { if (g_app_running.load()) { - // Stop the MediaPlaybackService if activity state transits from background - // to foreground. Note that the MediaPlaybackService may already have - // been stopped before Cobalt's lifecycle state transits from Concealed - // to Frozen. - ApplicationAndroid::Get()->StopMediaPlaybackService(); ApplicationAndroid::Get()->SendAndroidCommand(AndroidCommand::kResume); } } void OnPause(GameActivity* activity) { if (g_app_running.load()) { - // Start the MediaPlaybackService before activity state transits from - // foreground to background. - ApplicationAndroid::Get()->StartMediaPlaybackService(); ApplicationAndroid::Get()->SendAndroidCommand(AndroidCommand::kPause); } } diff --git a/starboard/android/shared/application_android.cc b/starboard/android/shared/application_android.cc index ce2ae6965bcc..527fa0a7fa1a 100644 --- a/starboard/android/shared/application_android.cc +++ b/starboard/android/shared/application_android.cc @@ -257,16 +257,6 @@ void ApplicationAndroid::OnSuspend() { env->CallStarboardVoidMethodOrAbort("beforeSuspend", "()V"); } -void ApplicationAndroid::StartMediaPlaybackService() { - JniEnvExt* env = JniEnvExt::Get(); - env->CallStarboardVoidMethodOrAbort("startMediaPlaybackService", "()V"); -} - -void ApplicationAndroid::StopMediaPlaybackService() { - JniEnvExt* env = JniEnvExt::Get(); - env->CallStarboardVoidMethodOrAbort("stopMediaPlaybackService", "()V"); -} - void ApplicationAndroid::ProcessAndroidCommand() { JniEnvExt* env = JniEnvExt::Get(); AndroidCommand cmd; diff --git a/starboard/android/shared/application_android.h b/starboard/android/shared/application_android.h index 0b7d34cc3fac..1ceefd919350 100644 --- a/starboard/android/shared/application_android.h +++ b/starboard/android/shared/application_android.h @@ -107,10 +107,6 @@ class ApplicationAndroid std::string GetOverlayedStringValue(const char* var_name); bool GetOverlayedBoolValue(const char* var_name); - // Methods to start/stop Media playback service. - void StartMediaPlaybackService(); - void StopMediaPlaybackService(); - protected: // --- Application overrides --- void Initialize() override; diff --git a/starboard/android/shared/audio_decoder.cc b/starboard/android/shared/audio_decoder.cc index 5af005957887..f93c868afdcf 100644 --- a/starboard/android/shared/audio_decoder.cc +++ b/starboard/android/shared/audio_decoder.cc @@ -169,8 +169,10 @@ void AudioDecoder::Reset() { SB_DCHECK(BelongsToCurrentThread()); SB_DCHECK(output_cb_); - // If fail to flush |media_decoder_|, then re-create |media_decoder_|. - if (!enable_flush_during_seek_ || !media_decoder_->Flush()) { + // If fail to flush |media_decoder_| or |media_decoder_| is null, then + // re-create |media_decoder_|. + if (!enable_flush_during_seek_ || !media_decoder_ || + !media_decoder_->Flush()) { media_decoder_.reset(); if (!InitializeCodec()) { diff --git a/starboard/android/shared/log_format.cc b/starboard/android/shared/log_format.cc index bcebdf5a0ea6..196aa42b4da9 100644 --- a/starboard/android/shared/log_format.cc +++ b/starboard/android/shared/log_format.cc @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include + #include #include "starboard/common/log.h" -#include "starboard/common/mutex.h" #include "starboard/common/string.h" namespace { -SbMutex log_line_mutex = SB_MUTEX_INITIALIZER; +pthread_mutex_t log_line_mutex = PTHREAD_MUTEX_INITIALIZER; std::stringstream log_line; const int kFormatBufferSizeBytes = 16 * 1024; @@ -39,7 +40,7 @@ void SbLogFormat(const char* format, va_list arguments) { const char* newline = strchr(formatted_buffer, '\n'); - SbMutexAcquire(&log_line_mutex); + pthread_mutex_lock(&log_line_mutex); std::string buffer_string(formatted_buffer); log_line << buffer_string; if (newline != NULL) { @@ -50,5 +51,5 @@ void SbLogFormat(const char* format, va_list arguments) { log_line.str(""); log_line.clear(); } - SbMutexRelease(&log_line_mutex); + pthread_mutex_unlock(&log_line_mutex); } diff --git a/starboard/android/shared/thread_create.cc b/starboard/android/shared/thread_create.cc index d760a611d367..35fb27f2e6d6 100644 --- a/starboard/android/shared/thread_create.cc +++ b/starboard/android/shared/thread_create.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" #include @@ -146,3 +148,4 @@ SbThread SbThreadCreate(int64_t stack_size, return kSbThreadInvalid; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/android/shared/video_decoder.cc b/starboard/android/shared/video_decoder.cc index fd509ad51631..fe252a2c2bbb 100644 --- a/starboard/android/shared/video_decoder.cc +++ b/starboard/android/shared/video_decoder.cc @@ -601,8 +601,10 @@ void VideoDecoder::WriteEndOfStream() { void VideoDecoder::Reset() { SB_DCHECK(BelongsToCurrentThread()); - // If fail to flush |media_decoder_|, then re-create |media_decoder_|. - if (!enable_flush_during_seek_ || !media_decoder_->Flush()) { + // If fail to flush |media_decoder_| or |media_decoder_| is null, then + // re-create |media_decoder_|. + if (!enable_flush_during_seek_ || !media_decoder_ || + !media_decoder_->Flush()) { TeardownCodec(); input_buffer_written_ = 0; diff --git a/starboard/common/condition_variable.cc b/starboard/common/condition_variable.cc index 892c725ed16e..d0b253b995df 100644 --- a/starboard/common/condition_variable.cc +++ b/starboard/common/condition_variable.cc @@ -14,37 +14,90 @@ #include "starboard/common/condition_variable.h" +#include + +#include "starboard/common/log.h" +#include "starboard/common/time.h" + namespace starboard { ConditionVariable::ConditionVariable(const Mutex& mutex) : mutex_(&mutex), condition_() { +#if SB_API_VERSION < 16 SbConditionVariableCreate(&condition_, mutex_->mutex()); +#else +#if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) + pthread_condattr_t attribute; + pthread_condattr_init(&attribute); + pthread_condattr_setclock(&attribute, CLOCK_MONOTONIC); + + int result = pthread_cond_init(&condition_, &attribute); + SB_DCHECK(result == 0); + + pthread_condattr_destroy(&attribute); +#else + int result = pthread_cond_init(&condition_, nullptr); + SB_DCHECK(result == 0); +#endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) +#endif // SB_API_VERSION < 16 } ConditionVariable::~ConditionVariable() { +#if SB_API_VERSION < 16 SbConditionVariableDestroy(&condition_); +#else + pthread_cond_destroy(&condition_); +#endif // SB_API_VERSION < 16 } void ConditionVariable::Wait() const { mutex_->debugSetReleased(); +#if SB_API_VERSION < 16 SbConditionVariableWait(&condition_, mutex_->mutex()); +#else + pthread_cond_wait(&condition_, mutex_->mutex()); +#endif // SB_API_VERSION < 16 mutex_->debugSetAcquired(); } bool ConditionVariable::WaitTimed(int64_t duration) const { mutex_->debugSetReleased(); +#if SB_API_VERSION < 16 bool was_signaled = SbConditionVariableIsSignaled( SbConditionVariableWaitTimed(&condition_, mutex_->mutex(), duration)); +#else +#if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) + int64_t timeout_time_usec = starboard::CurrentMonotonicTime(); +#else + int64_t timeout_time_usec = starboard::CurrentPosixTime(); +#endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) + timeout_time_usec += duration; + + struct timespec timeout; + timeout.tv_sec = timeout_time_usec / 1000'000; + timeout.tv_nsec = (timeout_time_usec % 1000'000) * 1000; + + bool was_signaled = + pthread_cond_timedwait(&condition_, mutex_->mutex(), &timeout) == 0; +#endif // SB_API_VERSION < 16 mutex_->debugSetAcquired(); return was_signaled; } void ConditionVariable::Broadcast() const { +#if SB_API_VERSION < 16 SbConditionVariableBroadcast(&condition_); +#else + pthread_cond_broadcast(&condition_); +#endif // SB_API_VERSION < 16 } void ConditionVariable::Signal() const { +#if SB_API_VERSION < 16 SbConditionVariableSignal(&condition_); +#else + pthread_cond_signal(&condition_); +#endif // SB_API_VERSION < 16 } } // namespace starboard diff --git a/starboard/common/condition_variable.h b/starboard/common/condition_variable.h index d666ef6ead6d..cc0328cb82f3 100644 --- a/starboard/common/condition_variable.h +++ b/starboard/common/condition_variable.h @@ -20,13 +20,15 @@ #ifndef STARBOARD_COMMON_CONDITION_VARIABLE_H_ #define STARBOARD_COMMON_CONDITION_VARIABLE_H_ -#include "starboard/common/mutex.h" +#include #include "starboard/condition_variable.h" + +#include "starboard/common/mutex.h" #include "starboard/types.h" namespace starboard { -// Inline class wrapper for SbConditionVariable. +// Inline class wrapper for pthread_cond_t. class ConditionVariable { public: explicit ConditionVariable(const Mutex& mutex); @@ -47,7 +49,11 @@ class ConditionVariable { private: const Mutex* mutex_; +#if SB_API_VERSION < 16 mutable SbConditionVariable condition_; +#else + mutable pthread_cond_t condition_; +#endif // SB_API_VERSION < 16 }; } // namespace starboard diff --git a/starboard/common/mutex.cc b/starboard/common/mutex.cc index da362cfec081..e9400d7646f7 100644 --- a/starboard/common/mutex.cc +++ b/starboard/common/mutex.cc @@ -14,26 +14,42 @@ #include "starboard/common/mutex.h" #include "starboard/common/log.h" -#include "starboard/thread.h" namespace starboard { Mutex::Mutex() : mutex_() { +#if SB_API_VERSION < 16 SbMutexCreate(&mutex_); +#else + pthread_mutex_init(&mutex_, nullptr); +#endif // SB_API_VERSION < 16 debugInit(); } Mutex::~Mutex() { +#if SB_API_VERSION < 16 SbMutexDestroy(&mutex_); +#else + pthread_mutex_destroy(&mutex_); +#endif // SB_API_VERSION < 16 } void Mutex::Acquire() const { debugPreAcquire(); +#if SB_API_VERSION < 16 SbMutexAcquire(&mutex_); +#else + pthread_mutex_lock(&mutex_); +#endif // SB_API_VERSION < 16 debugSetAcquired(); } + bool Mutex::AcquireTry() const { +#if SB_API_VERSION < 16 bool ok = SbMutexAcquireTry(&mutex_) == kSbMutexAcquired; +#else + bool ok = pthread_mutex_trylock(&mutex_) == 0; +#endif // SB_API_VERSION < 16 if (ok) { debugSetAcquired(); } @@ -42,7 +58,11 @@ bool Mutex::AcquireTry() const { void Mutex::Release() const { debugSetReleased(); +#if SB_API_VERSION < 16 SbMutexRelease(&mutex_); +#else + pthread_mutex_unlock(&mutex_); +#endif // SB_API_VERSION < 16 } void Mutex::DCheckAcquired() const { @@ -77,7 +97,11 @@ void Mutex::debugPreAcquire() const {} void Mutex::debugSetAcquired() const {} #endif +#if SB_API_VERSION < 16 SbMutex* Mutex::mutex() const { +#else +pthread_mutex_t* Mutex::mutex() const { +#endif return &mutex_; } diff --git a/starboard/common/mutex.h b/starboard/common/mutex.h index 1f9ddfa187a8..f63d4470ded3 100644 --- a/starboard/common/mutex.h +++ b/starboard/common/mutex.h @@ -20,11 +20,13 @@ #include +#if SB_API_VERSION < 16 #include "starboard/mutex.h" +#endif // SB_API_VERSION < 16 namespace starboard { -// Inline class wrapper for SbMutex. +// Inline class wrapper for mutex. class Mutex { public: Mutex(); @@ -50,9 +52,13 @@ class Mutex { #endif friend class ConditionVariable; +#if SB_API_VERSION < 16 SbMutex* mutex() const; mutable SbMutex mutex_; - +#else + pthread_mutex_t* mutex() const; + mutable pthread_mutex_t mutex_; +#endif // SB_API_VERSION < 16 Mutex(const Mutex&) = delete; void operator=(const Mutex&) = delete; }; diff --git a/starboard/common/rwlock.cc b/starboard/common/rwlock.cc index 0dd0ac12e8a3..6607e2a1abcc 100644 --- a/starboard/common/rwlock.cc +++ b/starboard/common/rwlock.cc @@ -21,52 +21,49 @@ namespace starboard { // Write-preferring lock. // https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock RWLock::RWLock() : readers_(0), writing_(false) { - SB_CHECK(SbMutexCreate(&mutex_)); - SB_CHECK(SbConditionVariableCreate(&condition_, &mutex_)); + SB_CHECK(pthread_mutex_init(&mutex_, nullptr) == 0); + SB_CHECK(pthread_cond_init(&condition_, nullptr) == 0); } RWLock::~RWLock() { - SbConditionVariableDestroy(&condition_); - SbMutexDestroy(&mutex_); + pthread_cond_destroy(&condition_); + pthread_mutex_destroy(&mutex_); } void RWLock::AcquireReadLock() { - SB_CHECK(SbMutexAcquire(&mutex_) == kSbMutexAcquired); + SB_CHECK(pthread_mutex_lock(&mutex_) == 0); while (writing_) { - SB_CHECK(SbConditionVariableWait(&condition_, &mutex_) != - kSbConditionVariableFailed); + SB_CHECK(pthread_cond_wait(&condition_, &mutex_) == 0); } ++readers_; - SB_CHECK(SbMutexRelease(&mutex_)); + SB_CHECK(pthread_mutex_unlock(&mutex_) == 0); } void RWLock::ReleaseReadLock() { - SB_CHECK(SbMutexAcquire(&mutex_) == kSbMutexAcquired); + SB_CHECK(pthread_mutex_lock(&mutex_) == 0); if (--readers_ == 0) { - SB_CHECK(SbConditionVariableBroadcast(&condition_)); + SB_CHECK(pthread_cond_broadcast(&condition_) == 0); } - SB_CHECK(SbMutexRelease(&mutex_)); + SB_CHECK(pthread_mutex_unlock(&mutex_) == 0); } void RWLock::AcquireWriteLock() { - SB_CHECK(SbMutexAcquire(&mutex_) == kSbMutexAcquired); + SB_CHECK(pthread_mutex_lock(&mutex_) == 0); while (writing_) { - SB_CHECK(SbConditionVariableWait(&condition_, &mutex_) != - kSbConditionVariableFailed); + SB_CHECK(pthread_cond_wait(&condition_, &mutex_) == 0); } writing_ = true; while (readers_ > 0) { - SB_CHECK(SbConditionVariableWait(&condition_, &mutex_) != - kSbConditionVariableFailed); + SB_CHECK(pthread_cond_wait(&condition_, &mutex_) == 0); } - SB_CHECK(SbMutexRelease(&mutex_)); + SB_CHECK(pthread_mutex_unlock(&mutex_) == 0); } void RWLock::ReleaseWriteLock() { - SB_CHECK(SbMutexAcquire(&mutex_) == kSbMutexAcquired); + SB_CHECK(pthread_mutex_lock(&mutex_) == 0); writing_ = false; - SB_CHECK(SbConditionVariableBroadcast(&condition_)); - SB_CHECK(SbMutexRelease(&mutex_)); + SB_CHECK(pthread_cond_broadcast(&condition_) == 0); + SB_CHECK(pthread_mutex_unlock(&mutex_) == 0); } } // namespace starboard diff --git a/starboard/common/rwlock.h b/starboard/common/rwlock.h index 73aafddc8f45..2bb8a405c8b3 100644 --- a/starboard/common/rwlock.h +++ b/starboard/common/rwlock.h @@ -20,8 +20,8 @@ #ifndef STARBOARD_COMMON_RWLOCK_H_ #define STARBOARD_COMMON_RWLOCK_H_ -#include "starboard/condition_variable.h" -#include "starboard/mutex.h" +#include +#include namespace starboard { @@ -63,8 +63,8 @@ class RWLock { void ReleaseWriteLock(); private: - SbMutex mutex_; - SbConditionVariable condition_; + pthread_mutex_t mutex_; + pthread_cond_t condition_; int32_t readers_; bool writing_; diff --git a/starboard/condition_variable.h b/starboard/condition_variable.h index 44928fcacd28..5fbb1ad102b6 100644 --- a/starboard/condition_variable.h +++ b/starboard/condition_variable.h @@ -19,6 +19,8 @@ #ifndef STARBOARD_CONDITION_VARIABLE_H_ #define STARBOARD_CONDITION_VARIABLE_H_ +#if SB_API_VERSION < 16 + #include "starboard/export.h" #include "starboard/mutex.h" #include "starboard/types.h" @@ -46,8 +48,7 @@ typedef union SbConditionVariable { #define SB_CONDITION_VARIABLE_INITIALIZER \ {} #else -#define SB_CONDITION_VARIABLE_INITIALIZER \ - { 0 } +#define SB_CONDITION_VARIABLE_INITIALIZER {0} #endif // Enumeration of possible results from waiting on a condvar. @@ -121,4 +122,5 @@ SB_EXPORT bool SbConditionVariableSignal(SbConditionVariable* condition); } // extern "C" #endif +#endif // SB_API_VERSION < 16 #endif // STARBOARD_CONDITION_VARIABLE_H_ diff --git a/starboard/elf_loader/exported_symbols.cc b/starboard/elf_loader/exported_symbols.cc index 943fc21f05e7..421345e1f2b7 100644 --- a/starboard/elf_loader/exported_symbols.cc +++ b/starboard/elf_loader/exported_symbols.cc @@ -139,13 +139,13 @@ ExportedSymbols::ExportedSymbols() { REGISTER_SYMBOL(SbByteSwapU16); REGISTER_SYMBOL(SbByteSwapU32); REGISTER_SYMBOL(SbByteSwapU64); -#endif // SB_API_VERSION < 16 REGISTER_SYMBOL(SbConditionVariableBroadcast); REGISTER_SYMBOL(SbConditionVariableCreate); REGISTER_SYMBOL(SbConditionVariableDestroy); REGISTER_SYMBOL(SbConditionVariableSignal); REGISTER_SYMBOL(SbConditionVariableWait); REGISTER_SYMBOL(SbConditionVariableWaitTimed); +#endif // SB_API_VERSION < 16 REGISTER_SYMBOL(SbCPUFeaturesGet); REGISTER_SYMBOL(SbDecodeTargetGetInfo); REGISTER_SYMBOL(SbDecodeTargetRelease); @@ -259,16 +259,14 @@ ExportedSymbols::ExportedSymbols() { REGISTER_SYMBOL(SbMicrophoneIsSampleRateSupported); REGISTER_SYMBOL(SbMicrophoneOpen); REGISTER_SYMBOL(SbMicrophoneRead); +#if SB_API_VERSION < 16 REGISTER_SYMBOL(SbMutexAcquire); REGISTER_SYMBOL(SbMutexAcquireTry); REGISTER_SYMBOL(SbMutexCreate); REGISTER_SYMBOL(SbMutexDestroy); REGISTER_SYMBOL(SbMutexRelease); - -#if SB_API_VERSION < 16 REGISTER_SYMBOL(SbOnce); #endif // SB_API_VERSION < 16 - REGISTER_SYMBOL(SbPlayerCreate); REGISTER_SYMBOL(SbPlayerDestroy); #if SB_API_VERSION >= 15 @@ -382,46 +380,36 @@ ExportedSymbols::ExportedSymbols() { REGISTER_SYMBOL(SbSystemSupportsResume); REGISTER_SYMBOL(SbSystemSymbolize); REGISTER_SYMBOL(SbThreadContextGetPointer); - REGISTER_SYMBOL(SbThreadCreate); - #if SB_API_VERSION < 16 + REGISTER_SYMBOL(SbThreadCreate); REGISTER_SYMBOL(SbThreadCreateLocalKey); REGISTER_SYMBOL(SbThreadDestroyLocalKey); -#endif // SB_API_VERSION < 16 - REGISTER_SYMBOL(SbThreadDetach); REGISTER_SYMBOL(SbThreadGetCurrent); +#endif // SB_API_VERSION < 16 REGISTER_SYMBOL(SbThreadGetId); - #if SB_API_VERSION >= 16 REGISTER_SYMBOL(SbThreadGetPriority); #endif // SB_API_VERSION >= 16 - #if SB_API_VERSION < 16 REGISTER_SYMBOL(SbThreadGetLocalValue); REGISTER_SYMBOL(SbThreadGetName); -#endif // SB_API_VERSION < 16 - REGISTER_SYMBOL(SbThreadIsEqual); REGISTER_SYMBOL(SbThreadJoin); +#endif // SB_API_VERSION < 16 + REGISTER_SYMBOL(SbThreadSamplerCreate); REGISTER_SYMBOL(SbThreadSamplerDestroy); REGISTER_SYMBOL(SbThreadSamplerFreeze); REGISTER_SYMBOL(SbThreadSamplerIsSupported); REGISTER_SYMBOL(SbThreadSamplerThaw); - #if SB_API_VERSION < 16 REGISTER_SYMBOL(SbThreadSetLocalValue); -#endif // SB_API_VERSION < 16 - -#if SB_API_VERSION < 16 REGISTER_SYMBOL(SbThreadSetName); #endif // SB_API_VERSION < 16 - #if SB_API_VERSION >= 16 REGISTER_SYMBOL(SbThreadSetPriority); #endif // SB_API_VERSION >= 16 - #if SB_API_VERSION < 16 REGISTER_SYMBOL(SbThreadSleep); REGISTER_SYMBOL(SbThreadYield); diff --git a/starboard/extension/extension_test.cc b/starboard/extension/extension_test.cc index 551e834860cc..989bb7c94fb2 100644 --- a/starboard/extension/extension_test.cc +++ b/starboard/extension/extension_test.cc @@ -517,7 +517,7 @@ TEST(ExtensionTest, LoaderAppMetrics) { EXPECT_STREQ(extension_api->name, kExtensionName); EXPECT_GE(extension_api->version, 1u); - EXPECT_LE(extension_api->version, 2u); + EXPECT_LE(extension_api->version, 3u); EXPECT_NE(extension_api->SetCrashpadInstallationStatus, nullptr); EXPECT_NE(extension_api->GetCrashpadInstallationStatus, nullptr); @@ -535,6 +535,11 @@ TEST(ExtensionTest, LoaderAppMetrics) { EXPECT_NE(extension_api->GetMaxSampledUsedCpuBytesDuringElfLoad, nullptr); } + if (extension_api->version >= 3) { + EXPECT_NE(extension_api->SetSlotSelectionStatus, nullptr); + EXPECT_NE(extension_api->GetSlotSelectionStatus, nullptr); + } + const ExtensionApi* second_extension_api = static_cast(SbSystemGetExtension(kExtensionName)); EXPECT_EQ(second_extension_api, extension_api) diff --git a/starboard/extension/loader_app_metrics.h b/starboard/extension/loader_app_metrics.h index ea02a956d7cb..d077f7090e6d 100644 --- a/starboard/extension/loader_app_metrics.h +++ b/starboard/extension/loader_app_metrics.h @@ -28,7 +28,7 @@ extern "C" { // numeric values should never be reused. Must be kept in sync with the // corresponding definition in // tools/metrics/histograms/metadata/cobalt/enums.xml. -typedef enum CrashpadInstallationStatus { +typedef enum class CrashpadInstallationStatus { // The enumerators below this point were added in version 1 or later. kUnknown = 0, kSucceeded = 1, @@ -38,6 +38,23 @@ typedef enum CrashpadInstallationStatus { kMaxValue = kFailedSignalHandlerInstallationFailed } CrashpadInstallationStatus; +typedef enum class SlotSelectionStatus { + // The enumerators below this point were added in version 3 or later. + kUnknown = 0, + kCurrentSlot = 1, + kRollForward = 2, + kRollBackOutOfRetries = 3, + kRollBackNoLibFile = 4, + kRollBackBadAppKeyFile = 5, + kRollBackSlotDraining = 6, + kRollBackFailedToAdopt = 7, + kRollBackFailedToLoadCobalt = 8, + kRollBackFailedToCheckSabi = 9, + kRollBackFailedToLookUpSymbols = 10, + kEGLite = 11, + kMaxValue = kEGLite, +} SlotSelectionStatus; + typedef struct StarboardExtensionLoaderAppMetricsApi { // Name should be the string |kStarboardExtensionLoaderAppMetricsName|. // This helps to validate that the extension API is correct. @@ -87,6 +104,11 @@ typedef struct StarboardExtensionLoaderAppMetricsApi { // using RecordUsedCpuBytesDuringElfLoad(), or -1 if no value was recorded. int64_t (*GetMaxSampledUsedCpuBytesDuringElfLoad)(); + // The fields below this point were added in version 3 or later. + + void (*SetSlotSelectionStatus)(SlotSelectionStatus status); + SlotSelectionStatus (*GetSlotSelectionStatus)(); + } StarboardExtensionLoaderAppMetricsApi; #ifdef __cplusplus diff --git a/starboard/loader_app/BUILD.gn b/starboard/loader_app/BUILD.gn index 25ce107fe6e5..bd0789324c5c 100644 --- a/starboard/loader_app/BUILD.gn +++ b/starboard/loader_app/BUILD.gn @@ -29,6 +29,7 @@ if (sb_is_evergreen_compatible && current_toolchain == starboard_toolchain) { ":app_key", ":installation_manager", ":memory_tracker_thread", + ":record_loader_app_status", ":reset_evergreen_update", ":slot_management", "//starboard:starboard_group", @@ -77,6 +78,14 @@ if (sb_is_evergreen_compatible && sb_evergreen_compatible_package && } } +static_library("record_loader_app_status") { + sources = [ + "record_loader_app_status.cc", + "record_loader_app_status.h", + ] + deps = [ "//starboard:starboard_group" ] +} + if (sb_is_evergreen_compatible && current_toolchain == starboard_toolchain) { target(starboard_level_final_executable_type, "loader_app") { build_loader = false @@ -246,6 +255,7 @@ static_library("installation_manager") { deps = [ ":installation_store_proto", ":pending_restart", + ":record_loader_app_status", "//starboard:starboard_group", ] } diff --git a/starboard/loader_app/installation_manager.cc b/starboard/loader_app/installation_manager.cc index 76639688bf88..ecb3869c6658 100644 --- a/starboard/loader_app/installation_manager.cc +++ b/starboard/loader_app/installation_manager.cc @@ -27,12 +27,14 @@ #include "starboard/common/string.h" #include "starboard/configuration_constants.h" #include "starboard/directory.h" +#include "starboard/extension/loader_app_metrics.h" #include "starboard/file.h" #include "starboard/loader_app/installation_store.pb.h" #if !SB_IS(EVERGREEN_COMPATIBLE_LITE) #include "starboard/loader_app/pending_restart.h" // nogncheck #endif // !SB_IS(EVERGREEN_COMPATIBLE_LITE) #include "starboard/common/once.h" +#include "starboard/loader_app/record_loader_app_status.h" #include "starboard/string.h" namespace starboard { @@ -54,7 +56,7 @@ class InstallationManager { int RollForward(int installation_index); int DecrementInstallationNumTries(int installation_index); - int RevertToSuccessfulInstallation(); + int RevertToSuccessfulInstallation(SlotSelectionStatus status); int GetInstallationPath(int installation_index, char* path, int path_length); int GetCurrentInstallationIndex(); int MarkInstallationSuccessful(int installation_index); @@ -299,7 +301,8 @@ int InstallationManager::DecrementInstallationNumTries(int installation_index) { // [x] => [ ] // low [ ] [-] // -int InstallationManager::RevertToSuccessfulInstallation() { +int InstallationManager::RevertToSuccessfulInstallation( + SlotSelectionStatus status) { if (!initialized_) { SB_LOG(ERROR) << "RevertToSuccessfulInstallation: not initialized"; return IM_ERROR; @@ -347,6 +350,7 @@ int InstallationManager::RevertToSuccessfulInstallation() { << DumpInstallationSlots(); if (SaveInstallationStore()) { + RecordSlotSelectionStatus(status); return fallback_installation; } return IM_ERROR; @@ -418,7 +422,12 @@ int InstallationManager::RollForwardInternal(int installation_index) { current_installation_ = installation_index; SB_DLOG(INFO) << "RollForwardInternal: " << DumpInstallationSlots(); - return SaveInstallationStore() ? IM_SUCCESS : IM_ERROR; + + if (SaveInstallationStore()) { + RecordSlotSelectionStatus(SlotSelectionStatus::kRollForward); + return IM_SUCCESS; + } + return IM_ERROR; } // Shift the priority in the inclusive range either up or down based @@ -831,9 +840,9 @@ int ImRollForward(int installation_index) { return g_installation_manager_->RollForward(installation_index); } -int ImRevertToSuccessfulInstallation() { +int ImRevertToSuccessfulInstallation(SlotSelectionStatus status) { starboard::ScopedLock lock(*GetImMutex()); - return g_installation_manager_->RevertToSuccessfulInstallation(); + return g_installation_manager_->RevertToSuccessfulInstallation(status); } int ImRequestRollForwardToInstallation(int installation_index) { diff --git a/starboard/loader_app/installation_manager.h b/starboard/loader_app/installation_manager.h index 8ace1ac348d0..adf2d6796736 100644 --- a/starboard/loader_app/installation_manager.h +++ b/starboard/loader_app/installation_manager.h @@ -15,6 +15,8 @@ #ifndef STARBOARD_LOADER_APP_INSTALLATION_MANAGER_H_ #define STARBOARD_LOADER_APP_INSTALLATION_MANAGER_H_ +#include "starboard/extension/loader_app_metrics.h" + #ifdef __cplusplus extern "C" { #endif @@ -122,7 +124,7 @@ int ImRollForward(int installation_index); // Revert to a previous successful installation. // Returns the installation to which it was reverted. // Returns |IM_ERROR| on error. -int ImRevertToSuccessfulInstallation(); +int ImRevertToSuccessfulInstallation(SlotSelectionStatus status); // Request the installation at |installation_index| to be rolled // forward next time the Loader App tries to load the app. diff --git a/starboard/loader_app/installation_manager_test.cc b/starboard/loader_app/installation_manager_test.cc index fbf394fd28c1..ff6d02ac5f20 100644 --- a/starboard/loader_app/installation_manager_test.cc +++ b/starboard/loader_app/installation_manager_test.cc @@ -21,6 +21,7 @@ #include "starboard/common/file.h" #include "starboard/configuration_constants.h" +#include "starboard/extension/loader_app_metrics.h" #include "starboard/loader_app/installation_store.pb.h" #include "testing/gtest/include/gtest/gtest.h" @@ -146,7 +147,8 @@ class InstallationManagerTest : public ::testing::TestWithParam { SaveStorageState(installation_store); ASSERT_EQ(IM_SUCCESS, ImInitialize(max_num_installations, kAppKey)); - int result = ImRevertToSuccessfulInstallation(); + int result = + ImRevertToSuccessfulInstallation(SlotSelectionStatus::kUnknown); if (!expected_succeed) { ASSERT_EQ(IM_ERROR, result); } @@ -398,7 +400,7 @@ TEST_P(InstallationManagerTest, RevertToSuccessfulInstallation) { ASSERT_EQ(1, ImGetCurrentInstallationIndex()); ASSERT_EQ(IM_SUCCESS, ImMarkInstallationSuccessful(1)); ASSERT_EQ(1, ImGetCurrentInstallationIndex()); - ASSERT_EQ(0, ImRevertToSuccessfulInstallation()); + ASSERT_EQ(0, ImRevertToSuccessfulInstallation(SlotSelectionStatus::kUnknown)); ASSERT_EQ(0, ImGetCurrentInstallationIndex()); } @@ -410,7 +412,8 @@ TEST_F(InstallationManagerTest, InvalidInput) { ASSERT_EQ(IM_INSTALLATION_STATUS_ERROR, ImGetInstallationStatus(10)); ASSERT_EQ(IM_SUCCESS, ImMarkInstallationSuccessful(0)); ASSERT_EQ(IM_INSTALLATION_STATUS_ERROR, ImGetInstallationStatus(-2)); - ASSERT_EQ(IM_ERROR, ImRevertToSuccessfulInstallation()); + ASSERT_EQ(IM_ERROR, + ImRevertToSuccessfulInstallation(SlotSelectionStatus::kUnknown)); ASSERT_EQ(IM_ERROR, ImMarkInstallationSuccessful(10)); ASSERT_EQ(IM_ERROR, ImMarkInstallationSuccessful(-2)); ASSERT_EQ(IM_ERROR, ImDecrementInstallationNumTries(10)); diff --git a/starboard/loader_app/loader_app.cc b/starboard/loader_app/loader_app.cc index 272ec52eefa6..c8b439758f2e 100644 --- a/starboard/loader_app/loader_app.cc +++ b/starboard/loader_app/loader_app.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include @@ -26,15 +27,16 @@ #include "starboard/elf_loader/evergreen_info.h" #include "starboard/elf_loader/sabi_string.h" #include "starboard/event.h" +#include "starboard/extension/loader_app_metrics.h" #include "starboard/file.h" #include "starboard/loader_app/app_key.h" #include "starboard/loader_app/loader_app_switches.h" #include "starboard/loader_app/memory_tracker_thread.h" +#include "starboard/loader_app/record_loader_app_status.h" #include "starboard/loader_app/reset_evergreen_update.h" #include "starboard/loader_app/slot_management.h" #include "starboard/loader_app/system_get_extension_shim.h" #include "starboard/memory.h" -#include "starboard/mutex.h" #include "starboard/shared/starboard/command_line.h" #include "starboard/string.h" #include "third_party/crashpad/crashpad/wrapper/annotations.h" @@ -191,9 +193,9 @@ void LoadLibraryAndInitialize(const std::string& alternative_content_path, } // namespace void SbEventHandle(const SbEvent* event) { - static SbMutex mutex = SB_MUTEX_INITIALIZER; + static pthread_mutex_t mutex PTHREAD_MUTEX_INITIALIZER; - SB_CHECK(SbMutexAcquire(&mutex) == kSbMutexAcquired); + SB_CHECK(pthread_mutex_lock(&mutex) == 0); if (!g_sb_event_func && (event->type == kSbEventTypeStart || event->type == kSbEventTypePreload)) { @@ -205,7 +207,7 @@ void SbEventHandle(const SbEvent* event) { SB_LOG(INFO) << "Resetting the Evergreen Update"; starboard::loader_app::ResetEvergreenUpdate(); SbSystemRequestStop(0); - SB_CHECK(SbMutexRelease(&mutex) == true); + SB_CHECK(pthread_mutex_unlock(&mutex) == 0); return; } @@ -259,6 +261,8 @@ void SbEventHandle(const SbEvent* event) { } if (is_evergreen_lite) { + starboard::loader_app::RecordSlotSelectionStatus( + SlotSelectionStatus::kEGLite); LoadLibraryAndInitialize(alternative_content, use_memory_mapped_file); } else { std::string url = @@ -281,5 +285,5 @@ void SbEventHandle(const SbEvent* event) { g_sb_event_func(event); } - SB_CHECK(SbMutexRelease(&mutex) == true); + SB_CHECK(pthread_mutex_unlock(&mutex) == 0); } diff --git a/starboard/loader_app/record_loader_app_status.cc b/starboard/loader_app/record_loader_app_status.cc new file mode 100644 index 000000000000..12c310433f5c --- /dev/null +++ b/starboard/loader_app/record_loader_app_status.cc @@ -0,0 +1,37 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// 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 +// +// http://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. + +#include "starboard/loader_app/record_loader_app_status.h" + +#include + +#include "starboard/system.h" + +namespace starboard { +namespace loader_app { + +void RecordSlotSelectionStatus(SlotSelectionStatus status) { + auto metrics_extension = + static_cast( + SbSystemGetExtension(kStarboardExtensionLoaderAppMetricsName)); + if (metrics_extension && + strcmp(metrics_extension->name, + kStarboardExtensionLoaderAppMetricsName) == 0 && + metrics_extension->version >= 3) { + metrics_extension->SetSlotSelectionStatus(status); + } +} + +} // namespace loader_app +} // namespace starboard diff --git a/starboard/loader_app/record_loader_app_status.h b/starboard/loader_app/record_loader_app_status.h new file mode 100644 index 000000000000..8f6ac52f7713 --- /dev/null +++ b/starboard/loader_app/record_loader_app_status.h @@ -0,0 +1,31 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// 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 +// +// http://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. + +#ifndef STARBOARD_LOADER_APP_RECORD_LOADER_APP_STATUS_H_ +#define STARBOARD_LOADER_APP_RECORD_LOADER_APP_STATUS_H_ + +#include + +#include "starboard/extension/loader_app_metrics.h" + +namespace starboard { +namespace loader_app { + +// Persist the slot selection status so that it can be read in the Cobalt layer +void RecordSlotSelectionStatus(SlotSelectionStatus status); + +} // namespace loader_app +} // namespace starboard + +#endif // STARBOARD_LOADER_APP_RECORD_LOADER_APP_STATUS_H_ diff --git a/starboard/loader_app/slot_management.cc b/starboard/loader_app/slot_management.cc index 928687e0f259..c576e565ed4c 100644 --- a/starboard/loader_app/slot_management.cc +++ b/starboard/loader_app/slot_management.cc @@ -24,6 +24,7 @@ #include "starboard/elf_loader/elf_loader_constants.h" #include "starboard/elf_loader/sabi_string.h" #include "starboard/event.h" +#include "starboard/extension/loader_app_metrics.h" #include "starboard/file.h" #include "starboard/loader_app/app_key_files.h" #include "starboard/loader_app/drain_file.h" @@ -57,7 +58,8 @@ const char kCobaltContentPath[] = "content"; int RevertBack(int current_installation, const std::string& app_key, - bool mark_bad) { + bool mark_bad, + SlotSelectionStatus status) { SB_LOG(INFO) << "RevertBack current_installation=" << current_installation; SB_DCHECK(current_installation != 0); if (mark_bad) { @@ -82,7 +84,7 @@ int RevertBack(int current_installation, << current_installation; } } - current_installation = ImRevertToSuccessfulInstallation(); + current_installation = ImRevertToSuccessfulInstallation(status); return current_installation; } @@ -163,7 +165,8 @@ void* LoadSlotManagedLibrary(const std::string& app_key, // the current image is not the system image. if (current_installation != 0) { current_installation = - RevertBack(current_installation, app_key, true /* mark_bad */); + RevertBack(current_installation, app_key, true /* mark_bad */, + SlotSelectionStatus::kRollBackOutOfRetries); } } } @@ -181,7 +184,8 @@ void* LoadSlotManagedLibrary(const std::string& app_key, // the current image is not the system image. if (current_installation != 0) { current_installation = - RevertBack(current_installation, app_key, true /* mark_bad */); + RevertBack(current_installation, app_key, true /* mark_bad */, + SlotSelectionStatus::kRollBackNoLibFile); continue; } else { // The system image at index 0 failed. @@ -202,7 +206,8 @@ void* LoadSlotManagedLibrary(const std::string& app_key, if (CheckBadFileExists(installation_path.data(), app_key.c_str())) { SB_LOG(INFO) << "Bad app key file"; current_installation = - RevertBack(current_installation, app_key, true /* mark_bad */); + RevertBack(current_installation, app_key, true /* mark_bad */, + SlotSelectionStatus::kRollBackBadAppKeyFile); continue; } // If the current installation is in use by an updater roll back. @@ -210,7 +215,8 @@ void* LoadSlotManagedLibrary(const std::string& app_key, app_key.c_str())) { SB_LOG(INFO) << "Active slot draining"; current_installation = - RevertBack(current_installation, app_key, false /* mark_bad */); + RevertBack(current_installation, app_key, false /* mark_bad */, + SlotSelectionStatus::kRollBackSlotDraining); continue; } // Adopt installation performed from different app. @@ -218,7 +224,8 @@ void* LoadSlotManagedLibrary(const std::string& app_key, app_key.c_str())) { SB_LOG(INFO) << "Unable to adopt installation"; current_installation = - RevertBack(current_installation, app_key, true /* mark_bad */); + RevertBack(current_installation, app_key, true /* mark_bad */, + SlotSelectionStatus::kRollBackFailedToAdopt); continue; } } @@ -277,7 +284,8 @@ void* LoadSlotManagedLibrary(const std::string& app_key, // the current image is not the system image. if (current_installation != 0) { current_installation = - RevertBack(current_installation, app_key, true /* mark_bad */); + RevertBack(current_installation, app_key, true /* mark_bad */, + SlotSelectionStatus::kRollBackFailedToLoadCobalt); continue; } else { // The system image at index 0 failed. @@ -304,7 +312,8 @@ void* LoadSlotManagedLibrary(const std::string& app_key, // the current image is not the system image. if (current_installation != 0) { current_installation = - RevertBack(current_installation, app_key, true /* mark_bad */); + RevertBack(current_installation, app_key, true /* mark_bad */, + SlotSelectionStatus::kRollBackFailedToCheckSabi); continue; } else { // The system image at index 0 failed. @@ -341,7 +350,8 @@ void* LoadSlotManagedLibrary(const std::string& app_key, // the current image is not the system image. if (current_installation != 0) { current_installation = - RevertBack(current_installation, app_key, true /* mark_bad */); + RevertBack(current_installation, app_key, true /* mark_bad */, + SlotSelectionStatus::kRollBackFailedToLookUpSymbols); continue; } else { // The system image at index 0 failed. diff --git a/starboard/mutex.h b/starboard/mutex.h index 0abc610e558e..c7dbcd810244 100644 --- a/starboard/mutex.h +++ b/starboard/mutex.h @@ -20,6 +20,8 @@ #ifndef STARBOARD_MUTEX_H_ #define STARBOARD_MUTEX_H_ +#if SB_API_VERSION < 16 + #include "starboard/configuration.h" #include "starboard/export.h" #include "starboard/thread.h" @@ -47,8 +49,7 @@ typedef union SbMutex { #define SB_MUTEX_INITIALIZER \ {} #else -#define SB_MUTEX_INITIALIZER \ - { 0 } +#define SB_MUTEX_INITIALIZER {0} #endif // Enumeration of possible results from acquiring a mutex. @@ -108,4 +109,5 @@ SB_EXPORT bool SbMutexRelease(SbMutex* mutex); } // extern "C" #endif +#endif // SB_API_VERSION < 16 #endif // STARBOARD_MUTEX_H_ diff --git a/starboard/nplb/condition_variable_broadcast_test.cc b/starboard/nplb/condition_variable_broadcast_test.cc index c6c0854962a7..fe6bc6dd1bd6 100644 --- a/starboard/nplb/condition_variable_broadcast_test.cc +++ b/starboard/nplb/condition_variable_broadcast_test.cc @@ -14,7 +14,9 @@ // Broadcast is Sunny Day tested in most of the other SbConditionVariable tests. -#include "starboard/common/condition_variable.h" +#if SB_API_VERSION < 16 + +#include "starboard/condition_variable.h" #include "testing/gtest/include/gtest/gtest.h" namespace starboard { @@ -34,3 +36,5 @@ TEST(SbConditionVariableBroadcastTest, RainyDayNull) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/condition_variable_create_test.cc b/starboard/nplb/condition_variable_create_test.cc index 4c9fb201a12b..d330f1c6c5cb 100644 --- a/starboard/nplb/condition_variable_create_test.cc +++ b/starboard/nplb/condition_variable_create_test.cc @@ -12,8 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "starboard/common/condition_variable.h" +#if SB_API_VERSION < 16 + #include "starboard/common/mutex.h" +#include "starboard/condition_variable.h" #include "testing/gtest/include/gtest/gtest.h" namespace starboard { @@ -83,3 +85,5 @@ TEST(SbConditionVariableCreateTest, SunnyDayNullMutex) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/condition_variable_destroy_test.cc b/starboard/nplb/condition_variable_destroy_test.cc index 223b4b09b25c..0b830cafe1c6 100644 --- a/starboard/nplb/condition_variable_destroy_test.cc +++ b/starboard/nplb/condition_variable_destroy_test.cc @@ -14,6 +14,8 @@ // Destroy is mostly Sunny Day tested in Create. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" #include "starboard/common/mutex.h" #include "starboard/nplb/thread_helpers.h" @@ -36,3 +38,5 @@ TEST(SbConditionVariableDestroyTest, RainyDayNull) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/condition_variable_signal_test.cc b/starboard/nplb/condition_variable_signal_test.cc index a284e0be635b..705aefcd567e 100644 --- a/starboard/nplb/condition_variable_signal_test.cc +++ b/starboard/nplb/condition_variable_signal_test.cc @@ -14,7 +14,9 @@ // Signal is Sunny Day tested in most of the other SbConditionVariable tests. -#include "starboard/common/condition_variable.h" +#if SB_API_VERSION < 16 + +#include "starboard/condition_variable.h" #include "testing/gtest/include/gtest/gtest.h" namespace starboard { @@ -34,3 +36,5 @@ TEST(SbConditionVariableSignalTest, RainyDayNull) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/condition_variable_wait_test.cc b/starboard/nplb/condition_variable_wait_test.cc index 94a0df906eda..ffb81c1f450a 100644 --- a/starboard/nplb/condition_variable_wait_test.cc +++ b/starboard/nplb/condition_variable_wait_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/configuration_constants.h" #include "starboard/nplb/thread_helpers.h" #include "starboard/thread.h" @@ -88,3 +90,5 @@ TEST(SbConditionVariableWaitTest, RainyDayNull) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/condition_variable_wait_timed_test.cc b/starboard/nplb/condition_variable_wait_timed_test.cc index f27f7b52c862..1079c603231f 100644 --- a/starboard/nplb/condition_variable_wait_timed_test.cc +++ b/starboard/nplb/condition_variable_wait_timed_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" #include "starboard/common/mutex.h" #include "starboard/common/time.h" @@ -170,3 +172,5 @@ TEST(SbConditionVariableWaitTimedTest, RainyDayNull) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/mutex_acquire_test.cc b/starboard/nplb/mutex_acquire_test.cc index f8d78a4f4a78..e2556bf430e2 100644 --- a/starboard/nplb/mutex_acquire_test.cc +++ b/starboard/nplb/mutex_acquire_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/configuration.h" #include "starboard/mutex.h" #include "starboard/thread.h" @@ -103,3 +105,5 @@ TEST(SbMutexAcquireTest, RainyDayReleaseNull) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/mutex_acquire_try_test.cc b/starboard/nplb/mutex_acquire_try_test.cc index 7d78855f1f74..c393478c1525 100644 --- a/starboard/nplb/mutex_acquire_try_test.cc +++ b/starboard/nplb/mutex_acquire_try_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/configuration.h" #include "starboard/mutex.h" #include "testing/gtest/include/gtest/gtest.h" @@ -82,3 +84,5 @@ TEST(SbMutexAcquireTest, RainyDayAcquireTryNull) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/mutex_create_test.cc b/starboard/nplb/mutex_create_test.cc index 7ec4e1c2ca7e..a1673ceeec17 100644 --- a/starboard/nplb/mutex_create_test.cc +++ b/starboard/nplb/mutex_create_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/configuration.h" #include "starboard/mutex.h" #include "testing/gtest/include/gtest/gtest.h" @@ -64,3 +66,5 @@ TEST(SbMutexCreateTest, RainyDayNull) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/mutex_destroy_test.cc b/starboard/nplb/mutex_destroy_test.cc index 96fa12009384..6c813388a1b2 100644 --- a/starboard/nplb/mutex_destroy_test.cc +++ b/starboard/nplb/mutex_destroy_test.cc @@ -14,6 +14,8 @@ // Destroy is mostly Sunny Day tested in Create. +#if SB_API_VERSION < 16 + #include "starboard/configuration.h" #include "starboard/mutex.h" #include "testing/gtest/include/gtest/gtest.h" @@ -36,3 +38,5 @@ TEST(SbMutexDestroyTest, RainyDayNull) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/nplb_evergreen_compat_tests/loader_app_metrics_test.cc b/starboard/nplb/nplb_evergreen_compat_tests/loader_app_metrics_test.cc index f421b53a88a6..07b24b62d23d 100644 --- a/starboard/nplb/nplb_evergreen_compat_tests/loader_app_metrics_test.cc +++ b/starboard/nplb/nplb_evergreen_compat_tests/loader_app_metrics_test.cc @@ -44,7 +44,7 @@ TEST_F(LoaderAppMetricsTest, VerifyLoaderAppMetricsExtension) { // shared implementation of the extension, it's reasonable to expect them to // be on the latest version of the extension API available at the commit from // which this test is built. - ASSERT_EQ(extension->version, 2u); + ASSERT_EQ(extension->version, 3u); } } // namespace diff --git a/starboard/nplb/thread_create_test.cc b/starboard/nplb/thread_create_test.cc index 7d6cde1bd2da..cc06902505cf 100644 --- a/starboard/nplb/thread_create_test.cc +++ b/starboard/nplb/thread_create_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/configuration_constants.h" #include "starboard/nplb/thread_helpers.h" #include "starboard/thread.h" @@ -169,3 +171,5 @@ TEST(SbThreadCreateTest, RainyDayNoEntryPoint) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/thread_detach_test.cc b/starboard/nplb/thread_detach_test.cc index ac4d3a82bbfa..e50b51be25f5 100644 --- a/starboard/nplb/thread_detach_test.cc +++ b/starboard/nplb/thread_detach_test.cc @@ -14,6 +14,8 @@ // Thread joining is mostly tested in the other tests. +#if SB_API_VERSION < 16 + #include "starboard/nplb/thread_helpers.h" #include "starboard/thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -40,3 +42,5 @@ TEST(SbThreadDetachTest, RainyDayInvalid) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/thread_get_current_test.cc b/starboard/nplb/thread_get_current_test.cc index 541894ed312e..db12599d450d 100644 --- a/starboard/nplb/thread_get_current_test.cc +++ b/starboard/nplb/thread_get_current_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/nplb/thread_helpers.h" #include "starboard/thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -45,3 +47,5 @@ TEST(SbThreadGetCurrentTest, SunnyDay) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/thread_get_id_test.cc b/starboard/nplb/thread_get_id_test.cc index 0fcc0897c75e..e4494162a96f 100644 --- a/starboard/nplb/thread_get_id_test.cc +++ b/starboard/nplb/thread_get_id_test.cc @@ -14,6 +14,8 @@ // Thread joining is mostly tested in the other tests. +#if SB_API_VERSION < 16 + #include "starboard/nplb/thread_helpers.h" #include "starboard/thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -62,3 +64,5 @@ TEST(SbThreadGetIdTest, SunnyDayDifferentIds) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/thread_helpers.cc b/starboard/nplb/thread_helpers.cc index 283eaf77d167..66e893fb0f77 100644 --- a/starboard/nplb/thread_helpers.cc +++ b/starboard/nplb/thread_helpers.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include #include "starboard/nplb/thread_helpers.h" @@ -91,3 +93,5 @@ void WaiterContext::WaitForReturnSignal() { } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/thread_helpers.h b/starboard/nplb/thread_helpers.h index 709613062799..fcc1a6f8738a 100644 --- a/starboard/nplb/thread_helpers.h +++ b/starboard/nplb/thread_helpers.h @@ -15,9 +15,11 @@ #ifndef STARBOARD_NPLB_THREAD_HELPERS_H_ #define STARBOARD_NPLB_THREAD_HELPERS_H_ -#include "starboard/common/condition_variable.h" +#if SB_API_VERSION < 16 + #include "starboard/common/mutex.h" #include "starboard/common/semaphore.h" +#include "starboard/condition_variable.h" #include "starboard/configuration.h" #include "starboard/thread.h" #include "starboard/types.h" @@ -195,4 +197,5 @@ class AbstractTestThread { } // namespace nplb } // namespace starboard +#endif // SB_API_VERSION < 16 #endif // STARBOARD_NPLB_THREAD_HELPERS_H_ diff --git a/starboard/nplb/thread_is_equal_test.cc b/starboard/nplb/thread_is_equal_test.cc index f0963acb6b82..5ab5ffd24b51 100644 --- a/starboard/nplb/thread_is_equal_test.cc +++ b/starboard/nplb/thread_is_equal_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/nplb/thread_helpers.h" #include "starboard/thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -37,3 +39,5 @@ TEST(SbThreadIsEqualTest, Everything) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/nplb/thread_join_test.cc b/starboard/nplb/thread_join_test.cc index 341aba335471..bf951043c179 100644 --- a/starboard/nplb/thread_join_test.cc +++ b/starboard/nplb/thread_join_test.cc @@ -14,6 +14,8 @@ // Thread joining is mostly tested in the other tests. +#if SB_API_VERSION < 16 + #include #include "starboard/thread.h" @@ -71,3 +73,5 @@ TEST(SbThreadLocalValueTest, ThreadJoinWaitsForFunctionRun) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/condition_variable_broadcast.cc b/starboard/shared/pthread/condition_variable_broadcast.cc index db5df4cbba01..e45b259dac1d 100644 --- a/starboard/shared/pthread/condition_variable_broadcast.cc +++ b/starboard/shared/pthread/condition_variable_broadcast.cc @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "starboard/common/condition_variable.h" +#if SB_API_VERSION < 16 + +#include "starboard/condition_variable.h" #include @@ -37,3 +39,5 @@ bool SbConditionVariableBroadcast(SbConditionVariable* condition) { return IsSuccess(pthread_cond_broadcast( &(SB_PTHREAD_INTERNAL_CONDITION(condition)->condition))); } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/condition_variable_create.cc b/starboard/shared/pthread/condition_variable_create.cc index 0dd49cb574a1..52a98a239062 100644 --- a/starboard/shared/pthread/condition_variable_create.cc +++ b/starboard/shared/pthread/condition_variable_create.cc @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "starboard/common/condition_variable.h" +#if SB_API_VERSION < 16 + +#include "starboard/condition_variable.h" #include @@ -85,3 +87,5 @@ bool SbConditionVariableCreate(SbConditionVariable* out_condition, return status; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/condition_variable_destroy.cc b/starboard/shared/pthread/condition_variable_destroy.cc index 9260326dc082..9c8e30f4be9c 100644 --- a/starboard/shared/pthread/condition_variable_destroy.cc +++ b/starboard/shared/pthread/condition_variable_destroy.cc @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "starboard/common/condition_variable.h" +#if SB_API_VERSION < 16 + +#include "starboard/condition_variable.h" #include @@ -37,3 +39,5 @@ bool SbConditionVariableDestroy(SbConditionVariable* condition) { return IsSuccess(pthread_cond_destroy( &(SB_PTHREAD_INTERNAL_CONDITION(condition)->condition))); } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/condition_variable_signal.cc b/starboard/shared/pthread/condition_variable_signal.cc index 5aa69a23adc9..b8ee61d2f45a 100644 --- a/starboard/shared/pthread/condition_variable_signal.cc +++ b/starboard/shared/pthread/condition_variable_signal.cc @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "starboard/common/condition_variable.h" +#if SB_API_VERSION < 16 + +#include "starboard/condition_variable.h" #include @@ -37,3 +39,5 @@ bool SbConditionVariableSignal(SbConditionVariable* condition) { return IsSuccess(pthread_cond_signal( &(SB_PTHREAD_INTERNAL_CONDITION(condition)->condition))); } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/condition_variable_wait.cc b/starboard/shared/pthread/condition_variable_wait.cc index fcd506a6af43..397d94d078ab 100644 --- a/starboard/shared/pthread/condition_variable_wait.cc +++ b/starboard/shared/pthread/condition_variable_wait.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/condition_variable.h" #include @@ -46,3 +48,4 @@ SbConditionVariableResult SbConditionVariableWait( return kSbConditionVariableFailed; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/condition_variable_wait_timed.cc b/starboard/shared/pthread/condition_variable_wait_timed.cc index 6965b5901667..8807680cecd0 100644 --- a/starboard/shared/pthread/condition_variable_wait_timed.cc +++ b/starboard/shared/pthread/condition_variable_wait_timed.cc @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "starboard/common/condition_variable.h" +#if SB_API_VERSION < 16 + +#include "starboard/condition_variable.h" #include #include @@ -77,3 +79,5 @@ SbConditionVariableResult SbConditionVariableWaitTimed( return kSbConditionVariableFailed; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/mutex_acquire.cc b/starboard/shared/pthread/mutex_acquire.cc index cf951e4fce64..a9f4d26b7eed 100644 --- a/starboard/shared/pthread/mutex_acquire.cc +++ b/starboard/shared/pthread/mutex_acquire.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -47,3 +49,5 @@ SbMutexResult SbMutexAcquire(SbMutex* mutex) { return kSbMutexBusy; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/mutex_acquire_try.cc b/starboard/shared/pthread/mutex_acquire_try.cc index f9d86a3c18ed..58fb709b5e3a 100644 --- a/starboard/shared/pthread/mutex_acquire_try.cc +++ b/starboard/shared/pthread/mutex_acquire_try.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -40,3 +42,5 @@ SbMutexResult SbMutexAcquireTry(SbMutex* mutex) { return kSbMutexBusy; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/mutex_create.cc b/starboard/shared/pthread/mutex_create.cc index 744caf49f3c5..e24abce5dd2a 100644 --- a/starboard/shared/pthread/mutex_create.cc +++ b/starboard/shared/pthread/mutex_create.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -33,3 +35,5 @@ bool SbMutexCreate(SbMutex* mutex) { SetInitialized(&(SB_INTERNAL_MUTEX(mutex)->initialized_state)); return IsSuccess(pthread_mutex_init(SB_PTHREAD_INTERNAL_MUTEX(mutex), NULL)); } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/mutex_destroy.cc b/starboard/shared/pthread/mutex_destroy.cc index 3fb53f5f9edd..754c52d14019 100644 --- a/starboard/shared/pthread/mutex_destroy.cc +++ b/starboard/shared/pthread/mutex_destroy.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -38,3 +40,5 @@ bool SbMutexDestroy(SbMutex* mutex) { // thread, as well as deleting a locked mutex, result in undefined behavior. return IsSuccess(pthread_mutex_destroy(SB_PTHREAD_INTERNAL_MUTEX(mutex))); } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/mutex_release.cc b/starboard/shared/pthread/mutex_release.cc index 86b318faeec2..0dbe87f363ce 100644 --- a/starboard/shared/pthread/mutex_release.cc +++ b/starboard/shared/pthread/mutex_release.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -33,3 +35,4 @@ bool SbMutexRelease(SbMutex* mutex) { } return IsSuccess(pthread_mutex_unlock(SB_PTHREAD_INTERNAL_MUTEX(mutex))); } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/thread_create.cc b/starboard/shared/pthread/thread_create.cc index 1b9f7f14f696..41167eb00f54 100644 --- a/starboard/shared/pthread/thread_create.cc +++ b/starboard/shared/pthread/thread_create.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" #include @@ -127,3 +129,5 @@ SbThread SbThreadCreate(int64_t stack_size, return kSbThreadInvalid; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/thread_detach.cc b/starboard/shared/pthread/thread_detach.cc index 3ba7471c814a..3a760d83727c 100644 --- a/starboard/shared/pthread/thread_detach.cc +++ b/starboard/shared/pthread/thread_detach.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" #include @@ -25,3 +27,5 @@ void SbThreadDetach(SbThread thread) { pthread_detach(SB_PTHREAD_INTERNAL_THREAD(thread)); } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/thread_get_current.cc b/starboard/shared/pthread/thread_get_current.cc index f547371e39b2..62a5d98576ca 100644 --- a/starboard/shared/pthread/thread_get_current.cc +++ b/starboard/shared/pthread/thread_get_current.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" #include @@ -21,3 +23,4 @@ SbThread SbThreadGetCurrent() { return SB_THREAD(pthread_self()); } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/thread_is_equal.cc b/starboard/shared/pthread/thread_is_equal.cc index c8c634988647..7131ef3cdfe8 100644 --- a/starboard/shared/pthread/thread_is_equal.cc +++ b/starboard/shared/pthread/thread_is_equal.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" #include @@ -22,3 +24,5 @@ bool SbThreadIsEqual(SbThread thread1, SbThread thread2) { return pthread_equal(SB_PTHREAD_INTERNAL_THREAD(thread1), SB_PTHREAD_INTERNAL_THREAD(thread2)) != 0; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/pthread/thread_join.cc b/starboard/shared/pthread/thread_join.cc index d4488db2e77a..3136701fdb68 100644 --- a/starboard/shared/pthread/thread_join.cc +++ b/starboard/shared/pthread/thread_join.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" #include @@ -36,3 +38,5 @@ bool SbThreadJoin(SbThread thread, void** out_return) { return true; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/starboard/loader_app_metrics.cc b/starboard/shared/starboard/loader_app_metrics.cc index 388e8c08d85d..c9b831d222a6 100644 --- a/starboard/shared/starboard/loader_app_metrics.cc +++ b/starboard/shared/starboard/loader_app_metrics.cc @@ -36,6 +36,8 @@ static int64_t g_elf_decompression_duration_us = -1; static int64_t g_max_sampled_cpu_bytes_during_elf_load = -1; +static SlotSelectionStatus g_slot_selection_status; + void SetCrashpadInstallationStatus(CrashpadInstallationStatus status) { g_crashpad_installation_status = status; } @@ -78,9 +80,17 @@ int64_t GetMaxSampledUsedCpuBytesDuringElfLoad() { return g_max_sampled_cpu_bytes_during_elf_load; } +void SetSlotSelectionStatus(SlotSelectionStatus status) { + g_slot_selection_status = status; +} + +SlotSelectionStatus GetSlotSelectionStatus() { + return g_slot_selection_status; +} + const StarboardExtensionLoaderAppMetricsApi kLoaderAppMetricsApi = { kStarboardExtensionLoaderAppMetricsName, - 2, + 3, &SetCrashpadInstallationStatus, &GetCrashpadInstallationStatus, &SetElfLibraryStoredCompressed, @@ -90,7 +100,9 @@ const StarboardExtensionLoaderAppMetricsApi kLoaderAppMetricsApi = { &SetElfDecompressionDurationMicroseconds, &GetElfDecompressionDurationMicroseconds, &RecordUsedCpuBytesDuringElfLoad, - &GetMaxSampledUsedCpuBytesDuringElfLoad}; + &GetMaxSampledUsedCpuBytesDuringElfLoad, + &SetSlotSelectionStatus, + &GetSlotSelectionStatus}; } // namespace diff --git a/starboard/shared/stub/condition_variable_broadcast.cc b/starboard/shared/stub/condition_variable_broadcast.cc index f7bfa45824ae..056366ac914b 100644 --- a/starboard/shared/stub/condition_variable_broadcast.cc +++ b/starboard/shared/stub/condition_variable_broadcast.cc @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" bool SbConditionVariableBroadcast(SbConditionVariable* condition) { return false; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/condition_variable_create.cc b/starboard/shared/stub/condition_variable_create.cc index c11de476c107..1589001f9a55 100644 --- a/starboard/shared/stub/condition_variable_create.cc +++ b/starboard/shared/stub/condition_variable_create.cc @@ -12,9 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 #include "starboard/common/condition_variable.h" bool SbConditionVariableCreate(SbConditionVariable* out_condition, SbMutex* opt_mutex) { return false; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/condition_variable_destroy.cc b/starboard/shared/stub/condition_variable_destroy.cc index 5b213d6c3c8a..654d2b1c9318 100644 --- a/starboard/shared/stub/condition_variable_destroy.cc +++ b/starboard/shared/stub/condition_variable_destroy.cc @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" bool SbConditionVariableDestroy(SbConditionVariable* condition) { return false; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/condition_variable_signal.cc b/starboard/shared/stub/condition_variable_signal.cc index 73589d4d44bf..6f905ead1d47 100644 --- a/starboard/shared/stub/condition_variable_signal.cc +++ b/starboard/shared/stub/condition_variable_signal.cc @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" bool SbConditionVariableSignal(SbConditionVariable* condition) { return false; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/condition_variable_wait.cc b/starboard/shared/stub/condition_variable_wait.cc index e649efdbecbc..8735a72337bb 100644 --- a/starboard/shared/stub/condition_variable_wait.cc +++ b/starboard/shared/stub/condition_variable_wait.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" SbConditionVariableResult SbConditionVariableWait( @@ -19,3 +21,4 @@ SbConditionVariableResult SbConditionVariableWait( SbMutex* mutex) { return kSbConditionVariableFailed; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/condition_variable_wait_timed.cc b/starboard/shared/stub/condition_variable_wait_timed.cc index dfc22d29771a..908759d0f98a 100644 --- a/starboard/shared/stub/condition_variable_wait_timed.cc +++ b/starboard/shared/stub/condition_variable_wait_timed.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" SbConditionVariableResult SbConditionVariableWaitTimed( @@ -20,3 +22,4 @@ SbConditionVariableResult SbConditionVariableWaitTimed( int64_t timeout) { return kSbConditionVariableFailed; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/mutex_acquire.cc b/starboard/shared/stub/mutex_acquire.cc index 423202e813a6..db64efd19d1c 100644 --- a/starboard/shared/stub/mutex_acquire.cc +++ b/starboard/shared/stub/mutex_acquire.cc @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" SbMutexResult SbMutexAcquire(SbMutex* mutex) { return kSbMutexDestroyed; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/mutex_acquire_try.cc b/starboard/shared/stub/mutex_acquire_try.cc index efc87b69d931..e59f2db4b581 100644 --- a/starboard/shared/stub/mutex_acquire_try.cc +++ b/starboard/shared/stub/mutex_acquire_try.cc @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" SbMutexResult SbMutexAcquireTry(SbMutex* mutex) { return kSbMutexDestroyed; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/mutex_create.cc b/starboard/shared/stub/mutex_create.cc index 4439ee071147..52876be4af47 100644 --- a/starboard/shared/stub/mutex_create.cc +++ b/starboard/shared/stub/mutex_create.cc @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" bool SbMutexCreate(SbMutex* mutex) { return false; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/mutex_destroy.cc b/starboard/shared/stub/mutex_destroy.cc index b88ae22767c5..e62414a53ec4 100644 --- a/starboard/shared/stub/mutex_destroy.cc +++ b/starboard/shared/stub/mutex_destroy.cc @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" bool SbMutexDestroy(SbMutex* mutex) { return false; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/mutex_release.cc b/starboard/shared/stub/mutex_release.cc index 207b6428d30e..21f81caf467a 100644 --- a/starboard/shared/stub/mutex_release.cc +++ b/starboard/shared/stub/mutex_release.cc @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" bool SbMutexRelease(SbMutex* mutex) { return false; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/thread_create.cc b/starboard/shared/stub/thread_create.cc index 7dc0360bf863..5b93031f9d75 100644 --- a/starboard/shared/stub/thread_create.cc +++ b/starboard/shared/stub/thread_create.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" SbThread SbThreadCreate(int64_t stack_size, @@ -23,3 +25,4 @@ SbThread SbThreadCreate(int64_t stack_size, void* context) { return kSbThreadInvalid; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/thread_detach.cc b/starboard/shared/stub/thread_detach.cc index b54ecd92f340..381a25025f0a 100644 --- a/starboard/shared/stub/thread_detach.cc +++ b/starboard/shared/stub/thread_detach.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 #include "starboard/thread.h" void SbThreadDetach(SbThread thread) {} +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/thread_get_current.cc b/starboard/shared/stub/thread_get_current.cc index 9e59c54fcfd3..d6b495c38b9d 100644 --- a/starboard/shared/stub/thread_get_current.cc +++ b/starboard/shared/stub/thread_get_current.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" SbThread SbThreadGetCurrent() { return kSbThreadInvalid; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/thread_is_equal.cc b/starboard/shared/stub/thread_is_equal.cc index fa8946921aa4..d1cf10aacd03 100644 --- a/starboard/shared/stub/thread_is_equal.cc +++ b/starboard/shared/stub/thread_is_equal.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" bool SbThreadIsEqual(SbThread thread1, SbThread thread2) { return false; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/thread_join.cc b/starboard/shared/stub/thread_join.cc index 54059eccf131..d19376e56d07 100644 --- a/starboard/shared/stub/thread_join.cc +++ b/starboard/shared/stub/thread_join.cc @@ -12,8 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" bool SbThreadJoin(SbThread thread, void** out_return) { return false; } +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/condition_variable_broadcast.cc b/starboard/shared/win32/condition_variable_broadcast.cc index 283887dd77aa..54afbd843ad7 100644 --- a/starboard/shared/win32/condition_variable_broadcast.cc +++ b/starboard/shared/win32/condition_variable_broadcast.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" #include @@ -25,3 +27,5 @@ bool SbConditionVariableBroadcast(SbConditionVariable* condition) { WakeAllConditionVariable(SB_WIN32_INTERNAL_CONDITION(condition)); return true; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/condition_variable_create.cc b/starboard/shared/win32/condition_variable_create.cc index 6bc8eaea3eef..8346a9cb1b41 100644 --- a/starboard/shared/win32/condition_variable_create.cc +++ b/starboard/shared/win32/condition_variable_create.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" #include @@ -29,3 +31,5 @@ bool SbConditionVariableCreate(SbConditionVariable* out_condition, InitializeConditionVariable(SB_WIN32_INTERNAL_CONDITION(out_condition)); return true; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/condition_variable_destroy.cc b/starboard/shared/win32/condition_variable_destroy.cc index f274855a39c3..a48c40fb4568 100644 --- a/starboard/shared/win32/condition_variable_destroy.cc +++ b/starboard/shared/win32/condition_variable_destroy.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" #include @@ -22,3 +24,5 @@ bool SbConditionVariableDestroy(SbConditionVariable* condition) { } return true; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/condition_variable_signal.cc b/starboard/shared/win32/condition_variable_signal.cc index 4653d6fa7103..ac38573e5232 100644 --- a/starboard/shared/win32/condition_variable_signal.cc +++ b/starboard/shared/win32/condition_variable_signal.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" #include @@ -25,3 +27,5 @@ bool SbConditionVariableSignal(SbConditionVariable* condition) { WakeConditionVariable(SB_WIN32_INTERNAL_CONDITION(condition)); return true; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/condition_variable_wait.cc b/starboard/shared/win32/condition_variable_wait.cc index d90dc89eda34..5360e7ec243c 100644 --- a/starboard/shared/win32/condition_variable_wait.cc +++ b/starboard/shared/win32/condition_variable_wait.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" #include @@ -30,3 +32,5 @@ SbConditionVariableResult SbConditionVariableWait( return result ? kSbConditionVariableSignaled : kSbConditionVariableFailed; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/condition_variable_wait_timed.cc b/starboard/shared/win32/condition_variable_wait_timed.cc index a2192ad1e6a4..2a448466affb 100644 --- a/starboard/shared/win32/condition_variable_wait_timed.cc +++ b/starboard/shared/win32/condition_variable_wait_timed.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/condition_variable.h" #include @@ -52,3 +54,5 @@ SbConditionVariableResult SbConditionVariableWaitTimed( } return kSbConditionVariableFailed; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/mutex_acquire.cc b/starboard/shared/win32/mutex_acquire.cc index 4e4238f48786..7c4bab841b86 100644 --- a/starboard/shared/win32/mutex_acquire.cc +++ b/starboard/shared/win32/mutex_acquire.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -25,3 +27,5 @@ SbMutexResult SbMutexAcquire(SbMutex* mutex) { AcquireSRWLockExclusive(SB_WIN32_INTERNAL_MUTEX(mutex)); return kSbMutexAcquired; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/mutex_acquire_try.cc b/starboard/shared/win32/mutex_acquire_try.cc index 391b6cfbdaf2..bc78ddaeab92 100644 --- a/starboard/shared/win32/mutex_acquire_try.cc +++ b/starboard/shared/win32/mutex_acquire_try.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -25,3 +27,5 @@ SbMutexResult SbMutexAcquireTry(SbMutex* mutex) { bool result = TryAcquireSRWLockExclusive(SB_WIN32_INTERNAL_MUTEX(mutex)); return result ? kSbMutexAcquired : kSbMutexBusy; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/mutex_create.cc b/starboard/shared/win32/mutex_create.cc index d8aead293ccc..de9039c22dae 100644 --- a/starboard/shared/win32/mutex_create.cc +++ b/starboard/shared/win32/mutex_create.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -28,3 +30,5 @@ bool SbMutexCreate(SbMutex* mutex) { InitializeSRWLock(SB_WIN32_INTERNAL_MUTEX(mutex)); return true; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/mutex_destroy.cc b/starboard/shared/win32/mutex_destroy.cc index bad468940c34..d8745b771993 100644 --- a/starboard/shared/win32/mutex_destroy.cc +++ b/starboard/shared/win32/mutex_destroy.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -35,3 +37,5 @@ bool SbMutexDestroy(SbMutex* mutex) { // https://devblogs.microsoft.com/oldnewthing/20160819-00/?p=94125 return true; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/mutex_release.cc b/starboard/shared/win32/mutex_release.cc index 72fbe311c406..a1d3839baea2 100644 --- a/starboard/shared/win32/mutex_release.cc +++ b/starboard/shared/win32/mutex_release.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/mutex.h" #include @@ -25,3 +27,5 @@ bool SbMutexRelease(SbMutex* mutex) { ReleaseSRWLockExclusive(SB_WIN32_INTERNAL_MUTEX(mutex)); return true; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/posix_emu/pthread.cc b/starboard/shared/win32/posix_emu/pthread.cc index c7d1d957c0ad..4c6391c3599d 100644 --- a/starboard/shared/win32/posix_emu/pthread.cc +++ b/starboard/shared/win32/posix_emu/pthread.cc @@ -208,15 +208,15 @@ static unsigned ThreadTrampoline(void* thread_create_info_context) { CallThreadLocalDestructorsMultipleTimes(); - SbMutexAcquire(&info->thread_private_.mutex_); + pthread_mutex_lock(&info->thread_private_.mutex_); info->thread_private_.result_ = result; info->thread_private_.result_is_valid_ = true; - SbConditionVariableSignal(&info->thread_private_.condition_); + pthread_cond_signal(&info->thread_private_.condition_); while (info->thread_private_.wait_for_join_) { - SbConditionVariableWait(&info->thread_private_.condition_, - &info->thread_private_.mutex_); + pthread_cond_wait(&info->thread_private_.condition_, + &info->thread_private_.mutex_); } - SbMutexRelease(&info->thread_private_.mutex_); + pthread_mutex_unlock(&info->thread_private_.mutex_); return 0; } @@ -268,22 +268,21 @@ int pthread_join(pthread_t thread, void** value_ptr) { SbThreadPrivate* thread_private = reinterpret_cast(thread); - SbMutexAcquire(&thread_private->mutex_); + pthread_mutex_lock(&thread_private->mutex_); if (!thread_private->wait_for_join_) { // Thread has already been detached. - SbMutexRelease(&thread_private->mutex_); + pthread_mutex_unlock(&thread_private->mutex_); return -1; } while (!thread_private->result_is_valid_) { - SbConditionVariableWait(&thread_private->condition_, - &thread_private->mutex_); + pthread_cond_wait(&thread_private->condition_, &thread_private->mutex_); } thread_private->wait_for_join_ = false; - SbConditionVariableSignal(&thread_private->condition_); + pthread_cond_signal(&thread_private->condition_); if (value_ptr != NULL) { *value_ptr = thread_private->result_; } - SbMutexRelease(&thread_private->mutex_); + pthread_mutex_unlock(&thread_private->mutex_); return 0; } @@ -293,10 +292,10 @@ int pthread_detach(pthread_t thread) { } SbThreadPrivate* thread_private = reinterpret_cast(thread); - SbMutexAcquire(&thread_private->mutex_); + pthread_mutex_lock(&thread_private->mutex_); thread_private->wait_for_join_ = false; - SbConditionVariableSignal(&thread_private->condition_); - SbMutexRelease(&thread_private->mutex_); + pthread_cond_signal(&thread_private->condition_); + pthread_mutex_unlock(&thread_private->mutex_); return 0; } @@ -325,9 +324,9 @@ int pthread_key_delete(pthread_key_t key) { DWORD tls_index = reinterpret_cast(key)->tls_index; ThreadSubsystemSingleton* singleton = GetThreadSubsystemSingleton(); - SbMutexAcquire(&singleton->mutex_); + pthread_mutex_lock(&singleton->mutex_); singleton->thread_local_keys_.erase(tls_index); - SbMutexRelease(&singleton->mutex_); + pthread_mutex_unlock(&singleton->mutex_); TlsInternalFree(tls_index); free(reinterpret_cast(key)); diff --git a/starboard/shared/win32/socket_waiter_internal.cc b/starboard/shared/win32/socket_waiter_internal.cc index a0a7da438cb2..f745689092f7 100644 --- a/starboard/shared/win32/socket_waiter_internal.cc +++ b/starboard/shared/win32/socket_waiter_internal.cc @@ -123,7 +123,7 @@ SbSocketWaiterInterest CombineInterests(SbSocketWaiterInterest a, } // namespace SbSocketWaiterPrivate::SbSocketWaiterPrivate() - : thread_(SbThreadGetCurrent()), + : thread_(pthread_self()), wakeup_event_token_(-1), wakeup_event_(CreateEvent(nullptr, false, false, nullptr)) { { @@ -152,7 +152,7 @@ bool SbSocketWaiterPrivate::Add(SbSocket socket, SbSocketWaiterCallback callback, int interests, bool persistent) { - SB_DCHECK(SbThreadIsCurrent(thread_)); + SB_DCHECK(pthread_equal(pthread_self(), thread_)); if (!SbSocketIsValid(socket)) { SB_DLOG(ERROR) << __FUNCTION__ << ": Socket (" << socket << ") is invalid."; @@ -235,7 +235,7 @@ bool SbSocketWaiterPrivate::Add(SbSocket socket, } bool SbSocketWaiterPrivate::Remove(SbSocket socket) { - SB_DCHECK(SbThreadIsCurrent(thread_)); + SB_DCHECK(pthread_equal(pthread_self(), thread_)); if (!CheckSocketWaiterIsThis(socket)) { return false; @@ -277,7 +277,7 @@ bool SbSocketWaiterPrivate::CheckSocketWaiterIsThis(SbSocket socket) { } void SbSocketWaiterPrivate::Wait() { - SB_DCHECK(SbThreadIsCurrent(thread_)); + SB_DCHECK(pthread_equal(pthread_self(), thread_)); // We basically wait for the largest amount of time to achieve an indefinite // block. @@ -285,7 +285,7 @@ void SbSocketWaiterPrivate::Wait() { } SbSocketWaiterResult SbSocketWaiterPrivate::WaitTimed(int64_t duration_usec) { - SB_DCHECK(SbThreadIsCurrent(thread_)); + SB_DCHECK(pthread_equal(pthread_self(), thread_)); const int64_t start_time = starboard::CurrentMonotonicTime(); int64_t duration_left = duration_usec; diff --git a/starboard/shared/win32/socket_waiter_internal.h b/starboard/shared/win32/socket_waiter_internal.h index 52d8eda1b1c5..28bd02e78b38 100644 --- a/starboard/shared/win32/socket_waiter_internal.h +++ b/starboard/shared/win32/socket_waiter_internal.h @@ -131,7 +131,7 @@ class SbSocketWaiterPrivate { // The thread this waiter was created on. Immutable, so accessible from any // thread. - const SbThread thread_; + const pthread_t thread_; // The registry of currently registered Waitees. WaiteeRegistry waitees_; diff --git a/starboard/shared/win32/thread_create.cc b/starboard/shared/win32/thread_create.cc index 8bff3ed983f4..058452247a80 100644 --- a/starboard/shared/win32/thread_create.cc +++ b/starboard/shared/win32/thread_create.cc @@ -92,7 +92,7 @@ void CallThreadLocalDestructorsMultipleTimes() { // TODO note that the implementation below holds a global lock // while processing TLS destructors on thread exit. This could // be a bottleneck in some scenarios. A lockless approach may be preferable. - SbMutexAcquire(&singleton->mutex_); + pthread_mutex_lock(&singleton->mutex_); for (int i = 0; i < kNumDestructorPasses; ++i) { // Run through each destructor and call it. @@ -102,7 +102,7 @@ void CallThreadLocalDestructorsMultipleTimes() { } } num_tls_objects_remaining = CountTlsObjectsRemaining(singleton); - SbMutexRelease(&singleton->mutex_); + pthread_mutex_unlock(&singleton->mutex_); SB_DCHECK(num_tls_objects_remaining == 0) << "Dangling objects in TLS exist."; } @@ -121,15 +121,15 @@ unsigned ThreadTrampoline(void* thread_create_info_context) { CallThreadLocalDestructorsMultipleTimes(); - SbMutexAcquire(&info->thread_private_.mutex_); + pthread_mutex_lock(&info->thread_private_.mutex_); info->thread_private_.result_ = result; info->thread_private_.result_is_valid_ = true; - SbConditionVariableSignal(&info->thread_private_.condition_); + pthread_cond_signal(&info->thread_private_.condition_); while (info->thread_private_.wait_for_join_) { - SbConditionVariableWait(&info->thread_private_.condition_, - &info->thread_private_.mutex_); + pthread_cond_wait(&info->thread_private_.condition_, + &info->thread_private_.mutex_); } - SbMutexRelease(&info->thread_private_.mutex_); + pthread_mutex_destroy(&info->thread_private_.mutex_); return 0; } @@ -174,6 +174,7 @@ SbThreadPriority Win32PriorityToSbThreadPriority(int priority) { } } // namespace +#if SB_API_VERSION < 16 // Note that SetThreadAffinityMask() is not available on some // platforms (eg UWP). If it's necessary for a non-UWP platform, // please fork this implementation for UWP. @@ -218,6 +219,7 @@ SbThread SbThreadCreate(int64_t stack_size, return &info->thread_private_; } +#endif // SB_API_VERSION < 16 bool SbThreadSetPriority(SbThreadPriority priority) { return SetThreadPriority(GetCurrentThread(), diff --git a/starboard/shared/win32/thread_create_local_key.cc b/starboard/shared/win32/thread_create_local_key.cc index 56dc12037e4d..1b1b771fb3cd 100644 --- a/starboard/shared/win32/thread_create_local_key.cc +++ b/starboard/shared/win32/thread_create_local_key.cc @@ -57,9 +57,9 @@ SbThreadLocalKey SbThreadCreateLocalKeyInternal( result->tls_index = index; result->destructor = destructor; - SbMutexAcquire(&singleton->mutex_); + pthread_mutex_lock(&singleton->mutex_); singleton->thread_local_keys_.insert(std::make_pair(index, result)); - SbMutexRelease(&singleton->mutex_); + pthread_mutex_unlock(&singleton->mutex_); return result; } diff --git a/starboard/shared/win32/thread_detach.cc b/starboard/shared/win32/thread_detach.cc index d16f52455458..1dfff6d24c50 100644 --- a/starboard/shared/win32/thread_detach.cc +++ b/starboard/shared/win32/thread_detach.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" #include "starboard/common/condition_variable.h" @@ -31,3 +33,5 @@ void SbThreadDetach(SbThread thread) { SbConditionVariableSignal(&thread_private->condition_); SbMutexRelease(&thread_private->mutex_); } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/thread_get_current.cc b/starboard/shared/win32/thread_get_current.cc index 0b8af37f14a1..b3dc47319993 100644 --- a/starboard/shared/win32/thread_get_current.cc +++ b/starboard/shared/win32/thread_get_current.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" #include "starboard/shared/win32/thread_private.h" @@ -22,3 +24,5 @@ using starboard::shared::win32::SbThreadPrivate; SbThread SbThreadGetCurrent() { return GetCurrentSbThreadPrivate(); } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/thread_is_equal.cc b/starboard/shared/win32/thread_is_equal.cc index e3afc0cbe81a..ae7ae9a7d2b1 100644 --- a/starboard/shared/win32/thread_is_equal.cc +++ b/starboard/shared/win32/thread_is_equal.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" bool SbThreadIsEqual(SbThread thread1, SbThread thread2) { return thread1 == thread2; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/thread_join.cc b/starboard/shared/win32/thread_join.cc index 7f2e7619720f..4fd30c911df4 100644 --- a/starboard/shared/win32/thread_join.cc +++ b/starboard/shared/win32/thread_join.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/thread.h" #include "starboard/common/condition_variable.h" @@ -45,3 +47,5 @@ bool SbThreadJoin(SbThread thread, void** out_return) { SbMutexRelease(&thread_private->mutex_); return true; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/thread_private.h b/starboard/shared/win32/thread_private.h index d5e62c4d0d5a..4f14d05e9825 100644 --- a/starboard/shared/win32/thread_private.h +++ b/starboard/shared/win32/thread_private.h @@ -28,6 +28,8 @@ #define kSbThreadLocalKeyInvalid (SbThreadLocalKey) NULL +typedef void (*SbThreadLocalDestructor)(void* value); + struct SbThreadLocalKeyPrivate { DWORD tls_index; SbThreadLocalDestructor destructor; @@ -60,10 +62,10 @@ SbThreadLocalKey SbThreadCreateLocalKeyInternal( class ThreadSubsystemSingleton { public: ThreadSubsystemSingleton() - : mutex_(SB_MUTEX_INITIALIZER), + : mutex_(PTHREAD_MUTEX_INITIALIZER), thread_private_key_(SbThreadCreateLocalKeyInternal(NULL, this)) {} // This mutex protects all class members - SbMutex mutex_; + pthread_mutex_t mutex_; // Allocated thread_local_keys. Note that std::map is used // so that elements can be deleted without triggering an allocation. std::map thread_local_keys_; @@ -82,8 +84,8 @@ void RegisterMainThread(); class SbThreadPrivate { public: SbThreadPrivate() - : mutex_(SB_MUTEX_INITIALIZER), - condition_(SB_CONDITION_VARIABLE_INITIALIZER), + : mutex_(PTHREAD_MUTEX_INITIALIZER), + condition_(PTHREAD_COND_INITIALIZER), handle_(NULL), result_(NULL), wait_for_join_(false), @@ -94,13 +96,13 @@ class SbThreadPrivate { CloseHandle(handle_); } - SbMutexDestroy(&mutex_); - SbConditionVariableDestroy(&condition_); + pthread_mutex_destroy(&mutex_); + pthread_cond_destroy(&condition_); } // This mutex protects all class members - SbMutex mutex_; - SbConditionVariable condition_; + pthread_mutex_t mutex_; + pthread_cond_t condition_; std::string name_; HANDLE handle_; // The result of the thread. The return value of SbThreadEntryPoint @@ -117,6 +119,8 @@ class SbThreadPrivate { // Obtains the current thread's SbThreadPrivate* from thread-local storage. SbThreadPrivate* GetCurrentSbThreadPrivate(); +typedef void* (*SbThreadEntryPoint)(void* context); + class ThreadCreateInfo { public: SbThreadPrivate thread_private_; diff --git a/starboard/thread.h b/starboard/thread.h index 94b1e502d24f..c7f3e9fc92ec 100644 --- a/starboard/thread.h +++ b/starboard/thread.h @@ -29,11 +29,6 @@ extern "C" { #endif -// An opaque handle to a thread type. -typedef void* SbThread; - -#define kSbThreadInvalid (SbThread) NULL - // A spectrum of thread priorities. Platforms map them appropriately to their // own priority system. Note that scheduling is platform-specific, and what // these priorities mean, if they mean anything at all, is also @@ -84,6 +79,36 @@ typedef enum SbThreadPriority { // An ID type that is unique per thread. typedef int32_t SbThreadId; +// Well-defined constant value to mean "no thread ID." +#define kSbThreadInvalidId (SbThreadId)0 + +// Returns whether the given thread ID is valid. +static inline bool SbThreadIsValidId(SbThreadId id) { + return id != kSbThreadInvalidId; +} + +// Returns whether the given thread priority is valid. +static inline bool SbThreadIsValidPriority(SbThreadPriority priority) { + return priority != kSbThreadNoPriority; +} + +// Returns the Thread ID of the currently executing thread. +SB_EXPORT SbThreadId SbThreadGetId(); + +#if SB_API_VERSION >= 16 +// Set the thread priority of the current thread. +SB_EXPORT bool SbThreadSetPriority(SbThreadPriority priority); + +// Get the thread priority of the current thread. +SB_EXPORT bool SbThreadGetPriority(SbThreadPriority* priority); +#endif + +#if SB_API_VERSION < 16 +// An opaque handle to a thread type. +typedef void* SbThread; + +#define kSbThreadInvalid (SbThread) NULL + // Function pointer type for SbThreadCreate. |context| is a pointer-sized bit // of data passed in from the calling thread. typedef void* (*SbThreadEntryPoint)(void* context); @@ -96,59 +121,32 @@ typedef void (*SbThreadLocalDestructor)(void* value); // may have specific rules about how it must be used. typedef int32_t SbThreadAffinity; -#if SB_API_VERSION < 16 // Private structure representing a thread-local key. typedef struct SbThreadLocalKeyPrivate SbThreadLocalKeyPrivate; // A handle to a thread-local key. typedef SbThreadLocalKeyPrivate* SbThreadLocalKey; -#endif - -// Well-defined constant value to mean "no thread ID." -#define kSbThreadInvalidId (SbThreadId)0 // Well-defined constant value to mean "no affinity." #define kSbThreadNoAffinity (SbThreadAffinity) kSbInvalidInt -#if SB_API_VERSION < 16 // Well-defined constant value to mean "no thread local key." #define kSbThreadLocalKeyInvalid (SbThreadLocalKey) NULL -#endif // Returns whether the given thread handle is valid. static inline bool SbThreadIsValid(SbThread thread) { return thread != kSbThreadInvalid; } -// Returns whether the given thread ID is valid. -static inline bool SbThreadIsValidId(SbThreadId id) { - return id != kSbThreadInvalidId; -} - -// Returns whether the given thread priority is valid. -static inline bool SbThreadIsValidPriority(SbThreadPriority priority) { - return priority != kSbThreadNoPriority; -} - // Returns whether the given thread affinity is valid. static inline bool SbThreadIsValidAffinity(SbThreadAffinity affinity) { return affinity != kSbThreadNoAffinity; } -#if SB_API_VERSION < 16 // Returns whether the given thread local variable key is valid. static inline bool SbThreadIsValidLocalKey(SbThreadLocalKey key) { return key != kSbThreadLocalKeyInvalid; } -#endif - -#if SB_API_VERSION >= 16 -// Set the thread priority of the current thread. -SB_EXPORT bool SbThreadSetPriority(SbThreadPriority priority); - -// Get the thread priority of the current thread. -SB_EXPORT bool SbThreadGetPriority(SbThreadPriority* priority); -#endif // Creates a new thread, which starts immediately. // - If the function succeeds, the return value is a handle to the newly @@ -206,7 +204,6 @@ SB_EXPORT bool SbThreadJoin(SbThread thread, void** out_return); // |thread|: The thread to be detached. SB_EXPORT void SbThreadDetach(SbThread thread); -#if SB_API_VERSION < 16 // Yields the currently executing thread, so another thread has a chance to run. SB_EXPORT void SbThreadYield(); @@ -216,21 +213,16 @@ SB_EXPORT void SbThreadYield(); // executing thread should sleep. The function is a no-op if this value is // negative or |0|. SB_EXPORT void SbThreadSleep(int64_t duration); -#endif // Returns the handle of the currently executing thread. SB_EXPORT SbThread SbThreadGetCurrent(); -// Returns the Thread ID of the currently executing thread. -SB_EXPORT SbThreadId SbThreadGetId(); - // Indicates whether |thread1| and |thread2| refer to the same thread. // // |thread1|: The first thread to compare. // |thread2|: The second thread to compare. SB_EXPORT bool SbThreadIsEqual(SbThread thread1, SbThread thread2); -#if SB_API_VERSION < 16 // Returns the debug name of the currently executing thread. SB_EXPORT void SbThreadGetName(char* buffer, int buffer_size); @@ -274,7 +266,6 @@ SB_EXPORT void* SbThreadGetLocalValue(SbThreadLocalKey key); // |key|: The key for which to set the key value. // |value|: The new pointer-sized key value. SB_EXPORT bool SbThreadSetLocalValue(SbThreadLocalKey key, void* value); -#endif // Returns whether |thread| is the current thread. // @@ -282,6 +273,7 @@ SB_EXPORT bool SbThreadSetLocalValue(SbThreadLocalKey key, void* value); static inline bool SbThreadIsCurrent(SbThread thread) { return SbThreadGetCurrent() == thread; } +#endif // Private structure representing the context of a frozen thread. typedef struct SbThreadContextPrivate SbThreadContextPrivate; diff --git a/starboard/tools/api_leak_detector/api_leak_detector.py b/starboard/tools/api_leak_detector/api_leak_detector.py index 8ad9affde4c6..15bcfe76960e 100755 --- a/starboard/tools/api_leak_detector/api_leak_detector.py +++ b/starboard/tools/api_leak_detector/api_leak_detector.py @@ -141,7 +141,7 @@ 'pthread_cond_signal', 'pthread_cond_timedwait', 'pthread_cond_wait', - 'pthread_condattr_destroy' + 'pthread_condattr_destroy', 'pthread_condattr_getclock', 'pthread_condattr_init', 'pthread_condattr_setclock', diff --git a/starboard/win/win32/test_filters.py b/starboard/win/win32/test_filters.py index ed9e7dbcd72c..5b733a7900e3 100644 --- a/starboard/win/win32/test_filters.py +++ b/starboard/win/win32/test_filters.py @@ -20,6 +20,10 @@ # pylint: disable=line-too-long _FILTERED_TESTS = { 'nplb': [ + # Currently frequently flaky on Windows + 'SbConditionVariableWaitTimedTest.FLAKY_SunnyDayAutoInit', + 'PosixConditionVariableWaitTimedTest.FLAKY_SunnyDayAutoInit', + # This single test takes >15 minutes. 'SbPlayerTest.MultiPlayer', # This test fails on win-win32 devel builds, because the compiler diff --git a/third_party/boringssl/src/crypto/thread_starboard.cc b/third_party/boringssl/src/crypto/thread_starboard.cc index 05017c00a1f3..413615d5d9f9 100644 --- a/third_party/boringssl/src/crypto/thread_starboard.cc +++ b/third_party/boringssl/src/crypto/thread_starboard.cc @@ -79,10 +79,10 @@ void EnsureInitialized(struct CRYPTO_STATIC_MUTEX* lock) { } // namespace void CRYPTO_MUTEX_init(CRYPTO_MUTEX* lock) { - if (!SbMutexCreate(&lock->mutex)) { + if (pthread_mutex_init(&lock->mutex, nullptr) != 0) { SbSystemBreakIntoDebugger(); } - if (!SbConditionVariableCreate(&lock->condition, &lock->mutex)) { + if (pthread_cond_init(&lock->condition, nullptr) != 0) { SbSystemBreakIntoDebugger(); } lock->readers = 0; @@ -91,74 +91,71 @@ void CRYPTO_MUTEX_init(CRYPTO_MUTEX* lock) { // https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock void CRYPTO_MUTEX_lock_read(CRYPTO_MUTEX* lock) { - if (SbMutexAcquire(&lock->mutex) != kSbMutexAcquired) { + if (pthread_mutex_lock(&lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } while (lock->writing) { - if (SbConditionVariableWait(&lock->condition, &lock->mutex) == - kSbConditionVariableFailed) { + if (pthread_cond_wait(&lock->condition, &lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } } ++(lock->readers); - if (!SbMutexRelease(&lock->mutex)) { + if (pthread_mutex_unlock(&lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } } // https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock void CRYPTO_MUTEX_lock_write(CRYPTO_MUTEX* lock) { - if (SbMutexAcquire(&lock->mutex) != kSbMutexAcquired) { + if (pthread_mutex_lock(&lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } while (lock->writing) { - if (SbConditionVariableWait(&lock->condition, &lock->mutex) == - kSbConditionVariableFailed) { + if (pthread_cond_wait(&lock->condition, &lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } } lock->writing = true; while (lock->readers > 0) { - if (SbConditionVariableWait(&lock->condition, &lock->mutex) == - kSbConditionVariableFailed) { + if (pthread_cond_wait(&lock->condition, &lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } } - if (!SbMutexRelease(&lock->mutex)) { + if (pthread_mutex_unlock(&lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } } // https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock void CRYPTO_MUTEX_unlock_read(CRYPTO_MUTEX* lock) { - if (SbMutexAcquire(&lock->mutex) != kSbMutexAcquired) { + if (pthread_mutex_lock(&lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } if (--(lock->readers) == 0) { - SbConditionVariableBroadcast(&lock->condition); + pthread_cond_broadcast(&lock->condition); } - if (!SbMutexRelease(&lock->mutex)) { + if (pthread_mutex_unlock(&lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } } // https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock void CRYPTO_MUTEX_unlock_write(CRYPTO_MUTEX* lock) { - if (SbMutexAcquire(&lock->mutex) != kSbMutexAcquired) { + if (pthread_mutex_lock(&lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } lock->writing = false; - SbConditionVariableBroadcast(&lock->condition); - if (!SbMutexRelease(&lock->mutex)) { + pthread_cond_broadcast(&lock->condition); + if (pthread_mutex_unlock(&lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } } void CRYPTO_MUTEX_cleanup(CRYPTO_MUTEX* lock) { - if (!SbConditionVariableDestroy(&lock->condition)) { + if (pthread_cond_destroy(&lock->condition) != 0) { SbSystemBreakIntoDebugger(); } - if (!SbMutexDestroy(&lock->mutex)) { + if (pthread_mutex_destroy(&lock->mutex) != 0) { SbSystemBreakIntoDebugger(); } } diff --git a/third_party/boringssl/src/include/openssl/thread.h b/third_party/boringssl/src/include/openssl/thread.h index a9f8a925522f..f954ce6337a0 100644 --- a/third_party/boringssl/src/include/openssl/thread.h +++ b/third_party/boringssl/src/include/openssl/thread.h @@ -80,8 +80,8 @@ typedef struct crypto_mutex_st { // a byte array that is sizeof(starboard::RWLock) without including the // declaration. Avoid the complication and just implement the RWMutex using // starboard C structs. - SbMutex mutex; - SbConditionVariable condition; + pthread_mutex_t mutex; + pthread_cond_t condition; size_t readers; bool writing; } CRYPTO_MUTEX; diff --git a/third_party/llvm-project/libcxx/include/__external_threading b/third_party/llvm-project/libcxx/include/__external_threading index eada137035b8..d614cecafaeb 100644 --- a/third_party/llvm-project/libcxx/include/__external_threading +++ b/third_party/llvm-project/libcxx/include/__external_threading @@ -8,8 +8,6 @@ #include #include "starboard/common/recursive_mutex.h" -#include "starboard/condition_variable.h" -#include "starboard/mutex.h" #include "starboard/thread.h" _LIBCPP_PUSH_MACROS @@ -27,12 +25,14 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -typedef SbMutex __libcpp_mutex_t; +typedef pthread_mutex_t __libcpp_mutex_t; + typedef starboard::RecursiveMutex __libcpp_recursive_mutex_t; -#define _LIBCPP_MUTEX_INITIALIZER SB_MUTEX_INITIALIZER +#define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER + +typedef pthread_cond_t __libcpp_condvar_t; -typedef SbConditionVariable __libcpp_condvar_t; -#define _LIBCPP_CONDVAR_INITIALIZER SB_CONDITION_VARIABLE_INITIALIZER +#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER typedef pthread_once_t __libcpp_exec_once_flag; #define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT @@ -161,57 +161,41 @@ int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t* __m) { // Similar situation to the constructor. int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t* __m) {} -int __libcpp_mutex_lock(__libcpp_mutex_t* __m) { return SbMutexAcquire(__m); } +int __libcpp_mutex_lock(__libcpp_mutex_t* __m) { + return pthread_mutex_lock(__m); +} bool __libcpp_mutex_trylock(__libcpp_mutex_t* __m) { - return (SbMutexAcquireTry(__m) == kSbMutexAcquired); + return pthread_mutex_trylock(__m) == 0; } int __libcpp_mutex_unlock(__libcpp_mutex_t* __m) { - if (SbMutexRelease(__m)) { - return 0; - } - return 1; + return pthread_mutex_unlock(__m); } int __libcpp_mutex_destroy(__libcpp_mutex_t* __m) { - if (SbMutexDestroy(__m)) { - return 0; - } - return 1; + return pthread_mutex_destroy(__m); } int __libcpp_condvar_signal(__libcpp_condvar_t* __cv) { - if (SbConditionVariableSignal(__cv)) { - return 0; - } - return 1; + return pthread_cond_signal(__cv); } int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv) { - if (SbConditionVariableBroadcast(__cv)) { - return 0; - } - return 1; + return pthread_cond_broadcast(__cv); } int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m) { - return SbConditionVariableWait(__cv, __m); + return pthread_cond_wait(__cv, __m); } int __libcpp_condvar_timedwait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m, timespec* __ts) { - // Convert the duration provided by __ts to a Starboard time. The conversion - // is from seconds (10^1) and nanoseconds (10^-9) to microseconds (10^-6). - const int64_t duration = __ts->tv_sec * 1000000 + __ts->tv_nsec / 1000; - return SbConditionVariableWaitTimed(__cv, __m, duration); + return pthread_cond_timedwait(__cv, __m, __ts); } int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv) { - if (SbConditionVariableDestroy(__cv)) { - return 0; - } - return 1; + return pthread_cond_destroy(__cv); } int __libcpp_execute_once(__libcpp_exec_once_flag* flag, diff --git a/third_party/musl/src/exit/atexit.c b/third_party/musl/src/exit/atexit.c index 4b50346f6462..2c0a03bea3f9 100644 --- a/third_party/musl/src/exit/atexit.c +++ b/third_party/musl/src/exit/atexit.c @@ -5,8 +5,8 @@ #include "fork_impl.h" #ifdef STARBOARD +#include #include "starboard/common/log.h" -#include "starboard/mutex.h" #include "starboard/types.h" #endif // STARBOARD @@ -26,14 +26,14 @@ static struct fl static int slot; #ifdef STARBOARD -static SbMutex lock = SB_MUTEX_INITIALIZER; +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; #define LOCK(x) \ do { \ - SB_DCHECK(SbMutexAcquire(&x) == kSbMutexAcquired); \ + SB_DCHECK(pthread_mutex_lock(&x) == 0); \ } while (0) #define UNLOCK(x) \ do { \ - SB_DCHECK(SbMutexRelease(&x)); \ + SB_DCHECK(pthread_mutex_unlock(&x) == 0); \ } while (0) #else // !STARBOARD static volatile int lock[1]; diff --git a/third_party/zlib/google/compression_utils_unittest.cc b/third_party/zlib/google/compression_utils_unittest.cc index 12a9ea8e7c54..4c415596d608 100644 --- a/third_party/zlib/google/compression_utils_unittest.cc +++ b/third_party/zlib/google/compression_utils_unittest.cc @@ -12,7 +12,6 @@ #include "base/logging.h" #include "base/stl_util.h" #include "starboard/common/log.h" -#include "starboard/common/time.h" #include "testing/gtest/include/gtest/gtest.h" namespace compression { @@ -102,22 +101,22 @@ TEST(CompressionUtilsTest, OutputCompressionAndDecompressionDuration) { for (size_t i = 0; i < kSize; ++i) data[i] = static_cast(i & 0xFF); - int64_t begin = starboard::CurrentPosixTime(); + int64_t begin = (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); std::string compressed_data; EXPECT_TRUE(GzipCompress(data, &compressed_data)); SB_LOG(INFO) << "GzipCompress() of 32MiB took " - << (starboard::CurrentPosixTime() - begin) / 1000 + << ((base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds() - begin) / 1000 << " milliseconds."; - begin = starboard::CurrentPosixTime(); + begin = (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); std::string uncompressed_data; EXPECT_TRUE(GzipUncompress(compressed_data, &uncompressed_data)); SB_LOG(INFO) << "GzipUncompress() of 32MiB took " - << (starboard::CurrentPosixTime() - begin) / 1000 + << ((base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds() - begin) / 1000 << " milliseconds."; } #endif diff --git a/tools/metrics/histograms/metadata/cobalt/enums.xml b/tools/metrics/histograms/metadata/cobalt/enums.xml index c593a7a6f734..2bad87c9eadc 100644 --- a/tools/metrics/histograms/metadata/cobalt/enums.xml +++ b/tools/metrics/histograms/metadata/cobalt/enums.xml @@ -156,6 +156,24 @@ https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histogra + + + Possible status of slot selection by the Loader App + + + + + + + + + + + + + + + diff --git a/tools/metrics/histograms/metadata/cobalt/histograms.xml b/tools/metrics/histograms/metadata/cobalt/histograms.xml index 4fba1e4004e8..5dd70d0124f4 100644 --- a/tools/metrics/histograms/metadata/cobalt/histograms.xml +++ b/tools/metrics/histograms/metadata/cobalt/histograms.xml @@ -119,6 +119,15 @@ Always run the pretty print utility on this file after editing: + + + + yuying@google.com + cobalt-team@google.com + Status of slot selection by the Loader App. + + diff --git a/v8/src/base/platform/condition-variable.cc b/v8/src/base/platform/condition-variable.cc index 081261c33a42..31cfbc01ea28 100644 --- a/v8/src/base/platform/condition-variable.cc +++ b/v8/src/base/platform/condition-variable.cc @@ -9,6 +9,10 @@ #include "src/base/platform/time.h" +#if V8_OS_STARBOARD +#include "starboard/common/time.h" +#endif + namespace v8 { namespace base { @@ -162,31 +166,79 @@ bool ConditionVariable::WaitFor(Mutex* mutex, const TimeDelta& rel_time) { #elif V8_OS_STARBOARD ConditionVariable::ConditionVariable() { +#if SB_API_VERSION < 16 SbConditionVariableCreate(&native_handle_, nullptr); +#else +#if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) + pthread_condattr_t attribute; + pthread_condattr_init(&attribute); + pthread_condattr_setclock(&attribute, CLOCK_MONOTONIC); + + int result = pthread_cond_init(&native_handle_, &attribute); + DCHECK(result == 0); + + pthread_condattr_destroy(&attribute); +#else + int result = pthread_cond_init(&native_handle_, nullptr); + DCHECK(result == 0); +#endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) +#endif // SB_API_VERSION < 16 } ConditionVariable::~ConditionVariable() { +#if SB_API_VERSION < 16 SbConditionVariableDestroy(&native_handle_); +#else + pthread_cond_destroy(&native_handle_); +#endif // SB_API_VERSION < 16 } void ConditionVariable::NotifyOne() { +#if SB_API_VERSION < 16 SbConditionVariableSignal(&native_handle_); +#else + pthread_cond_signal(&native_handle_); +#endif // SB_API_VERSION < 16 } void ConditionVariable::NotifyAll() { +#if SB_API_VERSION < 16 SbConditionVariableBroadcast(&native_handle_); +#else + pthread_cond_broadcast(&native_handle_); +#endif // SB_API_VERSION < 16 } void ConditionVariable::Wait(Mutex* mutex) { +#if SB_API_VERSION < 16 SbConditionVariableWait(&native_handle_, &mutex->native_handle()); +#else + pthread_cond_wait(&native_handle_, &mutex->native_handle()); +#endif // SB_API_VERSION < 16 } bool ConditionVariable::WaitFor(Mutex* mutex, const TimeDelta& rel_time) { +#if SB_API_VERSION < 16 int64_t microseconds = static_cast(rel_time.InMicroseconds()); SbConditionVariableResult result = SbConditionVariableWaitTimed( &native_handle_, &mutex->native_handle(), microseconds); DCHECK(result != kSbConditionVariableFailed); return result == kSbConditionVariableSignaled; +#else +#if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) + int64_t timeout_time_usec = starboard::CurrentMonotonicTime(); +#else + int64_t timeout_time_usec = starboard::CurrentPosixTime(); +#endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) + timeout_time_usec += static_cast(rel_time.InMicroseconds()); + + struct timespec delay_timestamp; + delay_timestamp.tv_sec = timeout_time_usec / 1000'000; + delay_timestamp.tv_nsec = (timeout_time_usec % 1000'000) * 1000; + + int result = pthread_cond_timedwait(&native_handle_, &mutex->native_handle(), &delay_timestamp); + return result == 0; +#endif // SB_API_VERSION < 16 } #endif // V8_OS_STARBOARD diff --git a/v8/src/base/platform/condition-variable.h b/v8/src/base/platform/condition-variable.h index 79e653a32aa1..a986fd68d22f 100644 --- a/v8/src/base/platform/condition-variable.h +++ b/v8/src/base/platform/condition-variable.h @@ -10,7 +10,11 @@ #include "src/base/platform/mutex.h" #if V8_OS_STARBOARD +#if SB_API_VERSION < 16 #include "starboard/common/condition_variable.h" +#else +#include +#endif // SB_API_VERSION < 16 #endif namespace v8 { @@ -71,7 +75,11 @@ class V8_BASE_EXPORT ConditionVariable final { #elif V8_OS_WIN using NativeHandle = CONDITION_VARIABLE; #elif V8_OS_STARBOARD +#if SB_API_VERSION < 16 using NativeHandle = SbConditionVariable; +#else + using NativeHandle = pthread_cond_t; +#endif // SB_API_VERSION < 16 #endif NativeHandle& native_handle() { diff --git a/v8/src/base/platform/mutex.cc b/v8/src/base/platform/mutex.cc index 40702f493ea4..30af6efe4368 100644 --- a/v8/src/base/platform/mutex.cc +++ b/v8/src/base/platform/mutex.cc @@ -296,13 +296,37 @@ bool SharedMutex::TryLockExclusive() { #elif V8_OS_STARBOARD -Mutex::Mutex() { SbMutexCreate(&native_handle_); } +Mutex::Mutex() { +#if SB_API_VERSION < 16 + SbMutexCreate(&native_handle_); +#else + pthread_mutex_init(&native_handle_, nullptr); +#endif +} -Mutex::~Mutex() { SbMutexDestroy(&native_handle_); } +Mutex::~Mutex() { +#if SB_API_VERSION < 16 + SbMutexDestroy(&native_handle_); +#else + pthread_mutex_destroy(&native_handle_); +#endif +} -void Mutex::Lock() { SbMutexAcquire(&native_handle_); } +void Mutex::Lock() { +#if SB_API_VERSION < 16 + SbMutexAcquire(&native_handle_); +#else + pthread_mutex_lock(&native_handle_); +#endif +} -void Mutex::Unlock() { SbMutexRelease(&native_handle_); } +void Mutex::Unlock() { +#if SB_API_VERSION < 16 + SbMutexRelease(&native_handle_); +#else + pthread_mutex_unlock(&native_handle_); +#endif +} RecursiveMutex::RecursiveMutex() {} diff --git a/v8/src/base/platform/mutex.h b/v8/src/base/platform/mutex.h index 1b950c61ad7c..1a5d8e9d1809 100644 --- a/v8/src/base/platform/mutex.h +++ b/v8/src/base/platform/mutex.h @@ -12,7 +12,7 @@ #endif #include "src/base/logging.h" -#if V8_OS_POSIX +#if V8_OS_POSIX || V8_OS_STARBOARD #include // NOLINT #endif @@ -67,7 +67,11 @@ class V8_BASE_EXPORT Mutex final { #elif V8_OS_WIN using NativeHandle = SRWLOCK; #elif V8_OS_STARBOARD +#if SB_API_VERSION < 16 using NativeHandle = SbMutex; +#else + using NativeHandle = pthread_mutex_t; +#endif // SB_API_VERSION < 16 #endif NativeHandle& native_handle() { diff --git a/v8/src/heap/scavenger.cc b/v8/src/heap/scavenger.cc index ea4cb904590b..a9fb11da9ad8 100644 --- a/v8/src/heap/scavenger.cc +++ b/v8/src/heap/scavenger.cc @@ -569,7 +569,7 @@ void Scavenger::AddPageToSweeperIfNecessary(MemoryChunk* page) { void Scavenger::ScavengePage(MemoryChunk* page) { CodePageMemoryModificationScope memory_modification_scope(page); - if (page->slot_set() != nullptr) { + if (page->slot_set() != nullptr) { InvalidatedSlotsFilter filter = InvalidatedSlotsFilter::OldToNew(page); RememberedSet::IterateAndTrackEmptyBuckets( page,