From 4cf120c1d5d5fb84208dd45e4483ae9d2e7467e1 Mon Sep 17 00:00:00 2001 From: Filippov Alex Date: Thu, 25 Jan 2024 09:44:56 +0530 Subject: [PATCH] technical debt --- plugins/alexa/server.go | 6 ++---- system/supervisor/plugin.go | 13 +++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/plugins/alexa/server.go b/plugins/alexa/server.go index 0761a1898..bc351ab46 100644 --- a/plugins/alexa/server.go +++ b/plugins/alexa/server.go @@ -70,10 +70,9 @@ func NewServer(adaptors *adaptors.Adaptors, // Start ... func (s *Server) Start() { - if s.isStarted.Load() { + if !s.isStarted.CompareAndSwap(false, true) { return } - s.isStarted.Store(true) s.init() @@ -119,10 +118,9 @@ func (s *Server) init() { // Stop ... func (s *Server) Stop() { - if !s.isStarted.Load() { + if !s.isStarted.CompareAndSwap(true, false) { return } - s.isStarted.Store(false) //todo fix //s.gate.SetAlexaApiEngine(nil) diff --git a/system/supervisor/plugin.go b/system/supervisor/plugin.go index c884e5db5..aea650478 100644 --- a/system/supervisor/plugin.go +++ b/system/supervisor/plugin.go @@ -55,13 +55,12 @@ func NewPlugin() *Plugin { // Load ... func (p *Plugin) Load(ctx context.Context, service Service, actorConstructor ActorConstructor) error { - p.Service = service - p.actorConstructor = actorConstructor - - if p.IsStarted.Load() { + if !p.IsStarted.CompareAndSwap(false, true) { return apperr.ErrPluginIsLoaded } - p.IsStarted.Store(true) + + p.Service = service + p.actorConstructor = actorConstructor return nil } @@ -69,7 +68,7 @@ func (p *Plugin) Load(ctx context.Context, service Service, actorConstructor Act // Unload ... func (p *Plugin) Unload(ctx context.Context) error { - if !p.IsStarted.Load() { + if !p.IsStarted.CompareAndSwap(true, false) { return apperr.ErrPluginIsUnloaded } @@ -80,8 +79,6 @@ func (p *Plugin) Unload(ctx context.Context) error { return true }) - p.IsStarted.Store(false) - return nil }