Cleanup logic for updating stats to avoid calling mutex outside of file
This commit is contained in:
		
							parent
							
								
									d7c7155802
								
							
						
					
					
						commit
						57daf0889a
					
				| 
						 | 
				
			
			@ -122,13 +122,10 @@ func (s *Server) StartEventListeners() {
 | 
			
		|||
				}()
 | 
			
		||||
			case e := <-stats:
 | 
			
		||||
				go func() {
 | 
			
		||||
					// Update the server resource tracking object with the resources we got here.
 | 
			
		||||
					s.resources.mu.Lock()
 | 
			
		||||
					s.resources.Stats = e.Data.(environment.Stats)
 | 
			
		||||
					s.resources.mu.Unlock()
 | 
			
		||||
					s.resources.UpdateStats(e.Data.(environment.Stats))
 | 
			
		||||
 | 
			
		||||
					// If there is no disk space available at this point, trigger the server disk limiter logic
 | 
			
		||||
					// which will start to stop the running instance.
 | 
			
		||||
					// If there is no disk space available at this point, trigger the server
 | 
			
		||||
					// disk limiter logic which will start to stop the running instance.
 | 
			
		||||
					if !s.Filesystem().HasSpaceAvailable(true) {
 | 
			
		||||
						l.Trigger()
 | 
			
		||||
					}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,6 +38,13 @@ func (s *Server) Proc() ResourceUsage {
 | 
			
		|||
	return s.resources
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateStats updates the current stats for the server's resource usage.
 | 
			
		||||
func (ru *ResourceUsage) UpdateStats(stats environment.Stats) {
 | 
			
		||||
	ru.mu.Lock()
 | 
			
		||||
	ru.Stats = stats
 | 
			
		||||
	ru.mu.Unlock()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Reset resets the usages values to zero, used when a server is stopped to ensure we don't hold
 | 
			
		||||
// onto any values incorrectly.
 | 
			
		||||
func (ru *ResourceUsage) Reset() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user