mirror of https://github.com/chzyer/readline.git
Fix race condition in DefaultOnWidthChanged
This commit is contained in:
parent
2972be24d4
commit
0d62993714
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build darwin || dragonfly || freebsd || (linux && !appengine) || netbsd || openbsd || solaris
|
||||||
// +build darwin dragonfly freebsd linux,!appengine netbsd openbsd solaris
|
// +build darwin dragonfly freebsd linux,!appengine netbsd openbsd solaris
|
||||||
|
|
||||||
package readline
|
package readline
|
||||||
|
@ -60,11 +61,14 @@ func GetStdin() int {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
widthChangeMutex sync.Mutex
|
||||||
widthChange sync.Once
|
widthChange sync.Once
|
||||||
widthChangeCallback func()
|
widthChangeCallback func()
|
||||||
)
|
)
|
||||||
|
|
||||||
func DefaultOnWidthChanged(f func()) {
|
func DefaultOnWidthChanged(f func()) {
|
||||||
|
widthChangeMutex.Lock()
|
||||||
|
defer widthChangeMutex.Unlock()
|
||||||
widthChangeCallback = f
|
widthChangeCallback = f
|
||||||
widthChange.Do(func() {
|
widthChange.Do(func() {
|
||||||
ch := make(chan os.Signal, 1)
|
ch := make(chan os.Signal, 1)
|
||||||
|
|
Loading…
Reference in New Issue