good morning!!!!

Skip to content
Snippets Groups Projects
Commit a072c68d authored by Garet Halliday's avatar Garet Halliday
Browse files

thinking

parent 5d1a84d4
Branches
Tags
No related merge requests found
package rob
// Constraints is a bitfield used to control which Sink a job runs on.
// They can be declared by using const ... rob.Constraints = 1 << iota.
// Because Constraints is an int64, you may have a maximum of 64 constraints
//
// Example:
/*
const (
ConstraintOne rob.Constraints = 1 << iota
ConstraintTwo
ConstraintThree
)
var All = rob.Constraints.All(
ConstraintOne,
ConstraintTwo,
ConstraintThree,
)
*/
type Constraints int64
func (T Constraints) All(cn ...Constraints) Constraints {
v := T
for _, c := range cn {
v |= c
}
return v
}
func (T Constraints) Satisfies(other Constraints) bool {
return (other & T) == other
}
package rob
type Scheduler interface {
NewSink() Sink
// NewSink creates a new sink that fulfills input constraints
NewSink(fulfills Constraints) Sink
NewSource() Source
}
......@@ -18,8 +18,8 @@ func NewScheduler() *Scheduler {
return new(Scheduler)
}
func (T *Scheduler) NewSink() rob.Sink {
sink := newSink(T)
func (T *Scheduler) NewSink(constraints rob.Constraints) rob.Sink {
sink := newSink(T, constraints)
T.mu.Lock()
defer T.mu.Unlock()
......
......@@ -37,7 +37,7 @@ func (T *ShareTable) Get(user int) int {
}
func testSink(sched *Scheduler, table *ShareTable) {
sink := sched.NewSink()
sink := sched.NewSink(0)
for {
w := sink.Read()
switch v := w.(type) {
......@@ -61,7 +61,7 @@ func testSource(sched *Scheduler, id int, dur time.Duration) {
Duration: dur,
Done: done,
}
source.Schedule(w)
source.Schedule(w, 0)
<-done
}
}
......
......@@ -17,6 +17,7 @@ const (
type Sink struct {
scheduler *Scheduler
constraints rob.Constraints
runtime map[uuid.UUID]time.Duration
......@@ -31,9 +32,10 @@ type Sink struct {
mu sync.Mutex
}
func newSink(scheduler *Scheduler) *Sink {
func newSink(scheduler *Scheduler, constraints rob.Constraints) *Sink {
return &Sink{
scheduler: scheduler,
constraints: constraints,
runtime: make(map[uuid.UUID]time.Duration),
ready: make(chan struct{}),
}
......
......@@ -23,7 +23,7 @@ func newSource() *Source {
}
}
func (T *Source) Schedule(w any) {
func (T *Source) Schedule(w any, constraints rob.Constraints) {
T.mu.Lock()
T.queue.PushBack(w)
notifier := T.notifier
......
package rob
type Source interface {
Schedule(any)
// Schedule work with constraints. Work will run on a Sink that at least fulfills these constraints
Schedule(work any, constraints Constraints)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment