diff options
Diffstat (limited to 'wsc.go')
-rw-r--r-- | wsc.go | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -25,6 +25,7 @@ import ( "errors" "fmt" "sync" + "sync/atomic" "time" "github.com/coder/websocket" @@ -35,6 +36,8 @@ type errbytesT struct { bytes *[]byte } +var usemCount int64 + /* * This is more appropriately typed as uint64, but it needs to be cast to int64 * later anyway due to time.Duration, so let's just use int64. @@ -83,6 +86,7 @@ func handleConn( usems := make(map[int]*usemT) func() { + atomic.AddInt64(&usemCount, int64(len(courses))) coursesLock.RLock() defer coursesLock.RUnlock() for courseID, course := range courses { @@ -106,6 +110,7 @@ func handleConn( delete(course.Usems, userID) }() } + atomic.AddInt64(&usemCount, -int64(len(courses))) }() usemParent := make(chan int) @@ -122,7 +127,12 @@ func handleConn( case usemParent <- courseID: } } - time.Sleep(time.Duration(config.Perf.CourseUpdateInterval) * time.Millisecond) + time.Sleep( + time.Duration( + atomic.LoadInt64(&usemCount)>> + config.Perf.UsemDelayShiftBits, + ) * time.Millisecond, + ) } }() } |