]> 127.0.0.1 Git - part/.git/commitdiff
96
authorqydysky <qydysky@foxmail.com>
Thu, 24 Dec 2020 15:14:55 +0000 (23:14 +0800)
committerqydysky <qydysky@foxmail.com>
Thu, 24 Dec 2020 15:14:55 +0000 (23:14 +0800)
msgq/Msgq.go

index f39849eb538ca25ed6564b1efaf79d9e67e8748f..07e873ee0ad4176a46757d71d5d2d859ff6331cd 100644 (file)
@@ -14,23 +14,23 @@ type Msgq struct {
        sync.RWMutex
 }
 
-type msgq_item struct {
+type Msgq_item struct {
        data interface{}
        sig uint64
 }
 
-func New(want_max_data_mun int) (*msgq) {
-       m := new(msgq)
+func New(want_max_data_mun int) (*Msgq) {
+       m := new(Msgq)
        (*m).wait_push = make(chan bool,100)
        (*m).data_list = list.New()
        (*m).max_data_mun = want_max_data_mun
        return m
 }
 
-func (m *msgq) Push(msg interface{}) {
+func (m *Msgq) Push(msg interface{}) {
        m.Lock()
        defer m.Unlock()
-       m.data_list.PushBack(msgq_item{
+       m.data_list.PushBack(Msgq_item{
                data:msg,
                sig:m.get_sig(),
        })
@@ -42,7 +42,7 @@ func (m *msgq) Push(msg interface{}) {
        }
 }
 
-func (m *msgq) Pull(old_sig uint64) (data interface{},sig uint64) {
+func (m *Msgq) Pull(old_sig uint64) (data interface{},sig uint64) {
        for old_sig == m.Sig() {
                select {
                case <- m.wait_push:
@@ -53,42 +53,42 @@ func (m *msgq) Pull(old_sig uint64) (data interface{},sig uint64) {
        defer m.RUnlock()
 
        for el := m.data_list.Front();el != nil;el = el.Next() {
-               if old_sig < el.Value.(msgq_item).sig {
-                       data = el.Value.(msgq_item).data
-                       sig = el.Value.(msgq_item).sig
+               if old_sig < el.Value.(Msgq_item).sig {
+                       data = el.Value.(Msgq_item).data
+                       sig = el.Value.(Msgq_item).sig
                        break
                }
        }
        return
 }
 
-func (m *msgq) Sig() (sig uint64) {
+func (m *Msgq) Sig() (sig uint64) {
        if el := m.data_list.Back();el == nil {
                sig = 0
        } else {
-               sig = el.Value.(msgq_item).sig
+               sig = el.Value.(Msgq_item).sig
        }
        return
 }
 
-func (m *msgq) get_sig() (sig uint64) {
+func (m *Msgq) get_sig() (sig uint64) {
        m.sig += 1
        return m.sig
 }
 
-type msgq_tag_data struct {
+type Msgq_tag_data struct {
        Tag string
        Data interface{}
 }
 
-func (m *msgq) Push_tag(Tag string,Data interface{}) {
-       m.Push(msgq_tag_data{
+func (m *Msgq) Push_tag(Tag string,Data interface{}) {
+       m.Push(Msgq_tag_data{
                Tag:Tag,
                Data:Data,
        })
 }
 
-func (m *msgq) Pull_tag(func_map map[string]func(interface{})(bool)) {
+func (m *Msgq) Pull_tag(func_map map[string]func(interface{})(bool)) {
        go func(){
                var (
                        sig = m.Sig()
@@ -96,7 +96,7 @@ func (m *msgq) Pull_tag(func_map map[string]func(interface{})(bool)) {
                )
                for {
                        data,sig = m.Pull(sig)
-                       if d,ok := data.(msgq_tag_data);!ok {
+                       if d,ok := data.(Msgq_tag_data);!ok {
                                continue
                        } else {
                                if f,ok := func_map[d.Tag];ok{