capnslog: fix small race on PackageLogger.level#48
Conversation
mischief
commented
Feb 5, 2016
|
Reader-writer locks don't generally make sense where the critical section is trivially short like the single integer assignment being done here, since internally a rwmutex is still serializing the potentially concurrent read-lock acquisitions like a mutex would @ entry to the critical section internally either using atomics or a lock to manage the reader/writer counts. Basically the cost of maintaining the reader-writer mutex is comparable to the critical section itself, in this case. This situation is better served by an atomic, in lieu of going that route just use a simple mutex. |
|
@vcaputo i think my vote currently would be plain mutex if that's preferred. LogLevel is a int8 type, and sync/atomic works on 32/64bit integers and i don't know if i can get it to cope with a int8. i'd have to change LogLevel's type, which seems like a poor idea, with consideration to all the users of this package. |
|
sgtm! |
2d80889 to
bc73737
Compare
|
switched to sync.Mutex, ptal |
| if inLevel != CRITICAL && mylevel < inLevel { | ||
| return | ||
| } | ||
| logger.Lock() |
There was a problem hiding this comment.
Is there any reason not to just piggyback on logger.Lock() for serializing the accesses to PackageLogger.level?
I don't think we need to worry about lock contention here
There was a problem hiding this comment.
Line #46 below contains an unprotected access to the level member.
bc73737 to
ba2a174
Compare
|
ptal |
|
LGTM |
capnslog: fix small race on PackageLogger.level