Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(792)

Unified Diff: src/pkg/syscall/dll_windows.go

Issue 6817086: syscall: fix data races in LazyDLL/LazyProc
Patch Set: diff -r 126c37a9e33c https://go.googlecode.com/hg/ Created 13 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/syscall/dll_windows.go
===================================================================
--- a/src/pkg/syscall/dll_windows.go
+++ b/src/pkg/syscall/dll_windows.go
@@ -6,6 +6,8 @@
import (
"sync"
+ "sync/atomic"
+ "unsafe"
)
// DLLError describes reasons for DLL load failures.
@@ -166,7 +168,7 @@
// Load loads DLL file d.Name into memory. It returns an error if fails.
// Load will not try to load DLL, if it is already loaded into memory.
func (d *LazyDLL) Load() error {
- if d.dll == nil {
+ if atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&d.dll))) == nil {
d.mu.Lock()
defer d.mu.Unlock()
if d.dll == nil {
@@ -174,7 +176,7 @@
if e != nil {
return e
}
- d.dll = dll
+ atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&d.dll)), unsafe.Pointer(dll))
brainman 2012/11/07 03:50:03 I do not think you need to change that line. d.mu.
}
}
return nil
@@ -217,7 +219,7 @@
// an error if search fails. Find will not search procedure,
// if it is already found and loaded into memory.
func (p *LazyProc) Find() error {
- if p.proc == nil {
+ if atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&p.proc))) == nil {
p.mu.Lock()
defer p.mu.Unlock()
if p.proc == nil {
@@ -229,7 +231,7 @@
if e != nil {
return e
}
- p.proc = proc
+ atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&p.proc)), unsafe.Pointer(proc))
brainman 2012/11/07 03:50:03 Same. Do not change that line.
}
}
return nil
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b