| 1 | package process |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "sync" |
| 6 | ) |
| 7 | |
| 8 | var ( |
| 9 | pidLock sync.Mutex |
| 10 | pid uint64 |
| 11 | ) |
| 12 | |
| 13 | func nextPid() uint64 { |
| 14 | pidLock.Lock() |
| 15 | defer pidLock.Unlock() |
| 16 | pid++ |
| 17 | return pid |
| 18 | } |
| 19 | |
| 20 | //TODO(jdef) add lifecycle funcs |
| 21 | //TODO(jdef) add messaging funcs |
| 22 | type Process struct { |
| 23 | label string |
| 24 | } |
| 25 | |
| 26 | func New(kind string) *Process { |
| 27 | return &Process{ |
| 28 | label: fmt.Sprintf("%s(%d)", kind, nextPid()), |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func (p *Process) Label() string { |
| 33 | return p.label |
| 34 | } |