-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove cgo #5
remove cgo #5
Conversation
Go can call POSIX API without using cgo.
"unsafe" | ||
|
||
"golang.org/x/sys/unix" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this into glide.yaml and glide.lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added glide.yaml and glide.lock
@catatsuy Fix compilation error.
|
cachectl/stat.go
Outdated
pagesActive := activePages(fpath) | ||
pagesActive, err := activePages(fpath) | ||
if err != nil { | ||
log.Fatalf("%v\n", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use log.Printf() instead of log.Fatalf().
cachectl/activepages.go
Outdated
if ret != 0 { | ||
return 0, err | ||
} | ||
defer unix.Munmap(mmap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should munmap-call move to line after unix.Mmap()?
cachectl/activepages.go
Outdated
result := 0 | ||
|
||
for _, p := range pageinfo { | ||
if p%2 == 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is not p&1 == 1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original C code is it. But I thought that this one was easier to understand.
I thought that it should be left to the optimization of the compiler, but should it match the original C code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original code looks easier to understand. Because each entry of pageinfo is assumed that it is checked by the least significant bit. So using bit manipulation is more clear.
According to man mincore,
On return, the least significant bit of each byte will be set if the corresponding page is currently resident in memory, and be clear otherwise. (The settings of the other bits in each byte are undefined; these bits are reserved for possible later use.)
Go can call POSIX API without using cgo.