github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/topic/topicwriterinternal/writer_reconnector_unsafe_test.go (about) 1 package topicwriterinternal 2 3 import ( 4 "container/list" 5 "reflect" 6 "runtime" 7 "sync" 8 "unsafe" 9 10 "golang.org/x/sync/semaphore" 11 ) 12 13 func getWaitersCount(sem *semaphore.Weighted) int { 14 defer runtime.KeepAlive(sem) 15 16 semVal := reflect.ValueOf(sem).Elem() 17 mutexField := semVal.FieldByName("mu") 18 19 mutexAddr := unsafe.Pointer(mutexField.UnsafeAddr()) 20 mutex := (*sync.Mutex)(mutexAddr) 21 mutex.Lock() 22 defer mutex.Unlock() 23 24 waitersField := semVal.FieldByName("waiters") 25 waitersPointer := unsafe.Pointer(waitersField.UnsafeAddr()) 26 waiters := (*list.List)(waitersPointer) 27 28 return waiters.Len() 29 }