Skip to content
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

Merged
merged 5 commits into from
Mar 28, 2017
Merged

remove cgo #5

merged 5 commits into from
Mar 28, 2017

Conversation

catatsuy
Copy link
Contributor

Go can call POSIX API without using cgo.

Go can call POSIX API without using cgo.
"unsafe"

"golang.org/x/sys/unix"
Copy link
Owner

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.

Copy link
Contributor Author

@catatsuy catatsuy Mar 28, 2017

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

@cubicdaiya
Copy link
Owner

@catatsuy Fix compilation error.

$ make
GO15VENDOREXPERIMENT=1 go build  -o bin/cachectl cmd/cachectl/cachectl.go
# github.com/cubicdaiya/cachectl/cachectl
cachectl/activepages.go:24: cannot use nil as type int in return argument
cachectl/activepages.go:42: cannot use nil as type int in return argument
cachectl/purge.go:26: no new variables on left side of :=
cachectl/purge.go:28: invalid operation: fsize * rate (mismatched types int64 and float64)
cachectl/stat.go:21: undefined: log.Errorf
make: *** [bin/cachectl] Error 2

cachectl/stat.go Outdated
pagesActive := activePages(fpath)
pagesActive, err := activePages(fpath)
if err != nil {
log.Fatalf("%v\n", err)
Copy link
Owner

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().

if ret != 0 {
return 0, err
}
defer unix.Munmap(mmap)
Copy link
Owner

@cubicdaiya cubicdaiya Mar 28, 2017

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()?

result := 0

for _, p := range pageinfo {
if p%2 == 1 {
Copy link
Owner

@cubicdaiya cubicdaiya Mar 28, 2017

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?

Copy link
Contributor Author

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?

Copy link
Owner

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.)

@cubicdaiya cubicdaiya merged commit 275dfba into cubicdaiya:master Mar 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants