wintun: do not load dll in init()

This prevents linking to wintun.dll until it's actually needed, which
should improve startup time.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld
2020-12-09 01:46:55 +01:00
parent 347ce76bbc
commit ca9edf1c63
5 changed files with 21 additions and 14 deletions

View File

@@ -20,6 +20,7 @@ type lazyDLL struct {
Name string
mu sync.Mutex
module windows.Handle
onLoad func(d *lazyDLL)
}
func (d *lazyDLL) Load() error {
@@ -42,6 +43,9 @@ func (d *lazyDLL) Load() error {
}
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&d.module)), unsafe.Pointer(module))
if d.onLoad != nil {
d.onLoad(d)
}
return nil
}