Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
b3382ec9
Commit
b3382ec9
authored
Jun 25, 2012
by
Jan Ziak
Committed by
Russ Cox
Jun 25, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/inotify: prevent data race
Fixes #3713. R=bradfitz, rsc CC=golang-dev
https://golang.org/cl/6331055
parent
5e75337c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
0 deletions
+9
-0
inotify_linux.go
src/pkg/exp/inotify/inotify_linux.go
+9
-0
No files found.
src/pkg/exp/inotify/inotify_linux.go
View file @
b3382ec9
...
...
@@ -31,6 +31,7 @@ import (
"fmt"
"os"
"strings"
"sync"
"syscall"
"unsafe"
)
...
...
@@ -47,6 +48,7 @@ type watch struct {
}
type
Watcher
struct
{
mu
sync
.
Mutex
fd
int
// File descriptor (as returned by the inotify_init() syscall)
watches
map
[
string
]
*
watch
// Map of inotify watches (key: path)
paths
map
[
int
]
string
// Map of watched paths (key: watch descriptor)
...
...
@@ -105,8 +107,12 @@ func (w *Watcher) AddWatch(path string, flags uint32) error {
watchEntry
.
flags
|=
flags
flags
|=
syscall
.
IN_MASK_ADD
}
w
.
mu
.
Lock
()
// synchronize with readEvents goroutine
wd
,
err
:=
syscall
.
InotifyAddWatch
(
w
.
fd
,
path
,
flags
)
if
err
!=
nil
{
w
.
mu
.
Unlock
()
return
&
os
.
PathError
{
Op
:
"inotify_add_watch"
,
Path
:
path
,
...
...
@@ -118,6 +124,7 @@ func (w *Watcher) AddWatch(path string, flags uint32) error {
w
.
watches
[
path
]
=
&
watch
{
wd
:
uint32
(
wd
),
flags
:
flags
}
w
.
paths
[
wd
]
=
path
}
w
.
mu
.
Unlock
()
return
nil
}
...
...
@@ -187,7 +194,9 @@ func (w *Watcher) readEvents() {
// doesn't append the filename to the event, but we would like to always fill the
// the "Name" field with a valid filename. We retrieve the path of the watch from
// the "paths" map.
w
.
mu
.
Lock
()
event
.
Name
=
w
.
paths
[
int
(
raw
.
Wd
)]
w
.
mu
.
Unlock
()
if
nameLen
>
0
{
// Point "bytes" at the first byte of the filename
bytes
:=
(
*
[
syscall
.
PathMax
]
byte
)(
unsafe
.
Pointer
(
&
buf
[
offset
+
syscall
.
SizeofInotifyEvent
]))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment