1
This commit is contained in:
parent
2b5498f808
commit
2660a713e4
21
app.go
21
app.go
@ -58,7 +58,8 @@ func (this *app) init(userApp UserApp) {
|
||||
this.userApp = userApp
|
||||
this.nowTime = time.Now()
|
||||
atomic.StoreInt64(&this.nowUnixNano, this.nowTime.UnixNano())
|
||||
_Timer = &q5.XTimer{}
|
||||
_Timer = &Timer{}
|
||||
/*
|
||||
_Timer.Init(
|
||||
func (context interface{}) int64 {
|
||||
return q5.GetTickCount()
|
||||
@ -66,13 +67,19 @@ func (this *app) init(userApp UserApp) {
|
||||
nil,
|
||||
1000 * 60,
|
||||
5000)
|
||||
*/
|
||||
_SysLog = new(SysLog_)
|
||||
_SysLog.Init()
|
||||
_TgLog = new(TGLog_)
|
||||
_TgLog.Init()
|
||||
//flag.IntVar(&this.nodeId, "n", 0, "node id")
|
||||
//flag.IntVar(&this.instanceId, "i", 0, "instance id")
|
||||
flag.Parse()
|
||||
{
|
||||
var tmpNodeId, tmpInstanceId int
|
||||
flag.IntVar(&tmpNodeId, "n", 0, "node id")
|
||||
flag.IntVar(&tmpInstanceId, "i", 0, "instance id")
|
||||
this.nodeId = int32(tmpNodeId)
|
||||
this.instanceId = int32(tmpInstanceId)
|
||||
flag.Parse()
|
||||
}
|
||||
this.loopCond = sync.NewCond(new(sync.Mutex))
|
||||
this.chGoLoopTimerExit = make(chan int)
|
||||
this.chGoLoopWait = make(chan int64)
|
||||
@ -88,7 +95,7 @@ func (this *app) init(userApp UserApp) {
|
||||
|
||||
func (this *app) unInit() {
|
||||
this.chGoLoopTimerExit <- 1
|
||||
_Timer.UnInit()
|
||||
//_Timer.UnInit()
|
||||
_Timer = nil
|
||||
this.userApp.UnInit()
|
||||
}
|
||||
@ -180,7 +187,7 @@ func (this *app) goLoopTimer() {
|
||||
}
|
||||
|
||||
func (this *app) schedule() {
|
||||
this.chGoLoopWait <- Timer().GetIdleTime()
|
||||
this.chGoLoopWait <- GetTimer().GetIdleTime()
|
||||
this.loopCond.L.Lock()
|
||||
this.loopCond.Wait()
|
||||
this.loopCond.L.Unlock()
|
||||
@ -222,7 +229,7 @@ func (this *app) dispatchIMMsg() {
|
||||
}
|
||||
|
||||
func (this *app) installTimer() {
|
||||
Timer().SetInterval(1000 * 60,
|
||||
GetTimer().SetInterval(1000 * 60,
|
||||
func (ev int32, params *q5.Args) {
|
||||
if ev == q5.TIMER_EXEC_EVENT {
|
||||
SysLog().Info("max_run_delay:%d max_schedule_time:%d",
|
||||
|
@ -1,13 +1,11 @@
|
||||
package f5
|
||||
|
||||
import "q5"
|
||||
|
||||
var _app *app
|
||||
var _Timer *q5.XTimer
|
||||
var _Timer *Timer
|
||||
var _SysLog *SysLog_
|
||||
var _TgLog *TGLog_
|
||||
|
||||
func Timer() *q5.XTimer {
|
||||
func GetTimer() *Timer {
|
||||
return _Timer
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ func (this *HttpServer) Init(serviceName string, logOutputTime int32) *HttpServe
|
||||
})
|
||||
SysLog().Info("HttpServer.Init")
|
||||
if logOutputTime > 0 {
|
||||
Timer().SetInterval(
|
||||
GetTimer().SetInterval(
|
||||
logOutputTime,
|
||||
func (ev int32, params *q5.Args) {
|
||||
if ev == q5.TIMER_EXEC_EVENT {
|
||||
|
65
timer.go
Normal file
65
timer.go
Normal file
@ -0,0 +1,65 @@
|
||||
package f5
|
||||
|
||||
import (
|
||||
"q5"
|
||||
)
|
||||
|
||||
type TimerWp struct {
|
||||
*q5.XTimerWp
|
||||
}
|
||||
|
||||
type TimerAttacher struct {
|
||||
q5.XTimerAttacher
|
||||
}
|
||||
|
||||
type Timer struct {
|
||||
timer *q5.XTimer
|
||||
}
|
||||
|
||||
func (this *Timer) Update() {
|
||||
this.timer.Update()
|
||||
}
|
||||
|
||||
func (this *Timer) SetTimeout(expireTime int32, cb q5.TimerCb) {
|
||||
this.timer.SetTimeout(expireTime, cb)
|
||||
}
|
||||
|
||||
func (this *Timer) SetTimeoutEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) {
|
||||
this.timer.SetTimeoutEx(expireTime, cb, &ac.XTimerAttacher)
|
||||
}
|
||||
|
||||
func (this *Timer) SetTimeoutWp(expireTime int32, cb q5.TimerCb) *TimerWp {
|
||||
wp := TimerWp{}
|
||||
wp.XTimerWp = this.timer.SetTimeoutWp(expireTime, cb)
|
||||
return &wp
|
||||
}
|
||||
|
||||
func (this *Timer) SetTimeoutExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp {
|
||||
wp := TimerWp{}
|
||||
wp.XTimerWp = this.timer.SetTimeoutExWp(expireTime, cb, &ac.XTimerAttacher)
|
||||
return &wp
|
||||
}
|
||||
|
||||
func (this *Timer) SetInterval(expireTime int32, cb q5.TimerCb) {
|
||||
this.timer.SetInterval(expireTime, cb)
|
||||
}
|
||||
|
||||
func (this *Timer) SetIntervalEx(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) {
|
||||
this.timer.SetIntervalEx(expireTime, cb, &ac.XTimerAttacher)
|
||||
}
|
||||
|
||||
func (this *Timer) SetIntervalWp(expireTime int32, cb q5.TimerCb) *TimerWp {
|
||||
wp := TimerWp{}
|
||||
wp.XTimerWp = this.timer.SetIntervalWp(expireTime, cb)
|
||||
return &wp
|
||||
}
|
||||
|
||||
func (this *Timer) SetIntervalExWp(expireTime int32, cb q5.TimerCb, ac *TimerAttacher) *TimerWp {
|
||||
wp := TimerWp{}
|
||||
wp.XTimerWp = this.timer.SetIntervalExWp(expireTime, cb, &ac.XTimerAttacher)
|
||||
return &wp
|
||||
}
|
||||
|
||||
func (this *Timer) GetIdleTime() int64 {
|
||||
return this.GetIdleTime()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user