Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libobs/util: Fix tv_nsec becoming 1000000000 in os_event_timedwait #11495

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

norihiro
Copy link
Contributor

@norihiro norihiro commented Nov 6, 2024

Description

Fix the carry condition of tv_nsec in the static function add_ms_to_ts, which add specified time in millisecond to an absolute time in struct timespec.

Motivation and Context

The static function add_ms_to_ts calculate the absolute time that will passed to pthread_cond_timedwait in the function os_event_timedwait.

When tv_nsec is 1000000000, some implementation of pthread_cond_timedwait, such as glibc on Linux, immediately return with an error code EINVAL.

How Has This Been Tested?

OS: Fedora 39

Tested with a modification as below to accelerate the failure condition.

 static inline void add_ms_to_ts(struct timespec *ts, unsigned long milliseconds)
 {
         ts->tv_sec += milliseconds / 1000;
         ts->tv_nsec += (milliseconds % 1000) * 1000000;
+
+        if (ts->tv_nsec > 999000000) {
+                blog(LOG_INFO, "setting tv_nsec = 1000000000");
+                ts->tv_nsec = 1000000000;
+        }
+
         if (ts->tv_nsec > 1000000000) {
                 ts->tv_sec += 1;
                 ts->tv_nsec -= 1000000000;
         }
 }

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@norihiro norihiro changed the title libobs/util: Fix tv_nsec becoming 1000000000 in os_event_timedwait libobs/util: Fix overflow of tv_nsec in os_event_timedwait Nov 6, 2024
@norihiro norihiro changed the title libobs/util: Fix overflow of tv_nsec in os_event_timedwait libobs/util: Fix tv_nsec becoming 1000000000 in os_event_timedwait Nov 6, 2024
@RytoEX RytoEX requested a review from Lain-B November 7, 2024 21:19
@RytoEX RytoEX added the Bug Fix Non-breaking change which fixes an issue label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants