Skip to content

Commit cdd0756

Browse files
committed
Move PersistentContextPtr to top
1 parent ce58813 commit cdd0756

File tree

1 file changed

+48
-50
lines changed

1 file changed

+48
-50
lines changed

bindings/profilers/wall.cc

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,54 @@ class SignalMutex {
7272
inline ~SignalMutex() { store(false); }
7373
};
7474

75+
void SetContextPtr(ContextPtr& contextPtr,
76+
Isolate* isolate,
77+
Local<Value> value) {
78+
if (!value->IsNullOrUndefined()) {
79+
contextPtr = std::make_shared<Global<Value>>(isolate, value);
80+
} else {
81+
contextPtr.reset();
82+
}
83+
}
84+
85+
class PersistentContextPtr {
86+
ContextPtr context;
87+
std::vector<PersistentContextPtr*>* dead;
88+
Persistent<Object> per;
89+
90+
PersistentContextPtr(std::vector<PersistentContextPtr*>* dead) : dead(dead) {}
91+
92+
void UnregisterFromGC() {
93+
if (!per.IsEmpty()) {
94+
per.ClearWeak();
95+
per.Reset();
96+
}
97+
}
98+
99+
void MarkDead() { dead->push_back(this); }
100+
101+
void RegisterForGC(Isolate* isolate, const Local<Object>& obj) {
102+
// Register a callback to delete this object when the object is GCed
103+
per.Reset(isolate, obj);
104+
per.SetWeak(
105+
this,
106+
[](const WeakCallbackInfo<PersistentContextPtr>& data) {
107+
auto ptr = data.GetParameter();
108+
ptr->MarkDead();
109+
ptr->UnregisterFromGC();
110+
},
111+
WeakCallbackType::kParameter);
112+
}
113+
114+
void Set(Isolate* isolate, const Local<Value>& value) {
115+
SetContextPtr(context, isolate, value);
116+
}
117+
118+
ContextPtr Get() const { return context; }
119+
120+
friend class WallProfiler;
121+
};
122+
75123
// Maximum number of rounds in the GetV8ToEpochOffset
76124
static constexpr int MAX_EPOCH_OFFSET_ATTEMPTS = 20;
77125

@@ -634,56 +682,6 @@ void WallProfiler::Dispose(Isolate* isolate, bool removeFromMap) {
634682
}
635683
}
636684

637-
void SetContextPtr(ContextPtr& contextPtr,
638-
Isolate* isolate,
639-
Local<Value> value) {
640-
if (contextPtr) {
641-
contextPtr = std::make_shared<Global<Value>>(isolate, value);
642-
} else {
643-
contextPtr.reset();
644-
}
645-
}
646-
647-
class PersistentContextPtr {
648-
ContextPtr context;
649-
std::vector<PersistentContextPtr*>* dead;
650-
Persistent<Object> per;
651-
652-
PersistentContextPtr(std::vector<PersistentContextPtr*>* dead) : dead(dead) {}
653-
654-
void UnregisterFromGC() {
655-
if (!per.IsEmpty()) {
656-
per.ClearWeak();
657-
per.Reset();
658-
}
659-
}
660-
661-
void MarkDead() { dead->push_back(this); }
662-
663-
void RegisterForGC(Isolate* isolate, const Local<Object>& obj) {
664-
// Register a callback to delete this object when the object is GCed
665-
per.Reset(isolate, obj);
666-
per.SetWeak(
667-
this,
668-
[](const WeakCallbackInfo<PersistentContextPtr>& data) {
669-
auto ptr = data.GetParameter();
670-
ptr->MarkDead();
671-
ptr->UnregisterFromGC();
672-
},
673-
WeakCallbackType::kParameter);
674-
}
675-
676-
void Set(Isolate* isolate, const Local<Value>& value) {
677-
SetContextPtr(context, isolate, value);
678-
}
679-
680-
ContextPtr Get() const {
681-
return context;
682-
}
683-
684-
friend class WallProfiler;
685-
};
686-
687685
#define DD_WALL_PROFILER_GET_BOOLEAN_CONFIG(name) \
688686
auto name##Value = \
689687
Nan::Get(arg, Nan::New<v8::String>(#name).ToLocalChecked()); \

0 commit comments

Comments
 (0)