Navigation Menu

Skip to content

Commit

Permalink
Don't think I need the locks
Browse files Browse the repository at this point in the history
  • Loading branch information
mrb committed Jan 6, 2013
1 parent a13f1bc commit adcc1a3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
6 changes: 4 additions & 2 deletions examples/syncasync/main.go
Expand Up @@ -49,8 +49,10 @@ func main() {
} }


func Starter(c syl.Channels, g syl.ControlChan) { func Starter(c syl.Channels, g syl.ControlChan) {
for cd := 0; cd < 100; cd++ { for { //
c.Data <- []byte{byte(cd)} for cd := 0; cd < 100; cd++ {
c.Data <- []byte{byte(cd)}
}
} }
c.Control.Exit() c.Control.Exit()
} }
Expand Down
10 changes: 0 additions & 10 deletions node.go
@@ -1,13 +1,5 @@
package sylvester package sylvester


import (
"sync"
)

var (
syncPositionMutex = &sync.Mutex{}
)

type Event func(Channels, ControlChan) type Event func(Channels, ControlChan)


type Node struct { type Node struct {
Expand Down Expand Up @@ -73,13 +65,11 @@ func (n *Node) StartSyncEvents() {
} }


func (n *Node) NextSyncEvent() { func (n *Node) NextSyncEvent() {
syncPositionMutex.Lock()
sp := n.syncPosition sp := n.syncPosition
if sp == (len(n.syncEvents) - 1) { if sp == (len(n.syncEvents) - 1) {
n.syncPosition = 0 n.syncPosition = 0
} else { } else {
n.syncPosition++ n.syncPosition++
} }
go n.syncEvents[n.syncPosition](*n.Channels, n.graph.Control) go n.syncEvents[n.syncPosition](*n.Channels, n.graph.Control)
syncPositionMutex.Unlock()
} }

0 comments on commit adcc1a3

Please sign in to comment.