1// Copyright 2022 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build unix
6
7package runtime
8
9// retryOnEAGAIN retries a function until it does not return EAGAIN.
10// It will use an increasing delay between calls, and retry up to 20 times.
11// The function argument is expected to return an errno value,
12// and retryOnEAGAIN will return any errno value other than EAGAIN.
13// If all retries return EAGAIN, then retryOnEAGAIN will return EAGAIN.
14func retryOnEAGAIN(fn func() int32) int32 {
15	for tries := 0; tries < 20; tries++ {
16		errno := fn()
17		if errno != _EAGAIN {
18			return errno
19		}
20		usleep_no_g(uint32(tries+1) * 1000) // milliseconds
21	}
22	return _EAGAIN
23}
24