From 19f52ebbf67ffb2f53d0445057ac27a624c3bef1 Mon Sep 17 00:00:00 2001 From: Shirou WAKAYAMA Date: Thu, 24 Apr 2014 18:41:46 +0900 Subject: [PATCH] use first-class funcs to fill Process information. --- process_linux.go | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/process_linux.go b/process_linux.go index 48a4e4c..e734d52 100644 --- a/process_linux.go +++ b/process_linux.go @@ -16,29 +16,25 @@ const ( PRIO_PROCESS = 0 // linux/resource.h ) +type fillFunc func(pid int32, p *Process) (error) + + func NewProcess(pid int32) (*Process, error) { p := &Process{ Pid: int32(pid), } + // Fill Process information from fillFuncs var wg sync.WaitGroup - wg.Add(4) - go func() { - wg.Done() - fillFromStat(pid, p) - }() - go func() { - defer wg.Done() - fillFromStatus(pid, p) - }() - go func() { - defer wg.Done() - go fillFromfd(pid, p) - }() - go func() { - defer wg.Done() - go fillFromCmdline(pid, p) - }() + funcs := []fillFunc{fillFromStat, fillFromStatus, fillFromfd, fillFromCmdline} + + wg.Add(len(funcs)) + for _, f := range funcs{ + go func(){ + wg.Done() + f(pid, p) + }() + } wg.Wait() /*