Use Eventfd() from x/sys/unix

Use unix.Eventfd() instead of C.eventfd and also use the correct
corresponding unix.EFD_CLOEXEC flag. This allows to get rid of cgo.
This commit is contained in:
Tobias Klauser 2017-07-20 14:35:05 +02:00
parent 4a69005fa1
commit 5acfb16023
2 changed files with 2 additions and 23 deletions

View File

@ -4,23 +4,10 @@ licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"cgo_genrule",
"go_library",
"go_test",
)
cgo_genrule(
name = "cgo_codegen",
srcs = ["threshold_notifier_linux.go"],
clinkopts = [
"-lz",
"-lm",
"-lpthread",
"-ldl",
],
tags = ["automanaged"],
)
go_test(
name = "go_default_test",
srcs = [
@ -53,9 +40,9 @@ go_library(
"doc.go",
"eviction_manager.go",
"helpers.go",
"threshold_notifier_linux.go",
"types.go",
],
library = ":cgo_codegen",
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",

View File

@ -1,5 +1,3 @@
// +build cgo
/*
Copyright 2016 The Kubernetes Authors.
@ -18,11 +16,6 @@ limitations under the License.
package eviction
/*
#include <sys/eventfd.h>
*/
import "C"
import (
"fmt"
@ -61,11 +54,10 @@ func NewMemCGThresholdNotifier(path, attribute, threshold, description string, h
unix.Close(controlfd)
}
}()
efd, err := C.eventfd(0, C.EFD_CLOEXEC)
eventfd, err := unix.Eventfd(0, unix.EFD_CLOEXEC)
if err != nil {
return nil, err
}
eventfd := int(efd)
if eventfd < 0 {
err = fmt.Errorf("eventfd call failed")
return nil, err