Ocean/Log/Flush.go

34 lines
835 B
Go
Raw Permalink Normal View History

package Log
import (
"github.com/SommerEngineering/Ocean/Log/Device"
)
2015-06-17 15:44:52 +00:00
// Function to force all buffers to flush the events.
func Flush() {
2015-06-17 15:44:52 +00:00
// Close the entry buffer:
mutexChannel.Lock()
channelReady = false
close(entriesBuffer)
mutexChannel.Unlock()
2015-06-17 15:44:52 +00:00
// Wait that the scheduler is done:
<-schedulerExitSignal
2015-06-17 15:44:52 +00:00
// Get all log entries from the device delay buffer:
mutexDeviceDelays.Lock()
dataArray := logEntryListToArray(deviceDelayBuffer)
deviceDelayBuffer.Init()
mutexDeviceDelays.Unlock()
2015-06-17 15:44:52 +00:00
// Deliver all the events to all devices:
mutexDevices.RLock()
for entry := devices.Front(); entry != nil; entry = entry.Next() {
dev := entry.Value.(Device.Device)
dev.Log(dataArray) // Want to wait to complete, therefore no new thread here
dev.Flush()
}
mutexDevices.RUnlock()
}