@@ -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
@@ -1007,28 +1006,13 @@ v8::CpuProfiler* WallProfiler::CreateV8CpuProfiler() {
1007
1006
}
1008
1007
1009
1008
v8::Local<v8::Value> WallProfiler::GetContext (Isolate* isolate) {
1010
- auto context = * curContext_.load (std::memory_order_relaxed );
1009
+ auto context = curContext_.Get ( );
1011
1010
if (!context) return v8::Undefined (isolate);
1012
1011
return context->Get (isolate);
1013
1012
}
1014
1013
1015
1014
void WallProfiler::SetContext (Isolate* isolate, Local<Value> value) {
1016
- // Need to be careful here, because we might be interrupted by a
1017
- // signal handler that will make use of curContext_.
1018
- // Update of shared_ptr is not atomic, so instead we use a pointer
1019
- // (curContext_) that points on two shared_ptr (context1_ and context2_),
1020
- // update the shared_ptr that is not currently in use and then atomically
1021
- // update curContext_.
1022
- auto newCurContext = curContext_.load (std::memory_order_relaxed) == &context1_
1023
- ? &context2_
1024
- : &context1_;
1025
- if (!value->IsNullOrUndefined ()) {
1026
- *newCurContext = std::make_shared<Global<Value>>(isolate, value);
1027
- } else {
1028
- newCurContext->reset ();
1029
- }
1030
- std::atomic_signal_fence (std::memory_order_release);
1031
- curContext_.store (newCurContext, std::memory_order_relaxed);
1015
+ curContext_.Set (isolate, value);
1032
1016
}
1033
1017
1034
1018
NAN_GETTER (WallProfiler::GetContext) {
@@ -1109,10 +1093,10 @@ void WallProfiler::PushContext(int64_t time_from,
1109
1093
// Be careful this is called in a signal handler context therefore all
1110
1094
// operations must be async signal safe (in particular no allocations).
1111
1095
// Our ring buffer avoids allocations.
1112
- auto context = curContext_.load (std::memory_order_relaxed );
1096
+ auto context = curContext_.Get ( );
1113
1097
std::atomic_signal_fence (std::memory_order_acquire);
1114
1098
if (contexts_.size () < contexts_.capacity ()) {
1115
- contexts_.push_back ({* context, time_from, time_to, cpu_time, async_id});
1099
+ contexts_.push_back ({context, time_from, time_to, cpu_time, async_id});
1116
1100
std::atomic_fetch_add_explicit (
1117
1101
reinterpret_cast <std::atomic<uint32_t >*>(&fields_[kSampleCount ]),
1118
1102
1U ,
0 commit comments