Skip to content
Snippets Groups Projects
Commit 073dae2b authored by Lukas Braun's avatar Lukas Braun
Browse files

comment on userlocks synchronization

parent e9bb8446
No related branches found
No related tags found
No related merge requests found
......@@ -259,14 +259,17 @@ func handle_conn(db *sql.DB, conn net.Conn) {
}
log.Printf("%v: %v", name, result)
// name exists, get or create its lock
// name exists, so we can get or create its lock, double-checked locking style
// NOTE: the read lock is important to synchronize with the mutex initiali-
// zation, not just the map itself (i.e. a reader might observe a non-
// zeroed mutex if we used a concurrent map without a temporary variable
// and further memory barriers)
faildelay.RLock()
delay, exists := faildelay.userlocks[name]
faildelay.RUnlock()
if !exists {
debugf("[%v] not yet in faildelay.userlocks", remote)
// no atomic upgrade with sync.RWMutex, so we have to do the lookup again
faildelay.Lock()
delay, exists = faildelay.userlocks[name]
if !exists {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment