mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
- Add new command executorserver as the draft executor server - Move shared pool logic into /pkg/pool
35 lines
711 B
Go
35 lines
711 B
Go
package pool
|
|
|
|
import "github.com/criyle/go-judge/pkg/envexec"
|
|
|
|
var _ envexec.CgroupPool = &FakeCgroupPool{}
|
|
|
|
// FakeCgroupPool implements cgroup pool but not actually do pool
|
|
type FakeCgroupPool struct {
|
|
builder CgroupBuilder
|
|
}
|
|
|
|
// NewFakeCgroupPool creates FakeCgroupPool
|
|
func NewFakeCgroupPool(builder CgroupBuilder) *FakeCgroupPool {
|
|
return &FakeCgroupPool{builder: builder}
|
|
}
|
|
|
|
// Get gets new cgroup
|
|
func (f *FakeCgroupPool) Get() (envexec.Cgroup, error) {
|
|
cg, err := f.builder.Build()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return (*wCgroup)(cg), nil
|
|
}
|
|
|
|
// Put destory the cgroup
|
|
func (f *FakeCgroupPool) Put(c envexec.Cgroup) {
|
|
c.Destory()
|
|
}
|
|
|
|
// Shutdown noop
|
|
func (f *FakeCgroupPool) Shutdown() {
|
|
|
|
}
|