sim_thread.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "sim_thread.h"
  2. #include "core_manager.h"
  3. #include "log.h"
  4. #include "simulator.h"
  5. #include "core.h"
  6. #include "sim_thread_manager.h"
  7. #include "sim_api.h"
  8. SimThread::SimThread()
  9. : m_thread(NULL)
  10. {
  11. }
  12. SimThread::~SimThread()
  13. {
  14. delete m_thread;
  15. }
  16. void SimThread::run()
  17. {
  18. core_id_t core_id = Sim()->getCoreManager()->registerSimThread(CoreManager::SIM_THREAD);
  19. // Set thread name for Sniper-in-Sniper simulations
  20. String threadName = String("sim-") + itostr(core_id);
  21. SimSetThreadName(threadName.c_str());
  22. LOG_PRINT("Sim thread starting...");
  23. Network *net = Sim()->getCoreManager()->getCoreFromID(core_id)->getNetwork();
  24. volatile bool cont = true;
  25. Sim()->getSimThreadManager()->simThreadStartCallback();
  26. // Turn off cont when we receive a quit message
  27. net->registerCallback(SIM_THREAD_TERMINATE_THREADS,
  28. terminateFunc,
  29. (void *)&cont);
  30. // Actual work gets done here
  31. while (cont)
  32. net->netPullFromTransport();
  33. Sim()->getSimThreadManager()->simThreadExitCallback();
  34. LOG_PRINT("Sim thread exiting");
  35. }
  36. void SimThread::spawn()
  37. {
  38. m_thread = _Thread::create(this);
  39. m_thread->run();
  40. }
  41. void SimThread::terminateFunc(void *vp, NetPacket pkt)
  42. {
  43. bool *pcont = (bool*) vp;
  44. *pcont = false;
  45. }