This commit is contained in:
aozhiwei 2023-08-12 20:23:16 +08:00
parent dacdd2a5db
commit 0644461bc7
2 changed files with 36 additions and 27 deletions

View File

@ -33,19 +33,17 @@ func MkInt64(lo32 int32, hi32 int32) int64 {
return int64(lo32) + (int64(hi32) << 32) return int64(lo32) + (int64(hi32) << 32)
} }
/* func Request(r *http.Request, name string) string {
func Request(r *http.Request, name string) *XValue {
if r.Form == nil { if r.Form == nil {
r.ParseForm() r.ParseForm()
} }
if vs, ok := r.Form[name]; ok { if vs, ok := r.Form[name]; ok {
if len(vs) > 0 { if len(vs) > 0 {
return NewXString(vs[0]) return vs[0]
} }
} }
return NewXString("") return ""
} }
*/
func Response(w* http.ResponseWriter, data string) { func Response(w* http.ResponseWriter, data string) {
(*w).Write([]byte(data)) (*w).Write([]byte(data))
@ -99,14 +97,6 @@ func ForceCreateDir(dir string) bool {
return true return true
} }
func TraverseArray(arrayPtr interface{}, callback func(data interface{})) {
array := reflect.ValueOf(arrayPtr).Elem()
for i := 0; i < array.Len(); i++ {
val := array.Index(i).Addr().Interface()
callback(val)
}
}
func IsNumberType(v interface{}) bool { func IsNumberType(v interface{}) bool {
switch reflect.TypeOf(v).Kind() { switch reflect.TypeOf(v).Kind() {
case case

View File

@ -38,16 +38,26 @@ func (this *XTimer) Init(
context interface{}, context interface{},
gcTime int32, gcTime int32,
cacheTimerNum int32) { cacheTimerNum int32) {
initListHeadFunc := func (data interface{}) { initListHeadFunc := func (head *ListHead) {
head := data.(*ListHead)
head.Init(nil) head.Init(nil)
} }
initListHeadFunc(&this.freeTimerList) initListHeadFunc(&this.freeTimerList)
TraverseArray(&this.tv1, initListHeadFunc) for i := 0; i < len(this.tv1); i++ {
TraverseArray(&this.tv2, initListHeadFunc) initListHeadFunc(&this.tv1[i])
TraverseArray(&this.tv3, initListHeadFunc) }
TraverseArray(&this.tv4, initListHeadFunc) for i := 0; i < len(this.tv2); i++ {
TraverseArray(&this.tv5, initListHeadFunc) initListHeadFunc(&this.tv2[i])
}
for i := 0; i < len(this.tv3); i++ {
initListHeadFunc(&this.tv3[i])
}
for i := 0; i < len(this.tv4); i++ {
initListHeadFunc(&this.tv4[i])
}
for i := 0; i < len(this.tv5); i++ {
initListHeadFunc(&this.tv5[i])
}
this.timerTick = getTickCount(context) this.timerTick = getTickCount(context)
this.context = context this.context = context
this.getTickCount = getTickCount this.getTickCount = getTickCount
@ -60,8 +70,7 @@ func (this *XTimer) UnInit() {
} }
func (this *XTimer) clear() { func (this *XTimer) clear() {
freeTimerFunc := func (data interface{}) { freeTimerFunc := func (head *ListHead) {
head := data.(*ListHead)
for !head.Empty() { for !head.Empty() {
timerList := head.FirstEntry().(*XTimerList) timerList := head.FirstEntry().(*XTimerList)
this.detachTimer(timerList) this.detachTimer(timerList)
@ -71,11 +80,21 @@ func (this *XTimer) clear() {
} }
} }
freeTimerFunc(&this.freeTimerList) freeTimerFunc(&this.freeTimerList)
TraverseArray(&this.tv1, freeTimerFunc) for i := 0; i < len(this.tv1); i++ {
TraverseArray(&this.tv2, freeTimerFunc) freeTimerFunc(&this.tv1[i])
TraverseArray(&this.tv3, freeTimerFunc) }
TraverseArray(&this.tv4, freeTimerFunc) for i := 0; i < len(this.tv2); i++ {
TraverseArray(&this.tv5, freeTimerFunc) freeTimerFunc(&this.tv2[i])
}
for i := 0; i < len(this.tv3); i++ {
freeTimerFunc(&this.tv3[i])
}
for i := 0; i < len(this.tv4); i++ {
freeTimerFunc(&this.tv4[i])
}
for i := 0; i < len(this.tv5); i++ {
freeTimerFunc(&this.tv5[i])
}
} }
func (this *XTimer) Update() { func (this *XTimer) Update() {