Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b1750a4
quic: continued refactoring for quic_stream/quic_session
jasnell Jul 1, 2020
b5bf5bb
quic: refactor native object flags for better readability
jasnell Jul 1, 2020
f7510ca
quic: additional cleanups on the c++ side
jasnell Jul 1, 2020
f9c2245
quic: refactor QuicSession close/destroy flow
jasnell Jul 1, 2020
3acdd6a
quic: refactor QuicSession shared state to use AliasedStruct
jasnell Jul 1, 2020
e4d369e
quic: remove onSessionDestroy callback
jasnell Jul 2, 2020
7b062ca
quic: refactor qlog handling
jasnell Jul 2, 2020
3837d9c
quic: fixup lint issues
jasnell Jul 2, 2020
5a87e9b
quic: cleanup timers if they haven't been already
jasnell Jul 3, 2020
1b1e985
quic: add missing memory tracker fields
jasnell Jul 3, 2020
e7dadd3
doc: specify how fs.WriteStream/ReadStreams are created
jasnell Jul 3, 2020
d4f6900
src: add TimerWrap utility
jasnell Jul 3, 2020
e19a251
src: replace InspectorTimer with TimerWrap utility
jasnell Jul 3, 2020
0f97d60
quic: use TimerWrap for idle and retransmit timers
jasnell Jul 3, 2020
8a57788
doc: move gibfahn to emeritus
Trott Jul 4, 2020
7eb500b
doc: move digitalinfinity to emeritus
Trott Jul 4, 2020
654df09
doc: move ERR_FEATURE_UNAVAILABLE_ON_PLATFORM to current errors
Trott Jul 4, 2020
82c435d
src: fix unused namespace member
Jul 5, 2020
67ba825
src: fix minor comment typo in KeyObjectData
danbev Jul 2, 2020
ddfaafa
repl: fix verb conjugation in deprecation message
Trott Jul 4, 2020
9f0671e
test: replace deprecated function call from test-repl-history-navigation
Trott Jul 4, 2020
bf77289
doc: remove errors that were never released
Trott Jul 4, 2020
3975799
doc: replace http to https of link urls
sapics Jun 29, 2020
ee3416b
lib: replace http to https of comment link urls
sapics Jun 29, 2020
772fdb0
test: fix flaky test-fs-stream-construct
Trott Jul 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src: replace InspectorTimer with TimerWrap utility
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #34186
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
jasnell committed Jul 5, 2020
commit e19a25182446032a6c9f0bedf4d063e305ddde0a
92 changes: 8 additions & 84 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "node_process.h"
#include "node_url.h"
#include "util-inl.h"
#include "timer_wrap.h"
#include "v8-inspector.h"
#include "v8-platform.h"

Expand Down Expand Up @@ -326,86 +327,6 @@ class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
bool retaining_context_;
};

class InspectorTimer {
public:
InspectorTimer(Environment* env,
double interval_s,
V8InspectorClient::TimerCallback callback,
void* data) : env_(env),
callback_(callback),
data_(data) {
uv_timer_init(env->event_loop(), &timer_);
int64_t interval_ms = 1000 * interval_s;
uv_timer_start(&timer_, OnTimer, interval_ms, interval_ms);
timer_.data = this;
}

InspectorTimer(const InspectorTimer&) = delete;

void Stop() {
if (timer_.data == nullptr) return;

timer_.data = nullptr;
uv_timer_stop(&timer_);
env_->CloseHandle(reinterpret_cast<uv_handle_t*>(&timer_), TimerClosedCb);
}

inline Environment* env() const { return env_; }

private:
static void OnTimer(uv_timer_t* uvtimer) {
InspectorTimer* timer = node::ContainerOf(&InspectorTimer::timer_, uvtimer);
timer->callback_(timer->data_);
}

static void TimerClosedCb(uv_handle_t* uvtimer) {
std::unique_ptr<InspectorTimer> timer(
node::ContainerOf(&InspectorTimer::timer_,
reinterpret_cast<uv_timer_t*>(uvtimer)));
// Unique_ptr goes out of scope here and pointer is deleted.
}

~InspectorTimer() = default;

Environment* env_;
uv_timer_t timer_;
V8InspectorClient::TimerCallback callback_;
void* data_;

friend std::unique_ptr<InspectorTimer>::deleter_type;
};

class InspectorTimerHandle {
public:
InspectorTimerHandle(Environment* env, double interval_s,
V8InspectorClient::TimerCallback callback, void* data) {
timer_ = new InspectorTimer(env, interval_s, callback, data);

env->AddCleanupHook(CleanupHook, this);
}

InspectorTimerHandle(const InspectorTimerHandle&) = delete;

~InspectorTimerHandle() {
Stop();
}

private:
void Stop() {
if (timer_ != nullptr) {
timer_->env()->RemoveCleanupHook(CleanupHook, this);
timer_->Stop();
}
timer_ = nullptr;
}

static void CleanupHook(void* data) {
static_cast<InspectorTimerHandle*>(data)->Stop();
}

InspectorTimer* timer_;
};

class SameThreadInspectorSession : public InspectorSession {
public:
SameThreadInspectorSession(
Expand Down Expand Up @@ -602,9 +523,12 @@ class NodeInspectorClient : public V8InspectorClient {
void startRepeatingTimer(double interval_s,
TimerCallback callback,
void* data) override {
timers_.emplace(std::piecewise_construct, std::make_tuple(data),
std::make_tuple(env_, interval_s, callback,
data));
auto result =
timers_.emplace(std::piecewise_construct, std::make_tuple(data),
std::make_tuple(env_, callback, data));
CHECK(result.second);
uint64_t interval = 1000 * interval_s;
result.first->second.Update(interval, interval);
}

void cancelTimer(void* data) override {
Expand Down Expand Up @@ -724,7 +648,7 @@ class NodeInspectorClient : public V8InspectorClient {
bool running_nested_loop_ = false;
std::unique_ptr<V8Inspector> client_;
// Note: ~ChannelImpl may access timers_ so timers_ has to come first.
std::unordered_map<void*, InspectorTimerHandle> timers_;
std::unordered_map<void*, TimerWrapHandle> timers_;
std::unordered_map<int, std::unique_ptr<ChannelImpl>> channels_;
int next_session_id_ = 1;
bool waiting_for_resume_ = false;
Expand Down