Add Timeout::get_timeout.
This commit is contained in:
parent
99375ff157
commit
5349e63c2b
@ -35,6 +35,9 @@ class Timeout final : public Actor {
|
||||
bool has_timeout() const {
|
||||
return Actor::has_timeout();
|
||||
}
|
||||
double get_timeout() const {
|
||||
return Actor::get_timeout();
|
||||
}
|
||||
void set_timeout_in(double timeout) {
|
||||
Actor::set_timeout_in(timeout);
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ class Actor : public ObserverBase {
|
||||
void stop();
|
||||
void do_stop();
|
||||
bool has_timeout() const;
|
||||
double get_timeout() const;
|
||||
void set_timeout_in(double timeout_in);
|
||||
void set_timeout_at(double timeout_at);
|
||||
void cancel_timeout();
|
||||
|
@ -54,6 +54,9 @@ inline void Actor::do_stop() {
|
||||
inline bool Actor::has_timeout() const {
|
||||
return Scheduler::instance()->has_actor_timeout(this);
|
||||
}
|
||||
inline double Actor::get_timeout() const {
|
||||
return Scheduler::instance()->get_actor_timeout(this);
|
||||
}
|
||||
inline void Actor::set_timeout_in(double timeout_in) {
|
||||
Scheduler::instance()->set_actor_timeout_in(this, timeout_in);
|
||||
}
|
||||
|
@ -126,6 +126,7 @@ class Scheduler {
|
||||
void finish_migrate_actor(Actor *actor);
|
||||
|
||||
bool has_actor_timeout(const Actor *actor) const;
|
||||
double get_actor_timeout(const Actor *actor) const;
|
||||
void set_actor_timeout_in(Actor *actor, double timeout);
|
||||
void set_actor_timeout_at(Actor *actor, double timeout_at);
|
||||
void cancel_actor_timeout(Actor *actor);
|
||||
@ -176,6 +177,7 @@ class Scheduler {
|
||||
void start_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id);
|
||||
|
||||
bool has_actor_timeout(const ActorInfo *actor_info) const;
|
||||
double get_actor_timeout(const ActorInfo *actor_info) const;
|
||||
void set_actor_timeout_in(ActorInfo *actor_info, double timeout);
|
||||
void set_actor_timeout_at(ActorInfo *actor_info, double timeout_at);
|
||||
void cancel_actor_timeout(ActorInfo *actor_info);
|
||||
|
@ -392,6 +392,7 @@ void Scheduler::do_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id) {
|
||||
void Scheduler::start_migrate_actor(Actor *actor, int32 dest_sched_id) {
|
||||
start_migrate_actor(actor->get_info(), dest_sched_id);
|
||||
}
|
||||
|
||||
void Scheduler::start_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id) {
|
||||
VLOG(actor) << "Start migrate actor: " << tag("name", actor_info) << tag("ptr", actor_info)
|
||||
<< tag("actor_count", actor_count_);
|
||||
@ -406,6 +407,11 @@ void Scheduler::start_migrate_actor(ActorInfo *actor_info, int32 dest_sched_id)
|
||||
cancel_actor_timeout(actor_info);
|
||||
}
|
||||
|
||||
double Scheduler::get_actor_timeout(const ActorInfo *actor_info) const {
|
||||
const HeapNode *heap_node = actor_info->get_heap_node();
|
||||
return heap_node->in_heap() ? timeout_queue_.get_key(heap_node) - Time::now() : 0.0;
|
||||
}
|
||||
|
||||
void Scheduler::set_actor_timeout_in(ActorInfo *actor_info, double timeout) {
|
||||
if (timeout > 1e10) {
|
||||
timeout = 1e10;
|
||||
|
@ -302,6 +302,9 @@ inline void Scheduler::finish_migrate_actor(Actor *actor) {
|
||||
inline bool Scheduler::has_actor_timeout(const Actor *actor) const {
|
||||
return has_actor_timeout(actor->get_info());
|
||||
}
|
||||
inline double Scheduler::get_actor_timeout(const Actor *actor) const {
|
||||
return get_actor_timeout(actor->get_info());
|
||||
}
|
||||
inline void Scheduler::set_actor_timeout_in(Actor *actor, double timeout) {
|
||||
set_actor_timeout_in(actor->get_info(), timeout);
|
||||
}
|
||||
|
@ -37,6 +37,12 @@ class KHeap {
|
||||
return array_[0].key_;
|
||||
}
|
||||
|
||||
KeyT get_key(const HeapNode *node) const {
|
||||
size_t pos = static_cast<size_t>(node->pos_);
|
||||
CHECK(pos < array_.size());
|
||||
return array_[pos].key_;
|
||||
}
|
||||
|
||||
const HeapNode *top() const {
|
||||
return array_[0].node_;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user