feat update
This commit is contained in:
parent
03a62901f2
commit
e08d8b7984
@ -4,12 +4,13 @@
|
||||
* @license : MIT
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
#ifndef SLED_TASK_QUEUE_PENDING_TASK_SAFETY_FLAG_H
|
||||
#define SLED_TASK_QUEUE_PENDING_TASK_SAFETY_FLAG_H
|
||||
|
||||
#pragma once
|
||||
#include "sled/ref_counted_base.h"
|
||||
#include "sled/scoped_refptr.h"
|
||||
#include "sled/synchronization/sequence_checker.h"
|
||||
#include <functional>
|
||||
|
||||
namespace sled {
|
||||
@ -31,6 +32,7 @@ protected:
|
||||
private:
|
||||
static sled::scoped_refptr<PendingTaskSafetyFlag> CreateInternal(bool alive);
|
||||
bool alive_ = true;
|
||||
SequenceChecker main_sequence_;
|
||||
};
|
||||
|
||||
class ScopedTaskSafety final {
|
||||
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
#include "sled/scoped_refptr.h"
|
||||
#ifndef SLED_TIMER_QUEUE_TIMEOUT_H
|
||||
#define SLED_TIMER_QUEUE_TIMEOUT_H
|
||||
#pragma once
|
||||
|
||||
#include "sled/scoped_refptr.h"
|
||||
#include "sled/synchronization/sequence_checker.h"
|
||||
#include "sled/task_queue/pending_task_safety_flag.h"
|
||||
#include "sled/task_queue/task_queue_base.h"
|
||||
#include "sled/timer/timeout.h"
|
||||
@ -45,6 +46,7 @@ private:
|
||||
scoped_refptr<PendingTaskSafetyFlag> safety_flag_;
|
||||
};
|
||||
|
||||
sled::SequenceChecker thread_checker_;
|
||||
sled::TaskQueueBase &task_queue_;
|
||||
const std::function<TimeMs()> get_time_;
|
||||
const std::function<void(TimeoutID)> on_expired_;
|
||||
|
@ -18,30 +18,37 @@ PendingTaskSafetyFlag::Create()
|
||||
sled::scoped_refptr<PendingTaskSafetyFlag>
|
||||
PendingTaskSafetyFlag::CreateDetached()
|
||||
{
|
||||
return CreateInternal(true);
|
||||
scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(true);
|
||||
safety_flag->main_sequence_.Detach();
|
||||
return safety_flag;
|
||||
}
|
||||
|
||||
sled::scoped_refptr<PendingTaskSafetyFlag>
|
||||
PendingTaskSafetyFlag::CreateDetachedInactive()
|
||||
{
|
||||
return CreateInternal(false);
|
||||
scoped_refptr<PendingTaskSafetyFlag> safety_flag = CreateInternal(false);
|
||||
safety_flag->main_sequence_.Detach();
|
||||
return safety_flag;
|
||||
}
|
||||
|
||||
void
|
||||
PendingTaskSafetyFlag::SetNotAlive()
|
||||
{
|
||||
SLED_DCHECK_RUN_ON(&main_sequence_);
|
||||
alive_ = false;
|
||||
}
|
||||
|
||||
void
|
||||
PendingTaskSafetyFlag::SetAlive()
|
||||
{
|
||||
SLED_DCHECK_RUN_ON(&main_sequence_);
|
||||
alive_ = true;
|
||||
}
|
||||
|
||||
bool
|
||||
PendingTaskSafetyFlag::alive() const
|
||||
{
|
||||
SLED_DCHECK_RUN_ON(&main_sequence_);
|
||||
return alive_;
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,16 @@ TaskQueueTimeoutFactory::TaskQueueTimeout::TaskQueueTimeout(TaskQueueTimeoutFact
|
||||
safety_flag_(PendingTaskSafetyFlag::Create())
|
||||
{}
|
||||
|
||||
TaskQueueTimeoutFactory::TaskQueueTimeout::~TaskQueueTimeout() { safety_flag_->SetNotAlive(); }
|
||||
TaskQueueTimeoutFactory::TaskQueueTimeout::~TaskQueueTimeout()
|
||||
{
|
||||
SLED_DCHECK_RUN_ON(&parent_.thread_checker_);
|
||||
safety_flag_->SetNotAlive();
|
||||
}
|
||||
|
||||
void
|
||||
TaskQueueTimeoutFactory::TaskQueueTimeout::Start(DurationMs duration_ms, TimeoutID timeout_id)
|
||||
{
|
||||
SLED_DCHECK_RUN_ON(&parent_.thread_checker_);
|
||||
ASSERT(timeout_expiration_ == std::numeric_limits<TimeMs>::max(), "");
|
||||
timeout_expiration_ = parent_.get_time_() + duration_ms;
|
||||
timeout_id_ = timeout_id;
|
||||
@ -36,10 +41,9 @@ TaskQueueTimeoutFactory::TaskQueueTimeout::Start(DurationMs duration_ms, Timeout
|
||||
precision_,
|
||||
SafeTask(safety_flag_,
|
||||
[timeout_id, this]() {
|
||||
// if (timeout_id != this->timeout_id_) { return; }
|
||||
LOGV("timer", "Timeout expired: {}", timeout_id);
|
||||
// FIXME: this is a bug, the posted_task_expiration_ should be reset to max
|
||||
ASSERT(posted_task_expiration_ != std::numeric_limits<TimeMs>::max(), "");
|
||||
SLED_DCHECK_RUN_ON(&parent_.thread_checker_);
|
||||
DCHECK(posted_task_expiration_ != std::numeric_limits<TimeMs>::max(), "");
|
||||
posted_task_expiration_ = std::numeric_limits<TimeMs>::max();
|
||||
|
||||
if (timeout_expiration_ == std::numeric_limits<TimeMs>::max()) {
|
||||
@ -67,6 +71,8 @@ TaskQueueTimeoutFactory::TaskQueueTimeout::Start(DurationMs duration_ms, Timeout
|
||||
void
|
||||
TaskQueueTimeoutFactory::TaskQueueTimeout::Stop()
|
||||
{
|
||||
|
||||
SLED_DCHECK_RUN_ON(&parent_.thread_checker_);
|
||||
timeout_expiration_ = std::numeric_limits<TimeMs>::max();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user