This commit is contained in:
zhouyuyan
2017-08-23 21:10:38 +08:00
parent 922a10fd66
commit e73776d670
6 changed files with 101 additions and 56 deletions

View File

@@ -5,9 +5,13 @@ import "sync"
type Message struct {
client *client
msg []byte
pool *MessagePool
// pool *MessagePool
}
var (
MSGPool []MessagePool
)
type MessagePool struct {
l sync.Mutex
maxuser int
@@ -15,14 +19,17 @@ type MessagePool struct {
queue chan *Message
}
func init() []MessagePool {
MSGPool = make([]MessagePool, (MessagePoolNum + 2))
for i := 0; i < (MessagePoolNum + 2); i++ {
MSGPool[i].Init(MessagePoolUser, MessagePoolMessageNum)
}
return MSGPool
}
func (p *MessagePool) Init(num int, maxusernum int) {
p.maxuser = maxusernum
p.queue = make(chan *Message, num)
for k := 0; k < num; k++ {
m := &Message{}
m.Pool = p
p.Push(m)
}
}
func (p *MessagePool) GetPool() *MessagePool {