Пример #1
0
func applyBloodBankDiscipline(sys *BloodBankSystem, queue *qsim.Queue, trashProcessor, transfusionProcessor *qsim.Processor) {
	// Assigns the youngest unit to the processor
	assigner := func(cbProc *qsim.Processor, cbJob *qsim.Job) {
		var i, iYoungest int
		var j *qsim.Job
		if queue.Length() == 0 {
			qsim.D("Aborted after Job", cbJob)
			if sys.statsStarted {
				sys.NumAborted++
			}
			// Give the processor a dummy job until the next transfusion
			j = qsim.NewJob(-1)
			cbProc.Start(j)
			return
		}
		for i, j = range queue.Jobs {
			if j.ArrTime > queue.Jobs[iYoungest].ArrTime {
				iYoungest = i
			}
		}
		j = queue.Jobs[iYoungest]
		queue.Remove(j)
		cbProc.Start(j)
		qsim.D("Started Job", j)
	}

	transfusionProcessor.AfterFinish(assigner)
}