1
0
Fork 0

channel close 버그 수정

This commit is contained in:
Sangbum Kim 2018-07-06 01:57:59 +09:00
parent 8ebf91bf19
commit 560c93c2e4
2 changed files with 13 additions and 4 deletions

View File

@ -29,6 +29,10 @@ func initLogger() func() {
// 로깅설정 // 로깅설정
formatter := zapcore.NewConsoleEncoder(zlog.LogCommonFormat) formatter := zapcore.NewConsoleEncoder(zlog.LogCommonFormat)
level := zap.InfoLevel
if *verbose{
level=zap.DebugLevel
}
// 전역 로거 초기화 // 전역 로거 초기화
var err error var err error
logger, err = zlog.Init( logger, err = zlog.Init(
@ -38,7 +42,7 @@ func initLogger() func() {
"Stderr", "Stderr",
"", "",
nil, nil,
zap.DebugLevel, level,
) )
if err != nil { if err != nil {

View File

@ -9,6 +9,7 @@ import (
"amuz.es/src/infra/goutils/handler" "amuz.es/src/infra/goutils/handler"
"amuz.es/src/infra/cpu_ctrl/producer" "amuz.es/src/infra/cpu_ctrl/producer"
"go.uber.org/zap" "go.uber.org/zap"
"github.com/alecthomas/chroma/lexers/m"
) )
var () var ()
@ -45,12 +46,18 @@ func (c *fanControl) StartControl() {
c.handler.NotifyError(err.(error)) c.handler.NotifyError(err.(error))
} }
}() }()
defer close(c.fanSpeedConsumer)
defer c.logger.Info("Fan control stopped") defer c.logger.Info("Fan control stopped")
c.logger.Info("Fan control started") c.logger.Info("Fan control started")
ticker := time.Tick(c.sampleDuration) ticker := time.Tick(c.sampleDuration)
pastFanSpeedList, newFanSpeedList := make([]int, c.processorCount), make([]int, c.processorCount) pastFanSpeedList, newFanSpeedList := make([]int, c.processorCount), make([]int, c.processorCount)
go func() {
for changedFanspeed := range c.fanSpeedConsumer {
newFanSpeedList[changedFanspeed.Id] = changedFanspeed.FanSpeed
}
}()
for { for {
select { select {
case <-ticker: case <-ticker:
@ -58,8 +65,6 @@ func (c *fanControl) StartControl() {
copy(pastFanSpeedList, newFanSpeedList) copy(pastFanSpeedList, newFanSpeedList)
go c.applyFanspeed(pastFanSpeedList) go c.applyFanspeed(pastFanSpeedList)
} }
case changedSpeed := <-c.fanSpeedConsumer:
newFanSpeedList[changedSpeed.Id] = changedSpeed.FanSpeed
case <-c.handler.Done(): case <-c.handler.Done():
return return
} }