guarded ext_svs with ext_mtx in client.go and server.go
This commit is contained in:
parent
b792997184
commit
74fb40d44f
@ -41,6 +41,7 @@ type Client struct {
|
|||||||
tlscfg *tls.Config
|
tlscfg *tls.Config
|
||||||
api_prefix string
|
api_prefix string
|
||||||
|
|
||||||
|
ext_mtx sync.Mutex
|
||||||
ext_svcs []Service
|
ext_svcs []Service
|
||||||
ctl *http.Server // control server
|
ctl *http.Server // control server
|
||||||
|
|
||||||
@ -1011,7 +1012,9 @@ func (c *Client) StartService(data interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) StartExtService(svc Service, data interface{}) {
|
func (c *Client) StartExtService(svc Service, data interface{}) {
|
||||||
|
c.ext_mtx.Lock()
|
||||||
c.ext_svcs = append(c.ext_svcs, svc)
|
c.ext_svcs = append(c.ext_svcs, svc)
|
||||||
|
c.ext_mtx.Unlock()
|
||||||
c.wg.Add(1)
|
c.wg.Add(1)
|
||||||
go svc.RunTask(&c.wg)
|
go svc.RunTask(&c.wg)
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ type Server struct {
|
|||||||
tlscfg *tls.Config
|
tlscfg *tls.Config
|
||||||
|
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
ext_mtx sync.Mutex
|
||||||
ext_svcs []Service
|
ext_svcs []Service
|
||||||
stop_req atomic.Bool
|
stop_req atomic.Bool
|
||||||
stop_chan chan bool
|
stop_chan chan bool
|
||||||
@ -913,7 +914,9 @@ func (s *Server) StartService(cfg interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) StartExtService(svc Service, data interface{}) {
|
func (s *Server) StartExtService(svc Service, data interface{}) {
|
||||||
|
s.ext_mtx.Lock()
|
||||||
s.ext_svcs = append(s.ext_svcs, svc)
|
s.ext_svcs = append(s.ext_svcs, svc)
|
||||||
|
s.ext_mtx.Unlock()
|
||||||
s.wg.Add(1)
|
s.wg.Add(1)
|
||||||
go svc.RunTask(&s.wg)
|
go svc.RunTask(&s.wg)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user