func NewB(m uint) *ImpB { // var s cs.CriticalSection if m < 1 { m = 1 } var nR, nW, rR uint c := func(k uint) bool { if k == reader { return nW == 0 && (s.Blocked(writer) || rR < m) } return nR == 0 && nW == 0 /* && ! x.s.Blocked (readeer) */ // writer } e := func(a Any, k uint) { if k == reader { nR++ rR++ } else { // writer nW++ rR = 0 } } l := func(a Any, k uint) { if k == reader { nR-- } else { // writer nW-- } } s = cs.New(2, c, e, l) return &ImpB{s} }
func NewCS2() *ImpCS2 { // var s cs.CriticalSection var nR, nW uint c := func(k uint) bool { if k == reader { return nW == 0 && !s.Blocked(writer) } return nR == 0 && nW == 0 // writer } e := func(a Any, k uint) { if k == reader { nR++ } else { // writer nW = 1 } } l := func(a Any, k uint) { if k == reader { nR-- } else { // writer nW = 0 } } s = cs.New(2, c, e, l) return &ImpCS2{s} }
func NewB(l, r uint) *ImpB { // if l == 0 { l = ker.MaxNat } if r == 0 { r = ker.MaxNat } var nL, nR, rL, rR, zL, zR uint var s cs.CriticalSection c := func(k uint) bool { if k == left { return nR == 0 && (!s.Blocked(right) || rL < zL) } return nL == 0 && (!s.Blocked(left) || rR < zR) // right } e := func(A Any, k uint) { if k == left { nL++ rL++ rR = 0 } else { // right nR++ rR++ rL = 0 } } a := func(A Any, k uint) { if k == left { nL-- } else { // right nR-- } } zL, zR = l, r s = cs.New(2, c, e, a) return &ImpB{s} }