代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。