Merge pull request #486 from Barenboim/master

add a new timer factory function to support longer time.
This commit is contained in:
xiehan
2021-07-26 16:10:42 +08:00
committed by GitHub
4 changed files with 26 additions and 11 deletions

View File

@@ -1487,7 +1487,8 @@ SubTask *WFKafkaTask::done()
{
if (this->state == WFT_STATE_TASK_ERROR)
{
WFTimerTask *timer = WFTaskFactory::create_timer_task(0, std::move(cb));
WFTimerTask *timer;
timer = WFTaskFactory::create_timer_task(0, 0, std::move(cb));
timer->user_data = this;
series->push_front(timer);
}

View File

@@ -30,30 +30,31 @@ class __WFTimerTask : public WFTimerTask
protected:
virtual int duration(struct timespec *value)
{
*value = this->value;
value->tv_sec = this->seconds;
value->tv_nsec = this->nanoseconds;
return 0;
}
protected:
struct timespec value;
time_t seconds;
long nanoseconds;
public:
__WFTimerTask(const struct timespec *value, CommScheduler *scheduler,
__WFTimerTask(time_t seconds, long nanoseconds, CommScheduler *scheduler,
timer_callback_t&& cb) :
WFTimerTask(scheduler, std::move(cb))
{
this->value = *value;
this->seconds = seconds;
this->nanoseconds = nanoseconds;
}
};
WFTimerTask *WFTaskFactory::create_timer_task(unsigned int microseconds,
timer_callback_t callback)
{
struct timespec value = {
.tv_sec = (time_t)(microseconds / 1000000),
.tv_nsec = (long)(microseconds % 1000000 * 1000)
};
return new __WFTimerTask(&value, WFGlobal::get_scheduler(),
return new __WFTimerTask((time_t)(microseconds / 1000000),
(long)(microseconds % 1000000 * 1000),
WFGlobal::get_scheduler(),
std::move(callback));
}
@@ -64,6 +65,13 @@ WFTimerTask *WFTaskFactory::create_timer_task(const std::string& name,
return WFTaskFactory::create_timer_task(microseconds, std::move(callback));
}
WFTimerTask *WFTaskFactory::create_timer_task(time_t seconds, long nanoseconds,
timer_callback_t callback)
{
return new __WFTimerTask(seconds, nanoseconds, WFGlobal::get_scheduler(),
std::move(callback));
}
class __WFCounterTask;
struct __counter_node

View File

@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <time.h>
#include <utility>
#include <functional>
#include "URIParser.h"
@@ -195,6 +196,9 @@ public:
unsigned int microseconds,
timer_callback_t callback);
static WFTimerTask *create_timer_task(time_t seconds, long nanoseconds,
timer_callback_t callback);
/* Counter is like semaphore. The callback of counter is called when
* 'count' operations reach target_value & after the task is started.
* It's perfectly legal to call 'count' before the task is started. */

View File

@@ -473,7 +473,9 @@ SubTask *WFComplexClientTask<REQ, RESP, CTX>::done()
auto&& cb = std::bind(&WFComplexClientTask::switch_callback,
this,
std::placeholders::_1);
WFTimerTask *timer = WFTaskFactory::create_timer_task(0, std::move(cb));
WFTimerTask *timer;
timer = WFTaskFactory::create_timer_task(0, 0, std::move(cb));
series->push_front(timer);
}
else