mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-27 13:48:49 +08:00

* NOISSUE - Add mProxy support (#1017) * Add mproxy Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com> * Fix docker and add EMQ compose Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com> * Fix EMQX name Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com> * Add nats, auth and es Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com> * Removed unucessary vendoring Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Update vendoring Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Fix mproxy interface implementation Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> NOISSUE - Aligned Event interface method signatures with new spec (#1025) * Aligned Event interface method signatures with new spec Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> * Updated deps Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> NOISSUE - Update mproxy dependency (#1038) Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> Update Vendor with new mProxy (#1043) Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> Twins merge conflict reverted Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> Twins merge conflict reverted Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> Twins fixed nats import Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> Update deps Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> * Resolved GolangCI remarks Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> Resolved GolangCI remarks Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> Resolved GolangCI remarks Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> * Fixed Event interface Unsubscribe() typo Signed-off-by: Nikola Marcetic <n.marcetic86@gmail.com> * Update vendors Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> * Upgrade CI script Signed-off-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com> Co-authored-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
87 lines
1.9 KiB
Go
87 lines
1.9 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// CPU affinity functions
|
|
|
|
package unix
|
|
|
|
import (
|
|
"math/bits"
|
|
"unsafe"
|
|
)
|
|
|
|
const cpuSetSize = _CPU_SETSIZE / _NCPUBITS
|
|
|
|
// CPUSet represents a CPU affinity mask.
|
|
type CPUSet [cpuSetSize]cpuMask
|
|
|
|
func schedAffinity(trap uintptr, pid int, set *CPUSet) error {
|
|
_, _, e := RawSyscall(trap, uintptr(pid), uintptr(unsafe.Sizeof(*set)), uintptr(unsafe.Pointer(set)))
|
|
if e != 0 {
|
|
return errnoErr(e)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// SchedGetaffinity gets the CPU affinity mask of the thread specified by pid.
|
|
// If pid is 0 the calling thread is used.
|
|
func SchedGetaffinity(pid int, set *CPUSet) error {
|
|
return schedAffinity(SYS_SCHED_GETAFFINITY, pid, set)
|
|
}
|
|
|
|
// SchedSetaffinity sets the CPU affinity mask of the thread specified by pid.
|
|
// If pid is 0 the calling thread is used.
|
|
func SchedSetaffinity(pid int, set *CPUSet) error {
|
|
return schedAffinity(SYS_SCHED_SETAFFINITY, pid, set)
|
|
}
|
|
|
|
// Zero clears the set s, so that it contains no CPUs.
|
|
func (s *CPUSet) Zero() {
|
|
for i := range s {
|
|
s[i] = 0
|
|
}
|
|
}
|
|
|
|
func cpuBitsIndex(cpu int) int {
|
|
return cpu / _NCPUBITS
|
|
}
|
|
|
|
func cpuBitsMask(cpu int) cpuMask {
|
|
return cpuMask(1 << (uint(cpu) % _NCPUBITS))
|
|
}
|
|
|
|
// Set adds cpu to the set s.
|
|
func (s *CPUSet) Set(cpu int) {
|
|
i := cpuBitsIndex(cpu)
|
|
if i < len(s) {
|
|
s[i] |= cpuBitsMask(cpu)
|
|
}
|
|
}
|
|
|
|
// Clear removes cpu from the set s.
|
|
func (s *CPUSet) Clear(cpu int) {
|
|
i := cpuBitsIndex(cpu)
|
|
if i < len(s) {
|
|
s[i] &^= cpuBitsMask(cpu)
|
|
}
|
|
}
|
|
|
|
// IsSet reports whether cpu is in the set s.
|
|
func (s *CPUSet) IsSet(cpu int) bool {
|
|
i := cpuBitsIndex(cpu)
|
|
if i < len(s) {
|
|
return s[i]&cpuBitsMask(cpu) != 0
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Count returns the number of CPUs in the set s.
|
|
func (s *CPUSet) Count() int {
|
|
c := 0
|
|
for _, b := range s {
|
|
c += bits.OnesCount64(uint64(b))
|
|
}
|
|
return c
|
|
}
|