-
Notifications
You must be signed in to change notification settings - Fork 114
/
init.go
108 lines (88 loc) · 2.09 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package antnet
import (
"os"
"runtime"
"sync"
"sync/atomic"
"time"
)
type Statis struct {
GoCount int
MsgqueCount int
StartTime time.Time
LastPanic int
PanicCount int32
PoolGoCount int32
}
var statis = &Statis{}
type WaitGroup struct {
count int64
}
func (r *WaitGroup) Add(delta int) {
atomic.AddInt64(&r.count, int64(delta))
}
func (r *WaitGroup) Done() {
atomic.AddInt64(&r.count, -1)
}
func (r *WaitGroup) Wait() {
for atomic.LoadInt64(&r.count) > 0 {
Sleep(1)
}
}
func (r *WaitGroup) TryWait() bool {
return atomic.LoadInt64(&r.count) == 0
}
var waitAll = &WaitGroup{} //等待所有goroutine
var waitAllForLog sync.WaitGroup
var waitAllForRedis sync.WaitGroup
var stopForLog int32 //
var stop int32 //停止标志
var gocount int32 //goroutine数量
var goid uint32
var DefLog *Log //日志
var msgqueId uint32 //消息队列id
var msgqueMapSync sync.Mutex
var msgqueMap = map[uint32]IMsgQue{}
type gMsg struct {
c chan struct{}
msg *Message
fun func(msgque IMsgQue) bool
}
var gmsgId uint16
var gmsgMapSync sync.Mutex
var gmsgArray = [65536]*gMsg{}
var atexitId uint32
var atexitMapSync sync.Mutex
var atexitMap = map[uint32]func(){}
var stopChanForGo = make(chan struct{})
var stopChanForLog = make(chan struct{})
var stopChanForSys = make(chan os.Signal, 1)
var poolChan = make(chan func())
var poolGoCount int32
var StartTick int64
var NowTick int64
var Timestamp int64 // 当前秒数
var TimeString string // 当前时间 格式:2020-7-9 14:59:15
var randIndex uint32 = 0
var Config = struct {
AutoCompressLen uint32
UdpServerGoCnt int
PoolSize int32
SSLCrtPath string
SSLKeyPath string
EnableWss bool
ReadDataBuffer int
StopTimeout int
}{UdpServerGoCnt: 64, PoolSize: 50000, ReadDataBuffer: 1 << 12, StopTimeout: 3000}
var stopCheckIndex uint64
var stopCheckMap = struct {
sync.Mutex
M map[uint64]string
}{M: map[uint64]string{}}
func init() {
gmsgArray[gmsgId] = &gMsg{c: make(chan struct{})}
runtime.GOMAXPROCS(runtime.NumCPU())
DefLog = NewLog(10000, &ConsoleLogger{true})
DefLog.SetLevel(LogLevelInfo)
timerTick()
}