mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
daemon/events: let Log be [slightly] blocking
With go1.5's concurrency, the use of a goroutine in Log'ing events was causing the resulting events to not be in order. Signed-off-by: Vincent Batts <vbatts@redhat.com>
This commit is contained in:
parent
59311faaed
commit
09e7dd03f8
1 changed files with 11 additions and 13 deletions
|
@ -45,19 +45,17 @@ func (e *Events) Evict(l chan interface{}) {
|
||||||
// Log broadcasts event to listeners. Each listener has 100 millisecond for
|
// Log broadcasts event to listeners. Each listener has 100 millisecond for
|
||||||
// receiving event or it will be skipped.
|
// receiving event or it will be skipped.
|
||||||
func (e *Events) Log(action, id, from string) {
|
func (e *Events) Log(action, id, from string) {
|
||||||
go func() {
|
jm := &jsonmessage.JSONMessage{Status: action, ID: id, From: from, Time: time.Now().UTC().Unix()}
|
||||||
e.mu.Lock()
|
e.mu.Lock()
|
||||||
jm := &jsonmessage.JSONMessage{Status: action, ID: id, From: from, Time: time.Now().UTC().Unix()}
|
if len(e.events) == cap(e.events) {
|
||||||
if len(e.events) == cap(e.events) {
|
// discard oldest event
|
||||||
// discard oldest event
|
copy(e.events, e.events[1:])
|
||||||
copy(e.events, e.events[1:])
|
e.events[len(e.events)-1] = jm
|
||||||
e.events[len(e.events)-1] = jm
|
} else {
|
||||||
} else {
|
e.events = append(e.events, jm)
|
||||||
e.events = append(e.events, jm)
|
}
|
||||||
}
|
e.mu.Unlock()
|
||||||
e.mu.Unlock()
|
e.pub.Publish(jm)
|
||||||
e.pub.Publish(jm)
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubscribersCount returns number of event listeners
|
// SubscribersCount returns number of event listeners
|
||||||
|
|
Loading…
Add table
Reference in a new issue