Skip to content

Commit c7e61ba

Browse files
adjust frequency caching
1 parent 734a4f3 commit c7e61ba

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

libc/src/__support/time/windows/clock_gettime.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ namespace LIBC_NAMESPACE_DECL {
2323
namespace internal {
2424
static long long get_ticks_per_second() {
2525
static cpp::Atomic<long long> frequency = 0;
26-
if (!frequency) {
26+
auto freq = frequency.load(cpp::MemoryOrder::RELAXED);
27+
if (!freq) {
2728
UNINITIALIZED LARGE_INTEGER buffer;
2829
// On systems that run Windows XP or later, the function will always
2930
// succeed and will thus never return zero.
3031
::QueryPerformanceFrequency(&buffer);
31-
frequency = buffer.QuadPart;
32+
frequency.store(buffer.QuadPart, cpp::MemoryOrder::RELAXED);
3233
return buffer.QuadPart;
3334
}
34-
return frequency.load(cpp::MemoryOrder::RELAXED);
35+
return freq;
3536
}
3637

3738
ErrorOr<int> clock_gettime(clockid_t clockid, timespec *ts) {

0 commit comments

Comments
 (0)