//go:build linux

package client

import (
	"golang.org/x/sys/unix"

	"repositories.action2quare.com/ayo/gocommon/logger"
)

func set_affinity(pid int, cpu int) {
	var cpuset unix.CPUSet
	err := unix.SchedGetaffinity(pid, &cpuset)
	if err != nil {
		logger.Println("SchedGetaffinity failed :", err)
	}

	count := cpuset.Count()
	cpuset.Zero()
	cpuset.Set(cpu % count)

	err = unix.SchedSetaffinity(pid, &cpuset)
	if err != nil {
		logger.Println("SchedSetaffinity failed :", err)
	}
}
