| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6f53c09 commit 7d01b6a
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 | |
|---|---|---|---|
@@ -1109,13 +1109,8 @@ void Environment::InitializeLibuv() { | |||
| 1109 | 1109 | } | |
| 1110 | 1110 | } | |
| 1111 | 1111 | ||
| 1112 | - // Register clean-up cb to be called to clean up the handles | ||
| 1113 | - // when the environment is freed, note that they are not cleaned in | ||
| 1114 | - // the one environment per process setup, but will be called in | ||
| 1115 | - // FreeEnvironment. | ||
| 1116 | - RegisterHandleCleanups(); | ||
| 1117 | - | ||
| 1118 | 1112 | StartProfilerIdleNotifier(); | |
| 1113 | + env_handle_initialized_ = true; | ||
| 1119 | 1114 | } | |
| 1120 | 1115 | ||
| 1121 | 1116 | void Environment::ExitEnv(StopFlags::Flags flags) { | |
@@ -1136,27 +1131,27 @@ void Environment::ExitEnv(StopFlags::Flags flags) { | |||
| 1136 | 1131 | }); | |
| 1137 | 1132 | } | |
| 1138 | 1133 | ||
| 1139 | - void Environment::RegisterHandleCleanups() { | ||
| 1140 | - HandleCleanupCb close_and_finish = [](Environment* env, uv_handle_t* handle, | ||
| 1141 | - void* arg) { | ||
| 1142 | - handle->data = env; | ||
| 1134 | + void Environment::ClosePerEnvHandles() { | ||
| 1135 | + // If LoadEnvironment and InitializeLibuv are not called, like when building | ||
| 1136 | + // snapshots, skip closing the per environment handles. | ||
| 1137 | + if (!env_handle_initialized_) { | ||
| 1138 | + return; | ||
| 1139 | + } | ||
| 1143 | 1140 | ||
| 1144 | - env->CloseHandle(handle, [](uv_handle_t* handle) { | ||
| 1141 | + auto close_and_finish = [&](uv_handle_t* handle) { | ||
| 1142 | + CloseHandle(handle, [](uv_handle_t* handle) { | ||
| 1145 | 1143 | #ifdef DEBUG | |
| 1146 | 1144 | memset(handle, 0xab, uv_handle_size(handle->type)); | |
| 1147 | 1145 | #endif | |
| 1148 | 1146 | }); | |
| 1149 | 1147 | }; | |
| 1150 | 1148 | ||
| 1151 | - auto register_handle = [&](uv_handle_t* handle) { | ||
| 1152 | - RegisterHandleCleanup(handle, close_and_finish, nullptr); | ||
| 1153 | - }; | ||
| 1154 | - register_handle(reinterpret_cast<uv_handle_t*>(timer_handle())); | ||
| 1155 | - register_handle(reinterpret_cast<uv_handle_t*>(immediate_check_handle())); | ||
| 1156 | - register_handle(reinterpret_cast<uv_handle_t*>(immediate_idle_handle())); | ||
| 1157 | - register_handle(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_)); | ||
| 1158 | - register_handle(reinterpret_cast<uv_handle_t*>(&idle_check_handle_)); | ||
| 1159 | - register_handle(reinterpret_cast<uv_handle_t*>(&task_queues_async_)); | ||
| 1149 | + close_and_finish(reinterpret_cast<uv_handle_t*>(timer_handle())); | ||
| 1150 | + close_and_finish(reinterpret_cast<uv_handle_t*>(immediate_check_handle())); | ||
| 1151 | + close_and_finish(reinterpret_cast<uv_handle_t*>(immediate_idle_handle())); | ||
| 1152 | + close_and_finish(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_)); | ||
| 1153 | + close_and_finish(reinterpret_cast<uv_handle_t*>(&idle_check_handle_)); | ||
| 1154 | + close_and_finish(reinterpret_cast<uv_handle_t*>(&task_queues_async_)); | ||
| 1160 | 1155 | } | |
| 1161 | 1156 | ||
| 1162 | 1157 | void Environment::CleanupHandles() { | |
@@ -1176,10 +1171,6 @@ void Environment::CleanupHandles() { | |||
| 1176 | 1171 | for (HandleWrap* handle : handle_wrap_queue_) | |
| 1177 | 1172 | handle->Close(); | |
| 1178 | 1173 | ||
| 1179 | - for (HandleCleanup& hc : handle_cleanup_queue_) | ||
| 1180 | - hc.cb_(this, hc.handle_, hc.arg_); | ||
| 1181 | - handle_cleanup_queue_.clear(); | ||
| 1182 | - | ||
| 1183 | 1174 | while (handle_cleanup_waiting_ != 0 || | |
| 1184 | 1175 | request_waiting_ != 0 || | |
| 1185 | 1176 | !handle_wrap_queue_.IsEmpty()) { | |
@@ -1233,6 +1224,7 @@ MaybeLocal<Value> Environment::RunSnapshotDeserializeMain() const { | |||
| 1233 | 1224 | void Environment::RunCleanup() { | |
| 1234 | 1225 | started_cleanup_ = true; | |
| 1235 | 1226 | TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "RunCleanup"); | |
| 1227 | + ClosePerEnvHandles(); | ||
| 1236 | 1228 | // Only BaseObject's cleanups are registered as per-realm cleanup hooks now. | |
| 1237 | 1229 | // Defer the BaseObject cleanup after handles are cleaned up. | |
| 1238 | 1230 | CleanupHandles(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -683,24 +683,10 @@ class Environment : public MemoryRetainer { | |||
| 683 | 683 | inline const std::vector<std::string>& argv(); | |
| 684 | 684 | const std::string& exec_path() const; | |
| 685 | 685 | ||
| 686 | - typedef void (*HandleCleanupCb)(Environment* env, | ||
| 687 | - uv_handle_t* handle, | ||
| 688 | - void* arg); | ||
| 689 | - struct HandleCleanup { | ||
| 690 | - uv_handle_t* handle_; | ||
| 691 | - HandleCleanupCb cb_; | ||
| 692 | - void* arg_; | ||
| 693 | - }; | ||
| 694 | - | ||
| 695 | - void RegisterHandleCleanups(); | ||
| 696 | 686 | void CleanupHandles(); | |
| 697 | 687 | void Exit(ExitCode code); | |
| 698 | 688 | void ExitEnv(StopFlags::Flags flags); | |
| 699 | - | ||
| 700 | - // Register clean-up cb to be called on environment destruction. | ||
| 701 | - inline void RegisterHandleCleanup(uv_handle_t* handle, | ||
| 702 | - HandleCleanupCb cb, | ||
| 703 | - void* arg); | ||
| 689 | + void ClosePerEnvHandles(); | ||
| 704 | 690 | ||
| 705 | 691 | template <typename T, typename OnCloseCallback> | |
| 706 | 692 | inline void CloseHandle(T* handle, OnCloseCallback callback); | |
@@ -1090,6 +1076,8 @@ class Environment : public MemoryRetainer { | |||
| 1090 | 1076 | std::list<binding::DLib> loaded_addons_; | |
| 1091 | 1077 | v8::Isolate* const isolate_; | |
| 1092 | 1078 | IsolateData* const isolate_data_; | |
| 1079 | + | ||
| 1080 | + bool env_handle_initialized_ = false; | ||
| 1093 | 1081 | uv_timer_t timer_handle_; | |
| 1094 | 1082 | uv_check_t immediate_check_handle_; | |
| 1095 | 1083 | uv_idle_t immediate_idle_handle_; | |
@@ -1201,7 +1189,6 @@ class Environment : public MemoryRetainer { | |||
| 1201 | 1189 | CleanableQueue cleanable_queue_; | |
| 1202 | 1190 | HandleWrapQueue handle_wrap_queue_; | |
| 1203 | 1191 | ReqWrapQueue req_wrap_queue_; | |
| 1204 | - std::list<HandleCleanup> handle_cleanup_queue_; | ||
| 1205 | 1192 | int handle_cleanup_waiting_ = 0; | |
| 1206 | 1193 | int request_waiting_ = 0; | |
| 1207 | 1194 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments