Repository navigation
Expand file tree
/
Copy pathCaches.cpp
More file actions
64 lines (50 loc) · 1.8 KB
/
Copy pathCaches.cpp
File metadata and controls
64 lines (50 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "Caches.h"
#include <atomic>
#include "Constants.h"
#include "NativeScriptException.h"
using namespace v8;
namespace tns {
Caches::Caches(Isolate* isolate, const int& isolateId)
: PromiseRejections(std::make_unique<PromiseRejectionTracker>(isolate)),
isolate_(isolate),
isolateId_(isolateId),
gateId_(isolateId) {}
Caches::~Caches() {
// Subsystem state may hold v8 handles and reference the core caches below;
// destroy it first, while both are still intact.
this->stateSlots_.clear();
this->Prototypes.clear();
this->ClassPrototypes.clear();
this->CtorFuncTemplates.clear();
this->CtorFuncs.clear();
this->ProtocolCtorFuncs.clear();
this->PrimitiveInteropTypes.clear();
this->CFunctions.clear();
this->Instances.clear();
this->PointerInstances.clear();
this->cacheBoundObjects_.clear();
}
size_t Caches::NextStateSlotIndex() {
static std::atomic<size_t> nextIndex{0};
return nextIndex.fetch_add(1, std::memory_order_relaxed);
}
void Caches::Remove(v8::Isolate* isolate) {
auto cache = isolate->GetData(Constants::CACHES_ISOLATE_SLOT);
isolate->SetData(Constants::CACHES_ISOLATE_SLOT, nullptr);
if (cache != nullptr) {
delete reinterpret_cast<std::shared_ptr<Caches>*>(cache);
}
}
void Caches::SetContext(Local<Context> context) {
this->context_ =
std::make_shared<Persistent<Context>>(this->isolate_, context);
}
Local<Context> Caches::GetContext() {
return this->context_->Get(this->isolate_);
}
std::shared_ptr<ConcurrentMap<std::string, const Meta*>> Caches::Metadata =
std::make_shared<ConcurrentMap<std::string, const Meta*>>();
std::shared_ptr<ConcurrentMap<int, std::shared_ptr<Caches::WorkerState>>>
Caches::Workers = std::make_shared<
ConcurrentMap<int, std::shared_ptr<Caches::WorkerState>>>();
} // namespace tns