-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread_linux.go
44 lines (36 loc) · 969 Bytes
/
thread_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Package thread is designed for manage OS thread parameters. Usually you
// need to call runtime.LockOSThread before use it.
//
// Only String methods allocates memory (mainly because using of fmt package)
// so don't use them when GC is disabled.
package thread
import (
"fmt"
"github.com/ziutek/sched"
"syscall"
)
type Thread struct {
tid int
}
func Current() Thread {
tid, _, e := syscall.RawSyscall(syscall.SYS_GETTID, 0, 0, 0)
if e != 0 {
panic(e)
}
return Thread{int(tid)}
}
func (t Thread) String() string {
return fmt.Sprint(t.tid)
}
func (t Thread) SetSchedPolicy(policy sched.Policy, param *sched.Param) error {
return sched.SetPolicy(t.tid, policy, param)
}
func (t Thread) SchedPolicy() (sched.Policy, error) {
return sched.GetPolicy(t.tid)
}
func (t Thread) SetSchedParam(param *sched.Param) error {
return sched.SetParam(t.tid, param)
}
func (t Thread) SchedParam(param *sched.Param) error {
return sched.GetParam(t.tid, param)
}