package instance

import (
	"sync"
)

var Mgr *insManager

type insManager struct {
	sync.RWMutex
	insMap map[int64]*Instance // [uniqueNo]
}

func init() {
	Mgr = &insManager{
		insMap: make(map[int64]*Instance),
	}
}

func (m *insManager) Add(uniqueNo int64, ins *Instance) {
	m.Lock()
	defer m.Unlock()
	m.insMap[uniqueNo] = ins
}

func (m *insManager) Delete(uniqueNo int64) {
	m.Lock()
	defer m.Unlock()
	delete(m.insMap, uniqueNo)
}

func (m *insManager) GetAll() map[int64]*Instance {
	m.RLock()
	defer m.RUnlock()
	return m.insMap
}

func (m *insManager) GetByUniqueNo(uniqueNo int64) *Instance {
	m.RLock()
	defer m.RUnlock()
	return m.insMap[uniqueNo]
}
