CreateExecutionPool creates an ExecutionPool object for the given VM.
(vm *otto.Otto)
| 35 | |
| 36 | // CreateExecutionPool creates an ExecutionPool object for the given VM. |
| 37 | func CreateExecutionPool(vm *otto.Otto) *ExecutionPool { |
| 38 | p := &ExecutionPool{ |
| 39 | root: vm, |
| 40 | clones: make([]*VM, numVMInPool), |
| 41 | freeList: make([]int, numVMInPool), |
| 42 | freeWay: make(chan int, numVMInPool), |
| 43 | } |
| 44 | |
| 45 | for i := 0; i < numVMInPool; i++ { |
| 46 | p.freeList[i] = i |
| 47 | p.clones[i] = &VM{ |
| 48 | Otto: p.root.Copy(), |
| 49 | parent: p, |
| 50 | index: i, |
| 51 | } |
| 52 | // presignal a free object so the very first |
| 53 | // loop won't wait |
| 54 | p.freeWay <- i |
| 55 | } |
| 56 | |
| 57 | return p |
| 58 | } |
| 59 | |
| 60 | func (p *ExecutionPool) setFree(index int) { |
| 61 | p.freeWay <- index |