1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

lock and unlock mutex correctly

This commit is contained in:
hellerve 2016-12-13 11:58:08 +01:00
parent 8bd8edc90d
commit fcf78afddc

View file

@ -10,7 +10,7 @@ import (
var ClientConf BirdConfig
var StatusConf StatusConfig
var RateLimitConf struct {
sync.Mutex
sync.RWMutex
Conf RateLimitConfig
}
@ -52,11 +52,17 @@ func InstallRateLimitReset() {
}
func checkRateLimit() bool {
if !RateLimitConf.Conf.Enabled {
RateLimitConf.RLock()
check := !RateLimitConf.Conf.Enabled
RateLimitConf.RUnlock()
if check {
return true
}
if RateLimitConf.Conf.Reqs > RateLimitConf.Conf.Max {
RateLimitConf.RLock()
check = RateLimitConf.Conf.Reqs > RateLimitConf.Conf.Max
RateLimitConf.RUnlock()
if check {
return false
}