Skip to content

[libcxx] std::chrono::steady_clock is not working as expected #767

@antonic901

Description

@antonic901

While working on my Kodi port I faced lot of issues with:

  • frame time (CTimeUtils::GetFrameTime)
  • stopwatch (CStopwatch)
  • events (CEvent)

I inspected this and everything leads to use of std::chrono::steady_clock::now(). This is used by std::condition_variable_any::wait_for (used in CEvent), it's used inside CStopwatch to calculate elapsed time and it's used to update frame time inside CTimeUtils. When app is started it behaves normally but after some time it starts behaving unpredictably giving negative and zero values which leads to crashes in case of std::condition_variable_any and brokes complete logic in Kodi because returned value of this functions should be always greater then previous one (somerhing like GetTickCount).

Astarivi helped me to debug this and we came to conslusion that problem is inside kernel functin KeQueryPerformanceFrequency which is invoked when std::chrono::steady_clock::now() is called. This is actually a know problem for Win 2K and older systems. In short, KeQueryPerformanceFrequency on Xbox can fail and LLVM assumes this will always succeed. See here. There are also more details on MS docs

Temporary solution for this is to replace steady_clock with system_clock but this should be fixed anyway. Or at least until this is sorted steady_clock should be disabled so it doesnt lead to confusion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions