Bug 131630 - monotonicallyIncreasingTime() should only initialize its static timebaseInfo once
Summary: monotonicallyIncreasingTime() should only initialize its static timebaseInfo ...
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
Keywords: InRadar
Depends on:
Reported: 2014-04-14 12:51 PDT by Mark Lam
Modified: 2014-04-14 13:33 PDT (History)
10 users (show)

See Also:

the patch (1.58 KB, patch)
2014-04-14 13:02 PDT, Mark Lam
fpizlo: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Lam 2014-04-14 12:51:58 PDT
The current initialization of the static field is not thread safe.
Comment 1 Mark Lam 2014-04-14 12:52:54 PDT
Comment 2 Mark Lam 2014-04-14 13:02:53 PDT
Created attachment 229302 [details]
the patch
Comment 3 Filip Pizlo 2014-04-14 13:20:28 PDT
Comment on attachment 229302 [details]
the patch

View in context: https://bugs.webkit.org/attachment.cgi?id=229302&action=review

> Source/WTF/wtf/CurrentTime.cpp:278
>      // Based on listing #2 from Apple QA 1398.
>      static mach_timebase_info_data_t timebaseInfo;
> -    if (!timebaseInfo.denom) {
> +    static std::once_flag initializeTimerOnceFlag;
> +    std::call_once(initializeTimerOnceFlag, [] {

You should change the comment to say that it fixes the race condition in that listing.  Say something like "Based on listing #2 from Apple QA 1398, but modified to be thread-safe".
Comment 4 Mark Lam 2014-04-14 13:33:06 PDT
Thanks.  Patch has been updated as suggested.  Landed in r167263: <http://trac.webkit.org/r167263>.