FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/src/context.cc at node-api · Chen-Software/nodegit · GitHub
Chen-Software
nodegit
Repository navigation
Code
Pull requests
23
(23)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
src
/
context.cc
Copy path
More file actions
More file actions
Latest commit
History
History
History
82 lines (67 loc) · 2.5 KB
Breadcrumbs
nodegit
/
src
/
context.cc
Copy path
File metadata and controls
82 lines (67 loc) · 2.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
include
"
../include/context.h
"
namespace
nodegit
{
thread_local
Context *Context::currentContext =
nullptr
;
AsyncContextCleanupHandle::AsyncContextCleanupHandle
(Napi::Env env, Context *context)
: context(context)
{
//
napi_add_env_cleanup_hook is N-API, unlike node::AddEnvironmentCleanupHook.
napi_add_env_cleanup_hook
(env, AsyncCleanupContext,
this
);
}
AsyncContextCleanupHandle::~AsyncContextCleanupHandle
() {
delete
context;
}
void
AsyncContextCleanupHandle::AsyncCleanupContext
(
void
*data) {
std::unique_ptr<AsyncContextCleanupHandle>
cleanupHandle
(
static_cast
<AsyncContextCleanupHandle *>(data));
Napi::Env env = cleanupHandle->
context
->
Env
();
Napi::HandleScope
scope
(env);
//
N-API's cleanup hook cannot be deferred, so ShutdownThreadPool has to
//
complete - including joining every worker thread - before we return.
//
The handle released at the end of this scope owns the Context, so the
//
thread pool is destroyed only after it is done shutting itself down.
cleanupHandle->
context
->
ShutdownThreadPool
();
cleanupHandle.
reset
();
}
Context::Context
(Napi::Env env)
: env(env),
threadPool
(
10
,
this
)
{
Napi::Object storage =
Napi::Object::New
(env);
persistentStorage =
Napi::Persistent
(storage);
currentContext =
this
;
new
AsyncContextCleanupHandle
(env,
this
);
}
Context::~Context
() {
nodegit::TrackerWrap::DeleteFromList
(&trackerList);
if
(currentContext ==
this
) {
currentContext =
nullptr
;
}
}
std::shared_ptr<CleanupHandle>
Context::GetCleanupHandle
(std::string key) {
return
cleanupHandles[key];
}
Context *
Context::GetCurrentContext
() {
return
currentContext;
}
Napi::Value
Context::GetFromPersistent
(std::string key) {
Napi::Object storage = persistentStorage.
Value
();
return
storage.
Get
(key);
}
void
Context::QueueWorker
(nodegit::AsyncWorker *worker) {
threadPool.
QueueWorker
(worker);
}
std::shared_ptr<CleanupHandle>
Context::RemoveCleanupHandle
(std::string key) {
std::shared_ptr<CleanupHandle> cleanupItem = cleanupHandles[key];
cleanupHandles.
erase
(key);
return
cleanupItem;
}
void
Context::SaveToPersistent
(std::string key,
const
Napi::Value &value) {
Napi::Object storage = persistentStorage.
Value
();
storage.
Set
(key, value);
}
void
Context::SaveCleanupHandle
(std::string key, std::shared_ptr<CleanupHandle> cleanupItem) {
cleanupHandles[key] = cleanupItem;
}
void
Context::ShutdownThreadPool
() {
threadPool.
Shutdown
();
}
}
Back
|
FazBrowse Home
|
New Git URL