github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/system/trace/db_record.go (about) 1 package trace 2 3 import ( 4 "sync" 5 "time" 6 ) 7 8 9 func getNowTimeMs() int64 { 10 return time.Now().UnixNano() / 1e6 11 } 12 13 type DbRecord struct { 14 lock sync.RWMutex 15 oper map[string]int 16 } 17 18 func newDbRecord() *DbRecord { 19 return &DbRecord{ 20 oper: make(map[string]int), 21 } 22 } 23 24 func (s *DbRecord) GetOperType(oper string) int { 25 s.lock.RLock() 26 defer s.lock.RUnlock() 27 if _, ok := s.oper[oper]; !ok { 28 return -1 29 } 30 return s.oper[oper] 31 } 32 33 func (s *DbRecord) AddOperType(oper string, value int) { 34 s.lock.Lock() 35 defer s.lock.Unlock() 36 s.oper[oper] = value 37 }