Skip to content

Commit

Permalink
refine: thread safety write intro data (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
shhdgit authored Jul 23, 2021
1 parent 7296574 commit 40cb539
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ ifeq ($(UI),1)
BUILD_TAGS += ui_server
endif

ifeq ($(DISTRO_BUILD_TAG),1)
BUILD_TAGS += dashboard_distro
endif

LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.InternalVersion=$(shell grep -v '^\#' ./release-version)"
LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.Standalone=Yes"
LDFLAGS += -X "$(DASHBOARD_PKG)/pkg/utils/version.PDVersion=N/A"
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/distro/default_distro_info.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !distro
// +build !dashboard_distro

package distro

Expand Down
18 changes: 14 additions & 4 deletions pkg/utils/distro/distro.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@

package distro

var data map[string]interface{}
import (
"sync/atomic"
)

func Replace(distro map[string]interface{}) {
data = distro
type introData map[string]interface{}

var data atomic.Value

func Replace(distro introData) {
data.Store(distro)
}

func Data(k string) string {
return data[k].(string)
d := data.Load().(introData)
if d[k] == nil {
return k
}
return d[k].(string)
}
2 changes: 1 addition & 1 deletion scripts/generate_distro_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PROJECT_DIR="$(dirname "$DIR")"

if [ "${DISTRO_BUILD_TAG:-}" = "1" ]; then
BUILD_TAG_PARAMETER=distro
BUILD_TAG_PARAMETER=dashboard_distro
else
BUILD_TAG_PARAMETER=""
fi
Expand Down

0 comments on commit 40cb539

Please sign in to comment.