Skip to content

Commit

Permalink
src: inline AsyncCleanupHookHandle in headers
Browse files Browse the repository at this point in the history
Fixes: #36349

PR-URL: #37000
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
implausible authored and jasnell committed Jan 24, 2021
1 parent a87190b commit 1fe571a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/api/hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void RunAsyncCleanupHook(void* arg) {
info->fun(info->arg, FinishAsyncCleanupHook, info);
}

AsyncCleanupHookHandle AddEnvironmentCleanupHook(
ACHHandle* AddEnvironmentCleanupHookRaw(
Isolate* isolate,
AsyncCleanupHook fun,
void* arg) {
Expand All @@ -157,11 +157,11 @@ AsyncCleanupHookHandle AddEnvironmentCleanupHook(
info->arg = arg;
info->self = info;
env->AddCleanupHook(RunAsyncCleanupHook, info.get());
return AsyncCleanupHookHandle(new ACHHandle { info });
return new ACHHandle { info };
}

void RemoveEnvironmentCleanupHook(
AsyncCleanupHookHandle handle) {
void RemoveEnvironmentCleanupHookRaw(
ACHHandle* handle) {
if (handle->info->started) return;
handle->info->self.reset();
handle->info->env->RemoveCleanupHook(RunAsyncCleanupHook, handle->info.get());
Expand Down
14 changes: 12 additions & 2 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,12 +925,22 @@ struct ACHHandle;
struct NODE_EXTERN DeleteACHHandle { void operator()(ACHHandle*) const; };
typedef std::unique_ptr<ACHHandle, DeleteACHHandle> AsyncCleanupHookHandle;

NODE_EXTERN AsyncCleanupHookHandle AddEnvironmentCleanupHook(
NODE_EXTERN ACHHandle* AddEnvironmentCleanupHookRaw(
v8::Isolate* isolate,
void (*fun)(void* arg, void (*cb)(void*), void* cbarg),
void* arg);
inline AsyncCleanupHookHandle AddEnvironmentCleanupHook(
v8::Isolate* isolate,
void (*fun)(void* arg, void (*cb)(void*), void* cbarg),
void* arg) {
return AsyncCleanupHookHandle(AddEnvironmentCleanupHookRaw(isolate, fun,
arg));
}

NODE_EXTERN void RemoveEnvironmentCleanupHook(AsyncCleanupHookHandle holder);
NODE_EXTERN void RemoveEnvironmentCleanupHookRaw(ACHHandle* holder);
inline void RemoveEnvironmentCleanupHook(AsyncCleanupHookHandle holder) {
RemoveEnvironmentCleanupHookRaw(holder.get());
}

/* Returns the id of the current execution context. If the return value is
* zero then no execution has been set. This will happen if the user handles
Expand Down

0 comments on commit 1fe571a

Please sign in to comment.