fixed some potential concurrency issues in the client side.

enhanded route_started log messages
renamed service to svc for some items
added two more fields to denote requested service address/network to ServerRoute
This commit is contained in:
2025-03-11 21:12:05 +09:00
parent befe65b486
commit 09593fd678
9 changed files with 250 additions and 126 deletions

View File

@ -1,6 +1,7 @@
package hodu
import "container/list"
import "container/ring"
import "errors"
import "sync"
@ -19,11 +20,19 @@ type Bulletin[T interface{}] struct {
sbsc_map BulletinSubscriptionMap
sbsc_mtx sync.RWMutex
closed bool
r_mtx sync.RWMutex
r *ring.Ring
r_capa int
r_full bool
}
func NewBulletin[T interface{}]() *Bulletin[T] {
func NewBulletin[T interface{}](capa int) *Bulletin[T] {
return &Bulletin[T]{
sbsc_map: make(BulletinSubscriptionMap, 0),
r: ring.New(capa),
r_capa: capa,
r_full: false,
}
}
@ -134,3 +143,30 @@ func (b *Bulletin[T]) Publish(topic string, data T) {
b.sbsc_mtx.Unlock()
}
func (b *Bulletin[T]) Enqueue(topic string, data T) {
b.r_mtx.Lock()
b.r.Value = data // update the value at the current position
b.r = b.r.Next() // move the current position
b.r_mtx.Unlock()
}
func (b *Bulletin[T]) Dequeue() {
b.r_mtx.Lock()
b.r_mtx.Unlock()
}
/*
func (b *Bulletin[T]) RunTask(wg *sync.WaitGroup) {
var done bool
var msg T
var ok bool
defer wg.Done()
for !done {
select {
case msg, ok = <- b.C:
if !ok { done = true }
}
}
}*/