Skip to content

Commit

Permalink
Set GOMAXPROCS property in GobotMaster
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Dec 19, 2013
1 parent 05bdb70 commit 7aa1104
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion master.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package gobot

import "runtime"

type Master struct {
Robots []Robot
NumCPU int
}

func GobotMaster() *Master {
m := new(Master)
m.NumCPU = runtime.NumCPU()
return m
}

func (m *Master) Start() {
runtime.GOMAXPROCS(m.NumCPU)
for s := range m.Robots {
go m.Robots[s].Start()
go m.Robots[s].startRobot()
}
select {}
}
Expand Down
7 changes: 6 additions & 1 deletion robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ type Robot struct {
}

func (r *Robot) Start() {
m := GobotMaster()
m.Robots = []Robot{*r}
m.Start()
}

func (r *Robot) startRobot() {
r.initName()
r.initCommands()
r.initConnections()
Expand All @@ -27,7 +33,6 @@ func (r *Robot) Start() {
if r.Work != nil {
r.Work()
}
select {}
}

func (r *Robot) initName() {
Expand Down

0 comments on commit 7aa1104

Please sign in to comment.