@@ -610,7 +610,7 @@ class GlobalHeap : public MeshableArena<PageSize> {
610610 }
611611
612612 void setMeshPeriodMs (std::chrono::milliseconds period) {
613- _meshPeriodMs = period;
613+ _meshPeriodMs. store ( period, std::memory_order_release) ;
614614 }
615615
616616 void lock () {
@@ -644,14 +644,16 @@ class GlobalHeap : public MeshableArena<PageSize> {
644644 return ;
645645 }
646646
647- if (_meshPeriodMs == kZeroMs ) {
647+ const auto meshPeriodMs = _meshPeriodMs.load (std::memory_order_acquire);
648+ if (meshPeriodMs == kZeroMs ) {
648649 return ;
649650 }
650651
651652 const auto now = time::now ();
652- auto duration = chrono::duration_cast<chrono::milliseconds>(now - _lastMesh);
653+ const auto lastMesh = _lastMesh.load (std::memory_order_acquire);
654+ auto duration = chrono::duration_cast<chrono::milliseconds>(now - lastMesh);
653655
654- if (likely (duration < _meshPeriodMs )) {
656+ if (likely (duration < meshPeriodMs )) {
655657 return ;
656658 }
657659
@@ -662,14 +664,15 @@ class GlobalHeap : public MeshableArena<PageSize> {
662664 // time, the second one bows out gracefully without meshing
663665 // twice in a row.
664666 const auto lockedNow = time::now ();
665- auto duration = chrono::duration_cast<chrono::milliseconds>(lockedNow - _lastMesh);
667+ const auto lockedLastMesh = _lastMesh.load (std::memory_order_relaxed);
668+ auto duration = chrono::duration_cast<chrono::milliseconds>(lockedNow - lockedLastMesh);
666669
667- if (unlikely (duration < _meshPeriodMs )) {
670+ if (unlikely (duration < meshPeriodMs )) {
668671 return ;
669672 }
670673 }
671674
672- _lastMesh = now;
675+ _lastMesh. store ( now, std::memory_order_release) ;
673676
674677 meshAllSizeClassesLocked ();
675678 }
@@ -720,7 +723,7 @@ class GlobalHeap : public MeshableArena<PageSize> {
720723
721724 const size_t _maxObjectSize;
722725 atomic_size_t _meshPeriod{kDefaultMeshPeriod };
723- std::chrono::milliseconds _meshPeriodMs{kMeshPeriodMs };
726+ std::atomic<std:: chrono::milliseconds> _meshPeriodMs{kMeshPeriodMs };
724727
725728 atomic_size_t ATTRIBUTE_ALIGNED (CACHELINE_SIZE) _lastMeshEffective{0 };
726729
@@ -756,7 +759,7 @@ class GlobalHeap : public MeshableArena<PageSize> {
756759 GlobalHeapStats _stats{};
757760
758761 // XXX: should be atomic, but has exception spec?
759- time::time_point _lastMesh;
762+ std::atomic< time::time_point> _lastMesh;
760763};
761764
762765static_assert (kNumBins == 25 , " if this changes, add more 'Head's above" );
0 commit comments