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: 11 11 100.0 %
Date: 2019-03-02 22:23:06 Branches: 1 2 50.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
308
class AsyncRequest : public MemoryRetainer {
16
 public:
17
354
  AsyncRequest() {}
18
  void Install(Environment* env, void* data, uv_async_cb target);
19
  void Uninstall();
20
  void Stop();
21
  void SetStopped(bool flag);
22
  bool IsStopped() const;
23
  uv_async_t* GetHandle();
24
  void MemoryInfo(MemoryTracker* tracker) const override;
25
8
  SET_MEMORY_INFO_NAME(AsyncRequest)
26
16
  SET_SELF_SIZE(AsyncRequest)
27
28
 private:
29
  Environment* env_;
30
  uv_async_t* async_ = nullptr;
31
  mutable Mutex mutex_;
32
  bool stop_ = true;
33
};
34
35
// A worker thread, as represented in its parent thread.
36
class Worker : public AsyncWrap {
37
 public:
38
  Worker(Environment* env,
39
         v8::Local<v8::Object> wrap,
40
         const std::string& url,
41
         std::shared_ptr<PerIsolateOptions> per_isolate_opts,
42
         std::vector<std::string>&& exec_argv);
43
  ~Worker() override;
44
45
  // Run the worker. This is only called from the worker thread.
46
  void Run();
47
48
  // Forcibly exit the thread with a specified exit code. This may be called
49
  // from any thread.
50
  void Exit(int code);
51
52
  // Wait for the worker thread to stop (in a blocking manner).
53
  void JoinThread();
54
55
4
  void MemoryInfo(MemoryTracker* tracker) const override {
56
4
    tracker->TrackField("parent_port", parent_port_);
57
4
    tracker->TrackInlineField(&thread_stopper_, "thread_stopper_");
58
4
    tracker->TrackInlineField(&on_thread_finished_, "on_thread_finished_");
59
4
  }
60
61
4
  SET_MEMORY_INFO_NAME(Worker)
62
4
  SET_SELF_SIZE(Worker)
63
64
  bool is_stopped() const;
65
66
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
67
  static void StartThread(const v8::FunctionCallbackInfo<v8::Value>& args);
68
  static void StopThread(const v8::FunctionCallbackInfo<v8::Value>& args);
69
  static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
70
  static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
71
72
 private:
73
  void OnThreadStopped();
74
75
  const std::string url_;
76
77
  std::shared_ptr<PerIsolateOptions> per_isolate_opts_;
78
  std::vector<std::string> exec_argv_;
79
  MultiIsolatePlatform* platform_;
80
  v8::Isolate* isolate_ = nullptr;
81
  bool profiler_idle_notifier_started_;
82
  uv_thread_t tid_;
83
84
#if NODE_USE_V8_PLATFORM && HAVE_INSPECTOR
85
  std::unique_ptr<inspector::ParentInspectorHandle> inspector_parent_handle_;
86
#endif
87
88
  // This mutex protects access to all variables listed below it.
89
  mutable Mutex mutex_;
90
91
  bool thread_joined_ = true;
92
  int exit_code_ = 0;
93
  uint64_t thread_id_ = -1;
94
  uintptr_t stack_base_;
95
96
  // Full size of the thread's stack.
97
  static constexpr size_t kStackSize = 4 * 1024 * 1024;
98
  // Stack buffer size that is not available to the JS engine.
99
  static constexpr size_t kStackBufferSize = 192 * 1024;
100
101
  std::unique_ptr<MessagePortData> child_port_data_;
102
103
  // The child port is kept alive by the child Environment's persistent
104
  // handle to it, as long as that child Environment exists.
105
  MessagePort* child_port_ = nullptr;
106
  // This is always kept alive because the JS object associated with the Worker
107
  // instance refers to it via its [kPort] property.
108
  MessagePort* parent_port_ = nullptr;
109
110
  AsyncRequest thread_stopper_;
111
  AsyncRequest on_thread_finished_;
112
113
  friend class WorkerThreadData;
114
};
115
116
}  // namespace worker
117
}  // namespace node
118
119
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
120
121
122
#endif  // SRC_NODE_WORKER_H_