Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: golang/glog
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.2.0
Choose a base ref
...
head repository: golang/glog
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.2.1
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Apr 4, 2024

  1. glog: don't hold mutex when sync'ing (#68)

    Some environments are slow when syncing and holding the lock might cause contention.
    
    cl/621846576 (google-internal)
    chressie authored Apr 4, 2024
    Copy the full SHA
    861d094 View commit details
Showing with 16 additions and 9 deletions.
  1. +16 −9 glog_file.go
25 changes: 16 additions & 9 deletions glog_file.go
Original file line number Diff line number Diff line change
@@ -369,23 +369,30 @@ func (s *fileSink) Flush() error {

// flush flushes all logs of severity threshold or greater.
func (s *fileSink) flush(threshold logsink.Severity) error {
s.mu.Lock()
defer s.mu.Unlock()

var firstErr error
updateErr := func(err error) {
if err != nil && firstErr == nil {
firstErr = err
}
}

// Flush from fatal down, in case there's trouble flushing.
for sev := logsink.Fatal; sev >= threshold; sev-- {
file := s.file[sev]
if file != nil {
updateErr(file.Flush())
updateErr(file.Sync())
// Remember where we flushed, so we can call sync without holding
// the lock.
var files []flushSyncWriter
func() {
s.mu.Lock()
defer s.mu.Unlock()
// Flush from fatal down, in case there's trouble flushing.
for sev := logsink.Fatal; sev >= threshold; sev-- {
if file := s.file[sev]; file != nil {
updateErr(file.Flush())
files = append(files, file)
}
}
}()

for _, file := range files {
updateErr(file.Sync())
}

return firstErr