diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-09-27 10:40:59 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-09-27 10:53:37 +0200 |
commit | ae319383ecb0a1af8964c4c5d1b19d5c2ec7d438 (patch) | |
tree | 68853e8b657762ebb09452b6e5ec514baf34ad67 /tunnel/winipcfg/unicast_address_change_handler.go | |
parent | winipcfg: port more granular locking from route change to others (diff) | |
download | wireguard-windows-ae319383ecb0a1af8964c4c5d1b19d5c2ec7d438.tar.xz wireguard-windows-ae319383ecb0a1af8964c4c5d1b19d5c2ec7d438.zip |
winipcfg: make Unregister wait for callbacks to complete
Diffstat (limited to '')
-rw-r--r-- | tunnel/winipcfg/unicast_address_change_handler.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/tunnel/winipcfg/unicast_address_change_handler.go b/tunnel/winipcfg/unicast_address_change_handler.go index 1ec34cd4..5f8f2c96 100644 --- a/tunnel/winipcfg/unicast_address_change_handler.go +++ b/tunnel/winipcfg/unicast_address_change_handler.go @@ -13,7 +13,8 @@ import ( // UnicastAddressChangeCallback structure allows unicast address change callback handling. type UnicastAddressChangeCallback struct { - cb func(notificationType MibNotificationType, unicastAddress *MibUnicastIPAddressRow) + cb func(notificationType MibNotificationType, unicastAddress *MibUnicastIPAddressRow) + wait sync.WaitGroup } var ( @@ -27,7 +28,7 @@ var ( // registered, the function will silently return. Returned UnicastAddressChangeCallback.Unregister method should be used // to unregister. func RegisterUnicastAddressChangeCallback(callback func(notificationType MibNotificationType, unicastAddress *MibUnicastIPAddressRow)) (*UnicastAddressChangeCallback, error) { - s := &UnicastAddressChangeCallback{callback} + s := &UnicastAddressChangeCallback{cb: callback} unicastAddressChangeAddRemoveMutex.Lock() defer unicastAddressChangeAddRemoveMutex.Unlock() @@ -59,6 +60,8 @@ func (callback *UnicastAddressChangeCallback) Unregister() error { removeIt := len(unicastAddressChangeCallbacks) == 0 && unicastAddressChangeHandle != 0 unicastAddressChangeMutex.Unlock() + callback.wait.Wait() + if removeIt { err := cancelMibChangeNotify2(unicastAddressChangeHandle) if err != nil { @@ -74,7 +77,11 @@ func unicastAddressChanged(callerContext uintptr, row *MibUnicastIPAddressRow, n rowCopy := *row unicastAddressChangeMutex.Lock() for cb := range unicastAddressChangeCallbacks { - go cb.cb(notificationType, &rowCopy) + cb.wait.Add(1) + go func(cb *UnicastAddressChangeCallback) { + cb.cb(notificationType, &rowCopy) + cb.wait.Done() + }(cb) } unicastAddressChangeMutex.Unlock() return 0 |