Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package procs
import (
_ "unsafe"
)
//go:linkname runtime_procPin runtime.procPin
func runtime_procPin() int
//go:linkname runtime_procUnpin runtime.procUnpin
func runtime_procUnpin() int
func Id() int {
var pid = runtime_procPin()
runtime_procUnpin()
return pid
}

View File

@@ -0,0 +1,99 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package procs_test
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/procs"
"github.com/iwind/TeaGo/lists"
"runtime"
"sort"
"sync"
"testing"
)
func TestId_24(t *testing.T) {
runtime.GOMAXPROCS(24)
var procIds []int
var mu = &sync.Mutex{}
var countProcs = runtime.GOMAXPROCS(0)
var wg = &sync.WaitGroup{}
wg.Add(countProcs * 4096)
for i := 0; i < countProcs*4096; i++ {
go func() {
defer wg.Done()
mu.Lock()
var procId = procs.Id()
if !lists.ContainsInt(procIds, procId) {
procIds = append(procIds, procId)
}
mu.Unlock()
}()
}
wg.Wait()
sort.Ints(procIds)
t.Log(procIds)
}
func TestId_4(t *testing.T) {
runtime.GOMAXPROCS(4)
var procIds []int
var mu = &sync.Mutex{}
var countProcs = runtime.GOMAXPROCS(0)
var wg = &sync.WaitGroup{}
wg.Add(countProcs * 4096)
for i := 0; i < countProcs*4096; i++ {
go func() {
defer wg.Done()
mu.Lock()
var procId = procs.Id()
if !lists.ContainsInt(procIds, procId) {
procIds = append(procIds, procId)
}
mu.Unlock()
}()
}
wg.Wait()
sort.Ints(procIds)
t.Log(procIds)
}
func TestId_Auto(t *testing.T) {
var procIds []int
var mu = &sync.Mutex{}
var countProcs = runtime.GOMAXPROCS(0)
var wg = &sync.WaitGroup{}
wg.Add(countProcs * 4096)
for i := 0; i < countProcs*4096; i++ {
go func() {
defer wg.Done()
mu.Lock()
var procId = procs.Id()
if !lists.ContainsInt(procIds, procId) {
procIds = append(procIds, procId)
}
mu.Unlock()
}()
}
wg.Wait()
sort.Ints(procIds)
t.Log(procIds)
}
func BenchmarkId(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = procs.Id()
}
})
}