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: 8 8 100.0 %
Date: 2019-02-26 22:23:30 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 "node_messaging.h"
7
#include <unordered_map>
8
9
namespace node {
10
namespace worker {
11
12
class WorkerThreadData;
13
14
// A worker thread, as represented in its parent thread.
15
class Worker : public AsyncWrap {
16
 public:
17
  Worker(Environment* env,
18
         v8::Local<v8::Object> wrap,
19
         const std::string& url,
20
         std::shared_ptr<PerIsolateOptions> per_isolate_opts);
21
  ~Worker() override;
22
23
  // Run the worker. This is only called from the worker thread.
24
  void Run();
25
26
  // Forcibly exit the thread with a specified exit code. This may be called
27
  // from any thread.
28
  void Exit(int code);
29
30
  // Wait for the worker thread to stop (in a blocking manner).
31
  void JoinThread();
32
33
4
  void MemoryInfo(MemoryTracker* tracker) const override {
34
    tracker->TrackFieldWithSize(
35
4
        "isolate_data", sizeof(IsolateData), "IsolateData");
36
4
    tracker->TrackFieldWithSize("env", sizeof(Environment), "Environment");
37
4
    tracker->TrackField("thread_exit_async", *thread_exit_async_);
38
4
    tracker->TrackField("parent_port", parent_port_);
39
4
  }
40
41
4
  SET_MEMORY_INFO_NAME(Worker)
42
4
  SET_SELF_SIZE(Worker)
43
44
  bool is_stopped() const;
45
46
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
47
  static void StartThread(const v8::FunctionCallbackInfo<v8::Value>& args);
48
  static void StopThread(const v8::FunctionCallbackInfo<v8::Value>& args);
49
  static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
50
  static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
51
52
 private:
53
  void OnThreadStopped();
54
55
  const std::string url_;
56
57
  std::shared_ptr<PerIsolateOptions> per_isolate_opts_;
58
  MultiIsolatePlatform* platform_;
59
  v8::Isolate* isolate_ = nullptr;
60
  bool profiler_idle_notifier_started_;
61
  uv_thread_t tid_;
62
63
#if NODE_USE_V8_PLATFORM && HAVE_INSPECTOR
64
  std::unique_ptr<inspector::ParentInspectorHandle> inspector_parent_handle_;
65
#endif
66
67
  // This mutex protects access to all variables listed below it.
68
  mutable Mutex mutex_;
69
70
  // Currently only used for telling the parent thread that the child
71
  // thread exited.
72
  std::unique_ptr<uv_async_t> thread_exit_async_;
73
  bool scheduled_on_thread_stopped_ = false;
74
75
  // This mutex only protects stopped_. If both locks are acquired, this needs
76
  // to be the latter one.
77
  mutable Mutex stopped_mutex_;
78
  bool stopped_ = true;
79
80
  bool thread_joined_ = true;
81
  int exit_code_ = 0;
82
  uint64_t thread_id_ = -1;
83
  uintptr_t stack_base_;
84
85
  // Full size of the thread's stack.
86
  static constexpr size_t kStackSize = 4 * 1024 * 1024;
87
  // Stack buffer size that is not available to the JS engine.
88
  static constexpr size_t kStackBufferSize = 192 * 1024;
89
90
  std::unique_ptr<MessagePortData> child_port_data_;
91
92
  // The child port is kept alive by the child Environment's persistent
93
  // handle to it, as long as that child Environment exists.
94
  MessagePort* child_port_ = nullptr;
95
  // This is always kept alive because the JS object associated with the Worker
96
  // instance refers to it via its [kPort] property.
97
  MessagePort* parent_port_ = nullptr;
98
99
  friend class WorkerThreadData;
100
};
101
102
}  // namespace worker
103
}  // namespace node
104
105
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
106
107
108
#endif  // SRC_NODE_WORKER_H_