-
Notifications
You must be signed in to change notification settings - Fork 20.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
log: use atomic types #27763
Merged
Merged
log: use atomic types #27763
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,9 +39,9 @@ var errTraceSyntax = errors.New("expect file.go:234") | |
type GlogHandler struct { | ||
origin Handler // The origin handler this wraps | ||
|
||
level uint32 // Current log level, atomically accessible | ||
override uint32 // Flag whether overrides are used, atomically accessible | ||
backtrace uint32 // Flag whether backtrace location is set | ||
level atomic.Uint32 // Current log level, atomically accessible | ||
override atomic.Bool // Flag whether overrides are used, atomically accessible | ||
backtrace atomic.Uint32 // Flag whether backtrace location is set | ||
|
||
patterns []pattern // Current list of patterns to override with | ||
siteCache map[uintptr]Lvl // Cache of callsite pattern evaluations | ||
|
@@ -72,7 +72,7 @@ type pattern struct { | |
// Verbosity sets the glog verbosity ceiling. The verbosity of individual packages | ||
// and source files can be raised using Vmodule. | ||
func (h *GlogHandler) Verbosity(level Lvl) { | ||
atomic.StoreUint32(&h.level, uint32(level)) | ||
h.level.Store(uint32(level)) | ||
} | ||
|
||
// Vmodule sets the glog verbosity pattern. | ||
|
@@ -138,7 +138,7 @@ func (h *GlogHandler) Vmodule(ruleset string) error { | |
|
||
h.patterns = filter | ||
h.siteCache = make(map[uintptr]Lvl) | ||
atomic.StoreUint32(&h.override, uint32(len(filter))) | ||
h.override.Store(len(filter) != 0) | ||
|
||
return nil | ||
} | ||
|
@@ -171,7 +171,7 @@ func (h *GlogHandler) BacktraceAt(location string) error { | |
defer h.lock.Unlock() | ||
|
||
h.location = location | ||
atomic.StoreUint32(&h.backtrace, uint32(len(location))) | ||
h.backtrace.Store(uint32(len(location))) | ||
|
||
return nil | ||
} | ||
|
@@ -180,7 +180,7 @@ func (h *GlogHandler) BacktraceAt(location string) error { | |
// and backtrace filters, finally emitting it if either allow it through. | ||
func (h *GlogHandler) Log(r *Record) error { | ||
// If backtracing is requested, check whether this is the callsite | ||
if atomic.LoadUint32(&h.backtrace) > 0 { | ||
if h.backtrace.Load() > 0 { | ||
// Everything below here is slow. Although we could cache the call sites the | ||
// same way as for vmodule, backtracing is so rare it's not worth the extra | ||
// complexity. | ||
|
@@ -198,11 +198,11 @@ func (h *GlogHandler) Log(r *Record) error { | |
} | ||
} | ||
// If the global log level allows, fast track logging | ||
if atomic.LoadUint32(&h.level) >= uint32(r.Lvl) { | ||
if h.level.Load() >= uint32(r.Lvl) { | ||
return h.origin.Log(r) | ||
} | ||
// If no local overrides are present, fast track skipping | ||
if atomic.LoadUint32(&h.override) == 0 { | ||
if h.override.Load() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It needs to be either |
||
return nil | ||
} | ||
// Check callsite cache for previously calculated log levels | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, backtrace also looks very boolean, in it's usage, to me :)