We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
对于skynet 定时器的 timer_update ,一直疑惑为什么要调用两次 timer_execute,主要是为什么还要在 timer_shift(T); 前调用一次。
timer_update
timer_execute
timer_shift(T);
我个人理解,timer_update 应该只需要每隔 10ms tick 一次,然后派发tick后的定时器消息即可, 类似下面的执行过程:
static void timer_update(struct timer *T) { SPIN_LOCK(T); // shift time first, and then dispatch timer message timer_shift(T); // timer_execute int idx = T->time & TIME_NEAR_MASK; while (T->near[idx].head.next) { struct timer_node *current = link_clear(&T->near[idx]); SPIN_UNLOCK(T); // dispatch_list don't need lock T dispatch_list(current); } }
例如,T->time 从 1 tick 到 2,这个过程中,如果在 T->time == 1 时又加入一个 timeout 0 的消息 A,根据 skynet_timeout 的逻辑,这个消息 A 会直接被 skynet_context_push 所消费掉,并不会插入到定时器中,那么在 10 ms 后,timer_update 的执行过程中,就不需要在 timer_shift 之前再调用一次 timer_execute,因为 near[1] 已经在上一轮被处理过了。
skynet_timeout
skynet_context_push
timer_shift
而我的疑惑是:为啥在 timer_shift(T); 前要多调用一次 timer_execute(T);,这样做的意图是什么呢? 希望有大佬能解惑一下,非常感谢。
timer_execute(T);
The text was updated successfully, but these errors were encountered:
timeout 0 的消息怎么处理,并没有对 timer 这个模块做出什么承诺。
Sorry, something went wrong.
也就是说,是为了timer的模块化,timer本身是需要提供处理timeout 0的能力。
那可以这样认为吗,如果我这个timer就是只在skynet内使用,而skynet已经提供了处理timeout 0的逻辑,那么第一个timer_execute 其实也可以不需要的。我这样理解对吗?
timer 的用户都在这个文件,skynet_timeout检查time的合法性,等价于timer的承诺。建议把timer_execute重复执行去掉。
No branches or pull requests
对于skynet 定时器的
timer_update
,一直疑惑为什么要调用两次timer_execute
,主要是为什么还要在timer_shift(T);
前调用一次。我个人理解,timer_update 应该只需要每隔 10ms tick 一次,然后派发tick后的定时器消息即可,
类似下面的执行过程:
例如,T->time 从 1 tick 到 2,这个过程中,如果在 T->time == 1 时又加入一个 timeout 0 的消息 A,根据
skynet_timeout
的逻辑,这个消息 A 会直接被skynet_context_push
所消费掉,并不会插入到定时器中,那么在 10 ms 后,timer_update
的执行过程中,就不需要在timer_shift
之前再调用一次timer_execute
,因为 near[1] 已经在上一轮被处理过了。而我的疑惑是:为啥在
timer_shift(T);
前要多调用一次timer_execute(T);
,这样做的意图是什么呢?希望有大佬能解惑一下,非常感谢。
The text was updated successfully, but these errors were encountered: