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: 0 7 0.0 %
Date: 2019-02-01 22:03:38 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
// A worker thread, as represented in its parent thread.
13
class Worker : public AsyncWrap {
14
 public:
15
  Worker(Environment* env,
16
         v8::Local<v8::Object> wrap,
17
         const std::string& url,
18
         std::shared_ptr<PerIsolateOptions> per_isolate_opts);
19
  ~Worker();
20
21
  // Run the worker. This is only called from the worker thread.
22
  void Run();
23
24
  // Forcibly exit the thread with a specified exit code. This may be called
25
  // from any thread.
26
  void Exit(int code);
27
28
  // Wait for the worker thread to stop (in a blocking manner).
29
  void JoinThread();
30
31
  void MemoryInfo(MemoryTracker* tracker) const override {
32
    tracker->TrackFieldWithSize(
33
        "isolate_data", sizeof(IsolateData), "IsolateData");
34
    tracker->TrackFieldWithSize("env", sizeof(Environment), "Environment");
35
    tracker->TrackField("thread_exit_async", *thread_exit_async_);
36
    tracker->TrackField("parent_port", parent_port_);
37
  }
38
39
  SET_MEMORY_INFO_NAME(Worker)
40
  SET_SELF_SIZE(Worker)
41
42
  bool is_stopped() const;
43
44
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
45
  static void StartThread(const v8::FunctionCallbackInfo<v8::Value>& args);
46
  static void StopThread(const v8::FunctionCallbackInfo<v8::Value>& args);
47
  static void GetMessagePort(const v8::FunctionCallbackInfo<v8::Value>& args);
48
  static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
49
  static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
50
51
 private:
52
  void OnThreadStopped();
53
  void DisposeIsolate();
54
55
  uv_loop_t loop_;
56
  DeleteFnPtr<IsolateData, FreeIsolateData> isolate_data_;
57
  DeleteFnPtr<Environment, FreeEnvironment> env_;
58
  const std::string url_;
59
  v8::Isolate* isolate_ = nullptr;
60
  DeleteFnPtr<ArrayBufferAllocator, FreeArrayBufferAllocator>
61
      array_buffer_allocator_;
62
  uv_thread_t tid_;
63
64
  // This mutex protects access to all variables listed below it.
65
  mutable Mutex mutex_;
66
67
  // Currently only used for telling the parent thread that the child
68
  // thread exited.
69
  std::unique_ptr<uv_async_t> thread_exit_async_;
70
  bool scheduled_on_thread_stopped_ = false;
71
72
  // This mutex only protects stopped_. If both locks are acquired, this needs
73
  // to be the latter one.
74
  mutable Mutex stopped_mutex_;
75
  bool stopped_ = true;
76
77
  bool thread_joined_ = true;
78
  int exit_code_ = 0;
79
  uint64_t thread_id_ = -1;
80
81
  std::unique_ptr<MessagePortData> child_port_data_;
82
83
  // The child port is always kept alive by the child Environment's persistent
84
  // handle to it.
85
  MessagePort* child_port_ = nullptr;
86
  // This is always kept alive because the JS object associated with the Worker
87
  // instance refers to it via its [kPort] property.
88
  MessagePort* parent_port_ = nullptr;
89
};
90
91
}  // namespace worker
92
}  // namespace node
93
94
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
95
96
97
#endif  // SRC_NODE_WORKER_H_