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