The C and C++ Include Header Files
/usr/include/nodejs/src/node_worker.h
$ cat -n /usr/include/nodejs/src/node_worker.h 1 #ifndef SRC_NODE_WORKER_H_ 2 #define SRC_NODE_WORKER_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include
7 #include "node_messaging.h" 8 #include "uv.h" 9 10 namespace node { 11 namespace worker { 12 13 class WorkerThreadData; 14 15 enum ResourceLimits { 16 kMaxYoungGenerationSizeMb, 17 kMaxOldGenerationSizeMb, 18 kCodeRangeSizeMb, 19 kStackSizeMb, 20 kTotalResourceLimitCount 21 }; 22 23 // A worker thread, as represented in its parent thread. 24 class Worker : public AsyncWrap { 25 public: 26 Worker(Environment* env, 27 v8::Local
wrap, 28 const std::string& url, 29 std::shared_ptr
per_isolate_opts, 30 std::vector
&& exec_argv, 31 std::shared_ptr
env_vars); 32 ~Worker() override; 33 34 // Run the worker. This is only called from the worker thread. 35 void Run(); 36 37 // Forcibly exit the thread with a specified exit code. This may be called 38 // from any thread. `error_code` and `error_message` can be used to create 39 // a custom `'error'` event before emitting `'exit'`. 40 void Exit(int code, 41 const char* error_code = nullptr, 42 const char* error_message = nullptr); 43 44 // Wait for the worker thread to stop (in a blocking manner). 45 void JoinThread(); 46 47 template
48 inline bool RequestInterrupt(Fn&& cb); 49 50 void MemoryInfo(MemoryTracker* tracker) const override; 51 SET_MEMORY_INFO_NAME(Worker) 52 SET_SELF_SIZE(Worker) 53 54 bool is_stopped() const; 55 std::shared_ptr
array_buffer_allocator(); 56 57 static void New(const v8::FunctionCallbackInfo
& args); 58 static void CloneParentEnvVars( 59 const v8::FunctionCallbackInfo
& args); 60 static void SetEnvVars(const v8::FunctionCallbackInfo
& args); 61 static void StartThread(const v8::FunctionCallbackInfo
& args); 62 static void StopThread(const v8::FunctionCallbackInfo
& args); 63 static void Ref(const v8::FunctionCallbackInfo
& args); 64 static void Unref(const v8::FunctionCallbackInfo
& args); 65 static void GetResourceLimits( 66 const v8::FunctionCallbackInfo
& args); 67 v8::Local
GetResourceLimits(v8::Isolate* isolate) const; 68 static void TakeHeapSnapshot(const v8::FunctionCallbackInfo
& args); 69 static void LoopIdleTime(const v8::FunctionCallbackInfo
& args); 70 static void LoopStartTime(const v8::FunctionCallbackInfo
& args); 71 72 private: 73 bool CreateEnvMessagePort(Environment* env); 74 static size_t NearHeapLimit(void* data, size_t current_heap_limit, 75 size_t initial_heap_limit); 76 77 std::shared_ptr
per_isolate_opts_; 78 std::vector
exec_argv_; 79 std::vector
argv_; 80 81 MultiIsolatePlatform* platform_; 82 std::shared_ptr
array_buffer_allocator_; 83 v8::Isolate* isolate_ = nullptr; 84 uv_thread_t tid_; 85 86 std::unique_ptr
inspector_parent_handle_; 87 88 // This mutex protects access to all variables listed below it. 89 mutable Mutex mutex_; 90 91 bool thread_joined_ = true; 92 const char* custom_error_ = nullptr; 93 std::string custom_error_str_; 94 int exit_code_ = 0; 95 ThreadId thread_id_; 96 uintptr_t stack_base_ = 0; 97 98 // Custom resource constraints: 99 double resource_limits_[kTotalResourceLimitCount]; 100 void UpdateResourceConstraints(v8::ResourceConstraints* constraints); 101 102 // Full size of the thread's stack. 103 size_t stack_size_ = 4 * 1024 * 1024; 104 // Stack buffer size that is not available to the JS engine. 105 static constexpr size_t kStackBufferSize = 192 * 1024; 106 107 std::unique_ptr
child_port_data_; 108 std::shared_ptr
env_vars_; 109 110 // This is always kept alive because the JS object associated with the Worker 111 // instance refers to it via its [kPort] property. 112 MessagePort* parent_port_ = nullptr; 113 114 // A raw flag that is used by creator and worker threads to 115 // sync up on pre-mature termination of worker - while in the 116 // warmup phase. Once the worker is fully warmed up, use the 117 // async handle of the worker's Environment for the same purpose. 118 bool stopped_ = true; 119 120 bool has_ref_ = true; 121 uint64_t environment_flags_ = EnvironmentFlags::kNoFlags; 122 123 // The real Environment of the worker object. It has a lesser 124 // lifespan than the worker object itself - comes to life 125 // when the worker thread creates a new Environment, and gets 126 // destroyed alongwith the worker thread. 127 Environment* env_ = nullptr; 128 129 friend class WorkerThreadData; 130 }; 131 132 template
133 bool Worker::RequestInterrupt(Fn&& cb) { 134 Mutex::ScopedLock lock(mutex_); 135 if (env_ == nullptr) return false; 136 env_->RequestInterrupt(std::move(cb)); 137 return true; 138 } 139 140 } // namespace worker 141 } // namespace node 142 143 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 144 145 146 #endif // SRC_NODE_WORKER_H_
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2024 MyWebUniversity.com ™