1 Star 3 Fork 0

尖斌卡 / go-rabbitmq-pool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
RabbitQueue.go 883 Bytes
一键复制 编辑 原始数据 按行查看 历史
天蝎儿 提交于 2021-10-22 11:55 . edit
package kelleyRabbimqPool
import (
"sync"
"sync/atomic"
)
/**
rabbitMq 通用队列
*/
type Node struct {
data *rChannel
next *Node
}
type ChannelQueue struct {
head *Node
end *Node
l int32
rlock sync.Mutex
}
func NewChannelQueue() *ChannelQueue {
q := &ChannelQueue{head: nil, end: nil, l: 0}
return q
}
func (q *ChannelQueue) Add(data *rChannel) {
q.rlock.Lock()
defer q.rlock.Unlock()
n := &Node{data: data, next: nil}
atomic.AddInt32(&q.l, 1)
if q.end == nil {
q.head = n
q.end = n
} else {
q.end.next = n
q.end = n
}
return
}
func (q *ChannelQueue) Pop() (*rChannel, bool) {
q.rlock.Lock()
defer q.rlock.Unlock()
if q.head == nil {
return nil, false
}
atomic.AddInt32(&q.l, -1)
data := q.head.data
q.head = q.head.next
if q.head == nil {
q.end = nil
}
return data, true
}
func (q *ChannelQueue)Count() int32 {
return q.l
}
Go
1
https://gitee.com/aohanhongzhi/go-rabbitmq-pool.git
git@gitee.com:aohanhongzhi/go-rabbitmq-pool.git
aohanhongzhi
go-rabbitmq-pool
go-rabbitmq-pool
dev

搜索帮助

53164aa7 5694891 3bd8fe86 5694891