diff --git a/ioutils/readers.go b/ioutils/readers.go index 0e542cb..de15a00 100644 --- a/ioutils/readers.go +++ b/ioutils/readers.go @@ -189,6 +189,7 @@ func (r *bufReader) drain() { reuseCount++ r.wait.Signal() r.Unlock() + callSchedulerIfNecessary() if err != nil { break } diff --git a/ioutils/readers_test.go b/ioutils/readers_test.go index d220487..0a39b6e 100644 --- a/ioutils/readers_test.go +++ b/ioutils/readers_test.go @@ -45,7 +45,7 @@ func TestReaderErrWrapperReadOnError(t *testing.T) { func TestReaderErrWrapperRead(t *testing.T) { reader := strings.NewReader("a string reader.") wrapper := NewReaderErrWrapper(reader, func() { - t.Fatalf("readErrWrapper should not have called the anonymous function on failure") + t.Fatalf("readErrWrapper should not have called the anonymous function") }) // Read 20 byte (should be ok with the string above) num, err := wrapper.Read(make([]byte, 20)) diff --git a/ioutils/scheduler.go b/ioutils/scheduler.go new file mode 100644 index 0000000..3c88f29 --- /dev/null +++ b/ioutils/scheduler.go @@ -0,0 +1,6 @@ +// +build !gccgo + +package ioutils + +func callSchedulerIfNecessary() { +} diff --git a/ioutils/scheduler_gccgo.go b/ioutils/scheduler_gccgo.go new file mode 100644 index 0000000..c11d02b --- /dev/null +++ b/ioutils/scheduler_gccgo.go @@ -0,0 +1,13 @@ +// +build gccgo + +package ioutils + +import ( + "runtime" +) + +func callSchedulerIfNecessary() { + //allow or force Go scheduler to switch context, without explicitly + //forcing this will make it hang when using gccgo implementation + runtime.Gosched() +}