mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 07:26:47 +00:00
Feature: Faster start & stop times (#648)
* Updates starting and stopping routines to be a bit more parallel with less waiting required * Removes stop, removes debugging output * linting and test fixes * Add extra kill switch for exiting on exchange loading delay * Fixes fun math * breaks loop instead of switch. Moves param warns higher * Removes unceccary gos. passes in cfg to remove data race * Removes os signal processing. Fixes bad master merge
This commit is contained in:
@@ -16,7 +16,6 @@ const gctscriptManagerName = "GCTScript"
|
||||
type GctScriptManager struct {
|
||||
config *Config
|
||||
started int32
|
||||
stopped int32
|
||||
shutdown chan struct{}
|
||||
// Optional values to override stored config ('nil' if not overridden)
|
||||
MaxVirtualMachines *uint8
|
||||
@@ -39,10 +38,9 @@ func (g *GctScriptManager) Started() bool {
|
||||
|
||||
// Start starts gctscript subsystem and creates shutdown channel
|
||||
func (g *GctScriptManager) Start(wg *sync.WaitGroup) (err error) {
|
||||
if atomic.AddInt32(&g.started, 1) != 1 {
|
||||
return fmt.Errorf("%s %s", gctscriptManagerName, subsystem.ErrSubSystemAlreadyStarted)
|
||||
if !atomic.CompareAndSwapInt32(&g.started, 0, 1) {
|
||||
return fmt.Errorf("%s %w", gctscriptManagerName, subsystem.ErrSubSystemAlreadyStarted)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
atomic.CompareAndSwapInt32(&g.started, 1, 0)
|
||||
@@ -59,16 +57,19 @@ func (g *GctScriptManager) Start(wg *sync.WaitGroup) (err error) {
|
||||
// Stop stops gctscript subsystem along with all running Virtual Machines
|
||||
func (g *GctScriptManager) Stop() error {
|
||||
if atomic.LoadInt32(&g.started) == 0 {
|
||||
return fmt.Errorf("%s %s", gctscriptManagerName, subsystem.ErrSubSystemNotStarted)
|
||||
}
|
||||
|
||||
if atomic.AddInt32(&g.stopped, 1) != 1 {
|
||||
return fmt.Errorf("%s %s", gctscriptManagerName, subsystem.ErrSubSystemAlreadyStopped)
|
||||
return fmt.Errorf("%s %w", gctscriptManagerName, subsystem.ErrSubSystemNotStarted)
|
||||
}
|
||||
defer func() {
|
||||
atomic.CompareAndSwapInt32(&g.started, 1, 0)
|
||||
}()
|
||||
|
||||
log.Debugln(log.GCTScriptMgr, gctscriptManagerName, subsystem.MsgSubSystemShuttingDown)
|
||||
err := g.ShutdownAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
close(g.shutdown)
|
||||
return g.ShutdownAll()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GctScriptManager) run(wg *sync.WaitGroup) {
|
||||
@@ -77,8 +78,6 @@ func (g *GctScriptManager) run(wg *sync.WaitGroup) {
|
||||
SetDefaultScriptOutput()
|
||||
g.autoLoad()
|
||||
defer func() {
|
||||
atomic.CompareAndSwapInt32(&g.stopped, 1, 0)
|
||||
atomic.CompareAndSwapInt32(&g.started, 1, 0)
|
||||
wg.Done()
|
||||
log.Debugln(log.GCTScriptMgr, gctscriptManagerName, subsystem.MsgSubSystemShutdown)
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user