@@ -560,7 +560,6 @@ WallProfiler::WallProfiler(std::chrono::microseconds samplingPeriod,
560
560
contexts_.reserve (duration * 2 / samplingPeriod);
561
561
}
562
562
563
- curContext_.store (&context1_, std::memory_order_relaxed);
564
563
collectionMode_.store (CollectionMode::kNoCollect , std::memory_order_relaxed);
565
564
gcCount.store (0 , std::memory_order_relaxed);
566
565
@@ -1006,28 +1005,13 @@ v8::CpuProfiler* WallProfiler::CreateV8CpuProfiler() {
1006
1005
}
1007
1006
1008
1007
v8::Local<v8::Value> WallProfiler::GetContext (Isolate* isolate) {
1009
- auto context = * curContext_.load (std::memory_order_relaxed );
1008
+ auto context = curContext_.Get ( );
1010
1009
if (!context) return v8::Undefined (isolate);
1011
1010
return context->Get (isolate);
1012
1011
}
1013
1012
1014
1013
void WallProfiler::SetContext (Isolate* isolate, Local<Value> value) {
1015
- // Need to be careful here, because we might be interrupted by a
1016
- // signal handler that will make use of curContext_.
1017
- // Update of shared_ptr is not atomic, so instead we use a pointer
1018
- // (curContext_) that points on two shared_ptr (context1_ and context2_),
1019
- // update the shared_ptr that is not currently in use and then atomically
1020
- // update curContext_.
1021
- auto newCurContext = curContext_.load (std::memory_order_relaxed) == &context1_
1022
- ? &context2_
1023
- : &context1_;
1024
- if (!value->IsNullOrUndefined ()) {
1025
- *newCurContext = std::make_shared<Global<Value>>(isolate, value);
1026
- } else {
1027
- newCurContext->reset ();
1028
- }
1029
- std::atomic_signal_fence (std::memory_order_release);
1030
- curContext_.store (newCurContext, std::memory_order_relaxed);
1014
+ curContext_.Set (isolate, value);
1031
1015
}
1032
1016
1033
1017
NAN_GETTER (WallProfiler::GetContext) {
@@ -1102,10 +1086,10 @@ void WallProfiler::PushContext(int64_t time_from,
1102
1086
// Be careful this is called in a signal handler context therefore all
1103
1087
// operations must be async signal safe (in particular no allocations).
1104
1088
// Our ring buffer avoids allocations.
1105
- auto context = curContext_.load (std::memory_order_relaxed );
1089
+ auto context = curContext_.Get ( );
1106
1090
std::atomic_signal_fence (std::memory_order_acquire);
1107
1091
if (contexts_.size () < contexts_.capacity ()) {
1108
- contexts_.push_back ({* context, time_from, time_to, cpu_time, async_id});
1092
+ contexts_.push_back ({context, time_from, time_to, cpu_time, async_id});
1109
1093
std::atomic_fetch_add_explicit (
1110
1094
reinterpret_cast <std::atomic<uint32_t >*>(&fields_[kSampleCount ]),
1111
1095
1U ,
0 commit comments