timer.tcl

来自「CBRP协议(移动adhoc中基于分簇的路由协议)ns2下的源码」· TCL 代码 · 共 46 行

TCL
46
字号
## A simple timer class.  You can derive a subclass of Timer# to provide a simple mechanism for scheduling events:## 	$self sched $delay -- causes "$self timeout" to be called#				$delay seconds in the future#	$self cancel	   -- cancels any pending scheduled callback# Class Timer# sched is the same as resched; the previous setting is cancelled# and another event is scheduled. No state is kept for the timers.# This is different than the C++ timer API in timer-handler.cc,h; where a # sched aborts if the timer is already set. C++ timers maintain state # (e.g. IDLE, PENDING..etc) that is checked before the timer is scheduled.Timer instproc sched delay {	$self instvar ns	$self instvar id_	$self cancel	set id_ [$ns at [expr [$ns now] + $delay] "$self timeout"]}Timer instproc destroy {} {	$self cancel}Timer instproc cancel {} {	$self instvar ns	$self instvar id_	if [info exists id_] {		$ns cancel $id_		unset id_	}}# resched and expire are added to have a similar API to C++ timers.Timer instproc resched delay {	$self sched $delay }# the subclass must provide the timeout functionTimer instproc expire {} {	$self timeout}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?