-
Notifications
You must be signed in to change notification settings - Fork 0
/
bottlingplant.cc
52 lines (44 loc) · 1.96 KB
/
bottlingplant.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "bottlingplant.h"
BottlingPlant::BottlingPlant( Printer & prt, NameServer & nameServer, unsigned int numVendingMachines,
unsigned int maxShippedPerFlavour, unsigned int maxStockPerFlavour, unsigned int timeBetweenShipments ):
printer(prt), nameServer(nameServer),
numVendingMachines(numVendingMachines), maxShippedPerFlavour(maxShippedPerFlavour),
maxStockPerFlavour(maxStockPerFlavour), timeBetweenShipments(timeBetweenShipments)
{ } // BottlingPlant::BottlingPlant
BottlingPlant::~BottlingPlant(){
delete truck;
printer.print(Printer::Kind::BottlingPlant, Finished);
}
void BottlingPlant::main(){
printer.print(Printer::Kind::BottlingPlant, Start);
truck = new Truck(printer, nameServer, *this, numVendingMachines, maxStockPerFlavour); // create truck;
// production run
yield(timeBetweenShipments); // yield between shipments, not including first production
while (!shutdown) {
_Accept (~BottlingPlant) {
shutdown = true;
_Accept(getShipment); // wait for truck to finish
bench.signal();
break;
}
or _Accept(getShipment){ // wait for truck to pickup shipment before starting next production run
int total = 0;
for (int i = 0; i < 4; i += 1){
production[i] = mprng(maxShippedPerFlavour);
total += production[i];
} // for
printer.print(Printer::Kind::BottlingPlant, Generating, total);
bench.signalBlock();
yield(timeBetweenShipments); // yield between shipments, not including first production
printer.print(Printer::Kind::BottlingPlant, Pickup);
} // Accept
}
} // BottlingPlant::main
void BottlingPlant::getShipment( unsigned int cargo[] ){
production = cargo;
bench.wait();
if (shutdown) {
_Throw Shutdown();
} // if
// copy production into cargo array
} // BottlingPlant::getShipment