aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlukechampine <luke.champine@gmail.com>2016-04-03 12:43:50 -0400
committerlukechampine <luke.champine@gmail.com>2016-04-03 12:43:50 -0400
commitc68fae8e1842534bc9709f7efc9bf1015251c5d5 (patch)
tree172427f0b9a32b0b549512a2bdba0feb54041f1f
parentadd TestPanic and TestReadWritten (diff)
downloadstm-c68fae8e1842534bc9709f7efc9bf1015251c5d5.tar.gz
stm-c68fae8e1842534bc9709f7efc9bf1015251c5d5.tar.xz
avoid using pointers as Vars
-rw-r--r--example_santa_test.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/example_santa_test.go b/example_santa_test.go
index aabe5ab..93de67f 100644
--- a/example_santa_test.go
+++ b/example_santa_test.go
@@ -42,7 +42,7 @@ type gate struct {
remaining *stm.Var
}
-func (g *gate) pass() {
+func (g gate) pass() {
stm.Atomically(func(tx *stm.Tx) {
rem := tx.Get(g.remaining).(int)
// wait until gate can hold us
@@ -51,7 +51,7 @@ func (g *gate) pass() {
})
}
-func (g *gate) operate() {
+func (g gate) operate() {
// open gate, reseting capacity
stm.AtomicSet(g.remaining, g.capacity)
// wait for gate to be full
@@ -61,8 +61,8 @@ func (g *gate) operate() {
})
}
-func newGate(capacity int) *gate {
- return &gate{
+func newGate(capacity int) gate {
+ return gate{
capacity: capacity,
remaining: stm.NewVar(0), // gate starts out closed
}
@@ -83,26 +83,26 @@ func newGroup(capacity int) *group {
}
}
-func (g *group) join() (g1, g2 *gate) {
+func (g *group) join() (g1, g2 gate) {
stm.Atomically(func(tx *stm.Tx) {
rem := tx.Get(g.remaining).(int)
// wait until the group can hold us
tx.Assert(rem > 0)
tx.Set(g.remaining, rem-1)
// return the group's gates
- g1 = tx.Get(g.gate1).(*gate)
- g2 = tx.Get(g.gate2).(*gate)
+ g1 = tx.Get(g.gate1).(gate)
+ g2 = tx.Get(g.gate2).(gate)
})
return
}
-func (g *group) await(tx *stm.Tx) (*gate, *gate) {
+func (g *group) await(tx *stm.Tx) (gate, gate) {
// wait for group to be empty
rem := tx.Get(g.remaining).(int)
tx.Assert(rem == 0)
// get the group's gates
- g1 := tx.Get(g.gate1).(*gate)
- g2 := tx.Get(g.gate2).(*gate)
+ g1 := tx.Get(g.gate1).(gate)
+ g2 := tx.Get(g.gate2).(gate)
// reset group
tx.Set(g.remaining, g.capacity)
tx.Set(g.gate1, newGate(g.capacity))
@@ -134,7 +134,7 @@ func spawnReindeer(g *group, id int) {
type selection struct {
task string
- gate1, gate2 *gate
+ gate1, gate2 gate
}
func chooseGroup(g *group, task string, s *selection) func(*stm.Tx) {