[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC 05/59] controller: Add WorkerParams argument to Init in Worker interface



From: George Dunlap <george.dunlap@xxxxxxxxxx>

For now just make it a plain []string; later make it more abstrcted.

Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>
---
 main.go          | 22 +++++++++++++++++-----
 processworker.go |  4 ++--
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/main.go b/main.go
index a4986cf..90388dd 100644
--- a/main.go
+++ b/main.go
@@ -14,9 +14,13 @@ type WorkerReport struct {
        MaxDelta int
 }
 
+type WorkerParams struct {
+       Args []string
+}
+
 type Worker interface {
        SetId(int)
-       Init() error
+       Init(WorkerParams) error
        Shutdown()
        Process(chan WorkerReport, chan bool)
 }
@@ -49,6 +53,14 @@ func Report(ws *WorkerState, r WorkerReport) {
        ws.LastReport = r
 }
 
+type WorkerList []WorkerState
+
+func (ws *WorkerList) Start(report chan WorkerReport, done chan bool) {
+       for i := range *ws {
+               go (*ws)[i].w.Process(report, done)
+       }
+}
+
 func main() {
        count := 2
        
@@ -60,17 +72,17 @@ func main() {
        
        i := 0
 
-       Workers := make([]WorkerState, count)
+       Workers := WorkerList(make([]WorkerState, count))
        
        for i = 0; i< count; i++ {
                Workers[i].w = &ProcessWorker{}
                Workers[i].w.SetId(i)
                
-               Workers[i].w.Init()
-               
-               go Workers[i].w.Process(report, done)
+               Workers[i].w.Init(WorkerParams{[]string{"burnwait", "20", 
"20000000"}})
        }
 
+       Workers.Start(report, done)
+
        for i > 0 {
                select {
                case r := <-report:
diff --git a/processworker.go b/processworker.go
index c1d1fd5..806e4d7 100644
--- a/processworker.go
+++ b/processworker.go
@@ -20,8 +20,8 @@ func (w *ProcessWorker) SetId(i int) {
        w.id = i
 }
 
-func (w *ProcessWorker) Init() (err error) {
-       w.c = exec.Command("../worker/worker-proc", "burnwait", "20", 
"20000000")
+func (w *ProcessWorker) Init(p WorkerParams) (err error) {
+       w.c = exec.Command("../worker/worker-proc", p.Args...)
 
        w.stdout, err = w.c.StdoutPipe()
        if err != nil {
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.