| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 06957ff commit ef546c8
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -260,12 +260,6 @@ inline uv_idle_t* Environment::immediate_idle_handle() { | |||
| 260 | 260 | return &immediate_idle_handle_; | |
| 261 | 261 | } | |
| 262 | 262 | ||
| 263 | - inline void Environment::RegisterHandleCleanup(uv_handle_t* handle, | ||
| 264 | - HandleCleanupCb cb, | ||
| 265 | - void* arg) { | ||
| 266 | - handle_cleanup_queue_.push_back(HandleCleanup{handle, cb, arg}); | ||
| 267 | - } | ||
| 268 | - | ||
| 269 | 263 | template <typename T, typename OnCloseCallback> | |
| 270 | 264 | inline void Environment::CloseHandle(T* handle, OnCloseCallback callback) { | |
| 271 | 265 | handle_cleanup_waiting_++; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1110,13 +1110,8 @@ void Environment::InitializeLibuv() { | |||
| 1110 | 1110 | } | |
| 1111 | 1111 | } | |
| 1112 | 1112 | ||
| 1113 | - // Register clean-up cb to be called to clean up the handles | ||
| 1114 | - // when the environment is freed, note that they are not cleaned in | ||
| 1115 | - // the one environment per process setup, but will be called in | ||
| 1116 | - // FreeEnvironment. | ||
| 1117 | - RegisterHandleCleanups(); | ||
| 1118 | - | ||
| 1119 | 1113 | StartProfilerIdleNotifier(); | |
| 1114 | + env_handle_initialized_ = true; | ||
| 1120 | 1115 | } | |
| 1121 | 1116 | ||
| 1122 | 1117 | void Environment::InitializeCompileCache() { | |
@@ -1194,27 +1189,27 @@ void Environment::ExitEnv(StopFlags::Flags flags) { | |||
| 1194 | 1189 | }); | |
| 1195 | 1190 | } | |
| 1196 | 1191 | ||
| 1197 | - void Environment::RegisterHandleCleanups() { | ||
| 1198 | - HandleCleanupCb close_and_finish = [](Environment* env, uv_handle_t* handle, | ||
| 1199 | - void* arg) { | ||
| 1200 | - handle->data = env; | ||
| 1192 | + void Environment::ClosePerEnvHandles() { | ||
| 1193 | + // If LoadEnvironment and InitializeLibuv are not called, like when building | ||
| 1194 | + // snapshots, skip closing the per environment handles. | ||
| 1195 | + if (!env_handle_initialized_) { | ||
| 1196 | + return; | ||
| 1197 | + } | ||
| 1201 | 1198 | ||
| 1202 | - env->CloseHandle(handle, [](uv_handle_t* handle) { | ||
| 1199 | + auto close_and_finish = [&](uv_handle_t* handle) { | ||
| 1200 | + CloseHandle(handle, [](uv_handle_t* handle) { | ||
| 1203 | 1201 | #ifdef DEBUG | |
| 1204 | 1202 | memset(handle, 0xab, uv_handle_size(handle->type)); | |
| 1205 | 1203 | #endif | |
| 1206 | 1204 | }); | |
| 1207 | 1205 | }; | |
| 1208 | 1206 | ||
| 1209 | - auto register_handle = [&](uv_handle_t* handle) { | ||
| 1210 | - RegisterHandleCleanup(handle, close_and_finish, nullptr); | ||
| 1211 | - }; | ||
| 1212 | - register_handle(reinterpret_cast<uv_handle_t*>(timer_handle())); | ||
| 1213 | - register_handle(reinterpret_cast<uv_handle_t*>(immediate_check_handle())); | ||
| 1214 | - register_handle(reinterpret_cast<uv_handle_t*>(immediate_idle_handle())); | ||
| 1215 | - register_handle(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_)); | ||
| 1216 | - register_handle(reinterpret_cast<uv_handle_t*>(&idle_check_handle_)); | ||
| 1217 | - register_handle(reinterpret_cast<uv_handle_t*>(&task_queues_async_)); | ||
| 1207 | + close_and_finish(reinterpret_cast<uv_handle_t*>(timer_handle())); | ||
| 1208 | + close_and_finish(reinterpret_cast<uv_handle_t*>(immediate_check_handle())); | ||
| 1209 | + close_and_finish(reinterpret_cast<uv_handle_t*>(immediate_idle_handle())); | ||
| 1210 | + close_and_finish(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_)); | ||
| 1211 | + close_and_finish(reinterpret_cast<uv_handle_t*>(&idle_check_handle_)); | ||
| 1212 | + close_and_finish(reinterpret_cast<uv_handle_t*>(&task_queues_async_)); | ||
| 1218 | 1213 | } | |
| 1219 | 1214 | ||
| 1220 | 1215 | void Environment::CleanupHandles() { | |
@@ -1234,10 +1229,6 @@ void Environment::CleanupHandles() { | |||
| 1234 | 1229 | for (HandleWrap* handle : handle_wrap_queue_) | |
| 1235 | 1230 | handle->Close(); | |
| 1236 | 1231 | ||
| 1237 | - for (HandleCleanup& hc : handle_cleanup_queue_) | ||
| 1238 | - hc.cb_(this, hc.handle_, hc.arg_); | ||
| 1239 | - handle_cleanup_queue_.clear(); | ||
| 1240 | - | ||
| 1241 | 1232 | while (handle_cleanup_waiting_ != 0 || | |
| 1242 | 1233 | request_waiting_ != 0 || | |
| 1243 | 1234 | !handle_wrap_queue_.IsEmpty()) { | |
@@ -1291,6 +1282,7 @@ MaybeLocal<Value> Environment::RunSnapshotDeserializeMain() const { | |||
| 1291 | 1282 | void Environment::RunCleanup() { | |
| 1292 | 1283 | started_cleanup_ = true; | |
| 1293 | 1284 | TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "RunCleanup"); | |
| 1285 | + ClosePerEnvHandles(); | ||
| 1294 | 1286 | // Only BaseObject's cleanups are registered as per-realm cleanup hooks now. | |
| 1295 | 1287 | // Defer the BaseObject cleanup after handles are cleaned up. | |
| 1296 | 1288 | CleanupHandles(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -682,24 +682,10 @@ class Environment final : public MemoryRetainer { | |||
| 682 | 682 | inline const std::vector<std::string>& argv(); | |
| 683 | 683 | const std::string& exec_path() const; | |
| 684 | 684 | ||
| 685 | - typedef void (*HandleCleanupCb)(Environment* env, | ||
| 686 | - uv_handle_t* handle, | ||
| 687 | - void* arg); | ||
| 688 | - struct HandleCleanup { | ||
| 689 | - uv_handle_t* handle_; | ||
| 690 | - HandleCleanupCb cb_; | ||
| 691 | - void* arg_; | ||
| 692 | - }; | ||
| 693 | - | ||
| 694 | - void RegisterHandleCleanups(); | ||
| 695 | 685 | void CleanupHandles(); | |
| 696 | 686 | void Exit(ExitCode code); | |
| 697 | 687 | void ExitEnv(StopFlags::Flags flags); | |
| 698 | - | ||
| 699 | - // Register clean-up cb to be called on environment destruction. | ||
| 700 | - inline void RegisterHandleCleanup(uv_handle_t* handle, | ||
| 701 | - HandleCleanupCb cb, | ||
| 702 | - void* arg); | ||
| 688 | + void ClosePerEnvHandles(); | ||
| 703 | 689 | ||
| 704 | 690 | template <typename T, typename OnCloseCallback> | |
| 705 | 691 | inline void CloseHandle(T* handle, OnCloseCallback callback); | |
@@ -1104,6 +1090,8 @@ class Environment final : public MemoryRetainer { | |||
| 1104 | 1090 | std::list<binding::DLib> loaded_addons_; | |
| 1105 | 1091 | v8::Isolate* const isolate_; | |
| 1106 | 1092 | IsolateData* const isolate_data_; | |
| 1093 | + | ||
| 1094 | + bool env_handle_initialized_ = false; | ||
| 1107 | 1095 | uv_timer_t timer_handle_; | |
| 1108 | 1096 | uv_check_t immediate_check_handle_; | |
| 1109 | 1097 | uv_idle_t immediate_idle_handle_; | |
@@ -1216,7 +1204,6 @@ class Environment final : public MemoryRetainer { | |||
| 1216 | 1204 | CleanableQueue cleanable_queue_; | |
| 1217 | 1205 | HandleWrapQueue handle_wrap_queue_; | |
| 1218 | 1206 | ReqWrapQueue req_wrap_queue_; | |
| 1219 | - std::list<HandleCleanup> handle_cleanup_queue_; | ||
| 1220 | 1207 | int handle_cleanup_waiting_ = 0; | |
| 1221 | 1208 | int request_waiting_ = 0; | |
| 1222 | 1209 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments