GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_worker.h Lines: 6 6 100.0 %
Date: 2019-07-28 22:34:34 Branches: 0 0 - %

Line Branch Exec Source
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 <unordered_map>
7
#include "node_messaging.h"
8
#include "uv.h"
9
10
namespace node {
11
namespace worker {
12
13
class WorkerThreadData;
14
15
// A worker thread, as represented in its parent thread.
16
class Worker : public AsyncWrap {
17
 public:
18
  Worker(Environment* env,
19
         v8::Local<v8::Object> wrap,
20
         const std::string& url,
21
         std::shared_ptr<PerIsolateOptions> per_isolate_opts,
22
         std::vector<std::string>&& exec_argv);
23
  ~Worker() override;
24
25
  // Run the worker. This is only called from the worker thread.
26
  void Run();
27
28
  // Forcibly exit the thread with a specified exit code. This may be called
29
  // from any thread.
30
  void Exit(int code);
31
32
  // Wait for the worker thread to stop (in a blocking manner).
33
  void JoinThread();
34
35
4
  void MemoryInfo(MemoryTracker* tracker) const override {
36
4
    tracker->TrackField("parent_port", parent_port_);
37
4
    tracker->TrackInlineField(&on_thread_finished_, "on_thread_finished_");
38
4
  }
39
40
4
  SET_MEMORY_INFO_NAME(Worker)
41
4
  SET_SELF_SIZE(Worker)
42
43
  bool is_stopped() const;
44
45
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
46
  static void CloneParentEnvVars(
47
      const v8::FunctionCallbackInfo<v8::Value>& args);
48
  static void SetEnvVars(const v8::FunctionCallbackInfo<v8::Value>& args);
49
  static void StartThread(const v8::FunctionCallbackInfo<v8::Value>& args);
50
  static void StopThread(const v8::FunctionCallbackInfo<v8::Value>& args);
51
  static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
52
  static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
53
54
 private:
55
  void CreateEnvMessagePort(Environment* env);
56
57
  std::shared_ptr<PerIsolateOptions> per_isolate_opts_;
58
  std::vector<std::string> exec_argv_;
59
  std::vector<std::string> argv_;
60
61
  MultiIsolatePlatform* platform_;
62
  v8::Isolate* isolate_ = nullptr;
63
  bool start_profiler_idle_notifier_;
64
  uv_thread_t tid_;
65
66
#if NODE_USE_V8_PLATFORM && HAVE_INSPECTOR
67
  std::unique_ptr<inspector::ParentInspectorHandle> inspector_parent_handle_;
68
#endif
69
70
  // This mutex protects access to all variables listed below it.
71
  mutable Mutex mutex_;
72
73
  bool thread_joined_ = true;
74
  int exit_code_ = 0;
75
  uint64_t thread_id_ = -1;
76
  uintptr_t stack_base_ = 0;
77
78
  // Full size of the thread's stack.
79
  static constexpr size_t kStackSize = 4 * 1024 * 1024;
80
  // Stack buffer size that is not available to the JS engine.
81
  static constexpr size_t kStackBufferSize = 192 * 1024;
82
83
  std::unique_ptr<MessagePortData> child_port_data_;
84
  std::shared_ptr<KVStore> env_vars_;
85
86
  // The child port is kept alive by the child Environment's persistent
87
  // handle to it, as long as that child Environment exists.
88
  MessagePort* child_port_ = nullptr;
89
  // This is always kept alive because the JS object associated with the Worker
90
  // instance refers to it via its [kPort] property.
91
  MessagePort* parent_port_ = nullptr;
92
93
  AsyncRequest on_thread_finished_;
94
95
  // A raw flag that is used by creator and worker threads to
96
  // sync up on pre-mature termination of worker  - while in the
97
  // warmup phase.  Once the worker is fully warmed up, use the
98
  // async handle of the worker's Environment for the same purpose.
99
  bool stopped_ = true;
100
101
  // The real Environment of the worker object. It has a lesser
102
  // lifespan than the worker object itself - comes to life
103
  // when the worker thread creates a new Environment, and gets
104
  // destroyed alongwith the worker thread.
105
  Environment* env_ = nullptr;
106
107
  friend class WorkerThreadData;
108
};
109
110
}  // namespace worker
111
}  // namespace node
112
113
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
114
115
116
#endif  // SRC_NODE_WORKER_H_