You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExecutiveProcess.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SNF4CGP/ExecutiveProcess.cpp
  2. // Copyright (C) 2009 ARM Research Labs, LLC.
  3. // See www.armresearch.com for more information.
  4. #include "ExecutiveProcess.hpp"
  5. #include "../CodeDweller/faults.hpp"
  6. #include <iostream>
  7. using namespace std;
  8. void ExecutiveProcess::initializeOutput() {
  9. Output.init(Jobs);
  10. }
  11. void ExecutiveProcess::initializeJobPool() {
  12. Jobs.init(ConfigInfo, Output);
  13. }
  14. void ExecutiveProcess::initializeWorkerPool() {
  15. Workers.init();
  16. }
  17. void ExecutiveProcess::shutdownWorkerPool() {
  18. Workers.stop();
  19. }
  20. void ExecutiveProcess::shutdownJobPool() {
  21. Jobs.stop();
  22. }
  23. void ExecutiveProcess::shutdownOutput() {
  24. Output.stop();
  25. }
  26. void ExecutiveProcess::dispatchCommand(Command& C) { // Job + Worker + Command; go!
  27. Job& J = Jobs.grab();
  28. J.setCommand(C);
  29. Worker& W = Workers.grab();
  30. W.doJob(J);
  31. }
  32. ExecutiveProcess::ExecutiveProcess(const string& Version, const string& Config) : // Simple construction.
  33. VersionInfo(Version),
  34. ConfigInfo(Config),
  35. QuitJobNumber(0) {}
  36. ExecutiveProcess::~ExecutiveProcess() { // Deal with uncerimoneous shutdowns.
  37. }
  38. void ExecutiveProcess::doStartup() { // Startup happens in this sequence.
  39. initializeJobPool();
  40. initializeOutput();
  41. initializeWorkerPool();
  42. }
  43. void ExecutiveProcess::dispatchWakeupCommand() {
  44. Command C;
  45. C.Type = Command::WAKE; // Create the WAKE command to announce
  46. C.Data = VersionInfo; // that we are alive (and who we are)
  47. dispatchCommand(C); // and dispatch a job with it.
  48. }
  49. void ExecutiveProcess::doProcessing() { // Command processing happens here.
  50. dispatchWakeupCommand(); // First job is to announce ourselves.
  51. for(;;) { // Then process all jobs but QUIT.
  52. Command C = Input.getCommand();
  53. switch(C.Type) {
  54. case Command::QUIT: {
  55. QuitJobNumber = C.Number;
  56. cout << "* SNF4CGP[" << C.Number << "] Received QUIT, shutting down..." << endl;
  57. cout.flush();
  58. return;
  59. }
  60. case Command::NOTGOOD: {
  61. cout << "* SNF4CGP Input stream has gone bad, shutting down..." << endl;
  62. cout.flush();
  63. return;
  64. }
  65. default: {
  66. dispatchCommand(C);
  67. }
  68. }
  69. }
  70. }
  71. void ExecutiveProcess::doShutdown() { // Shutdown happens in this sequence.
  72. shutdownWorkerPool();
  73. shutdownOutput();
  74. shutdownJobPool();
  75. cout << "* SNF4CGP Shutdown completed." << endl;
  76. if(0 < QuitJobNumber) {
  77. cout << QuitJobNumber << " OK" << endl;
  78. }
  79. cout.flush();
  80. }