mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Make RegisterNotificationListener() thread safe
This commit is contained in:
parent
a33054b0b7
commit
3623b41a2e
1 changed files with 5 additions and 0 deletions
5
ha/ha.go
5
ha/ha.go
|
|
@ -8,6 +8,7 @@ import (
|
|||
"git.icinga.com/icingadb/icingadb-main/supervisor"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -22,12 +23,14 @@ type HA struct {
|
|||
uid uuid.UUID
|
||||
super *supervisor.Supervisor
|
||||
notificationListeners []chan int
|
||||
notificationListenersMutex sync.Mutex
|
||||
}
|
||||
|
||||
func NewHA(super *supervisor.Supervisor) (*HA, error) {
|
||||
var err error
|
||||
ho := HA{
|
||||
super: super,
|
||||
notificationListenersMutex: sync.Mutex{},
|
||||
}
|
||||
|
||||
if ho.uid, err = uuid.NewRandom(); err != nil {
|
||||
|
|
@ -190,7 +193,9 @@ func (h *HA) Run(chEnv chan *Environment) {
|
|||
|
||||
func (h *HA) RegisterNotificationListener() chan int {
|
||||
ch := make(chan int)
|
||||
h.notificationListenersMutex.Lock()
|
||||
h.notificationListeners = append(h.notificationListeners, ch)
|
||||
h.notificationListenersMutex.Unlock()
|
||||
return ch
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue