mirror of
https://github.com/sogou/workflow.git
synced 2026-10-22 15:16:20 +08:00
fix named counter dismiss bug
This commit is contained in:
@@ -79,6 +79,7 @@ public:
|
||||
|
||||
void count_n(const std::string& name, unsigned int n);
|
||||
void count(struct __CounterList *counters, struct __counter_node *node);
|
||||
void remove(struct __CounterList *counters, struct __counter_node *node);
|
||||
|
||||
virtual ~__CounterMap();
|
||||
|
||||
@@ -107,6 +108,12 @@ public:
|
||||
counters_->push_back(&node_);
|
||||
}
|
||||
|
||||
virtual ~__WFCounterTask()
|
||||
{
|
||||
if (this->value != 0)
|
||||
__CounterMap::get_instance()->remove(counters_, &node_);
|
||||
}
|
||||
|
||||
virtual void count()
|
||||
{
|
||||
__CounterMap::get_instance()->count(counters_, &node_);
|
||||
@@ -262,6 +269,20 @@ void __CounterMap::count(struct __CounterList *counters,
|
||||
task->WFCounterTask::count();
|
||||
}
|
||||
|
||||
void __CounterMap::remove(struct __CounterList *counters,
|
||||
struct __counter_node *node)
|
||||
{
|
||||
mutex_.lock();
|
||||
counters->del(node);
|
||||
if (counters->empty())
|
||||
{
|
||||
rb_erase(&counters->rb, &counters_map_);
|
||||
delete counters;
|
||||
}
|
||||
|
||||
mutex_.unlock();
|
||||
}
|
||||
|
||||
WFCounterTask *WFTaskFactory::create_counter_task(const std::string& counter_name,
|
||||
unsigned int target_value,
|
||||
counter_callback_t callback)
|
||||
|
||||
Reference in New Issue
Block a user