Guest User

Untitled

a guest
Jun 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. //
  2. // Schedule an event for a _relative_ time in the future.
  3. //
  4. EventId
  5. MultiThreadedSimulatorImpl::Schedule (Time const &time, EventImpl *event)
  6. {
  7. Ptr<MultiThreadingPartition> partition = GetCurrentMultiThreadingPartition ();
  8. Time tAbsolute = time + partition->Now ();
  9. fprintf (stderr, "Schedule %u time : %lu current %lu\n", partition->GetPartitionId (), tAbsolute.GetHighPrecision ().GetInteger (), partition->GetCurrentTs ());
  10. fflush (stderr);
  11.  
  12. NS_ASSERT (tAbsolute.IsPositive ());
  13. NS_ASSERT (tAbsolute >= partition->Now ());
  14. Scheduler::Event ev;
  15. ev.impl = event;
  16. ev.key.m_ts = (uint64_t) tAbsolute.GetTimeStep ();
  17. ev.key.m_context = partition->GetPartitionId ();
  18. pthread_mutex_lock (&m_uidLock);
  19. ev.key.m_uid = m_uid;
  20. m_uid++;
  21. pthread_mutex_unlock (&m_uidLock);
  22. partition->Schedule (ev);
  23. return EventId (event, ev.key.m_ts, ev.key.m_context, ev.key.m_uid);
  24. }
  25.  
  26. //
  27. // Schedule an event with the given context to occur at the given _absolute_ time.
  28. //
  29. EventId
  30. MultiThreadedSimulatorImpl::ScheduleWithContext (uint32_t context, Time const &time, EventImpl *event)
  31. {
  32. MultiThreadingPartitions::iterator it = m_partitions.find (context);
  33. NS_ASSERT ((m_running && it != m_partitions.end ()) || !m_running);
  34. Ptr<MultiThreadingPartition> partition;
  35. if (it != m_partitions.end ())
  36. {
  37. partition = it->second;
  38. }
  39.  
  40. Scheduler::Event ev;
  41. ev.impl = event;
  42. ev.key.m_ts = (uint64_t) time.GetTimeStep ();
  43. ev.key.m_context = context;
  44. pthread_mutex_lock (&m_uidLock);
  45. ev.key.m_uid = m_uid;
  46. m_uid++;
  47. pthread_mutex_unlock (&m_uidLock);
  48. if (partition)
  49. {
  50. fprintf (stderr, "Scheduling...\n");
  51. fflush (stderr);
  52. partition->Schedule (ev);
  53. fprintf (stderr, "ScheduleWithContext %u time : %lu, current at %lu, current here %lu\n", context, time.GetHighPrecision ().GetInteger (), partition->Now ().GetHighPrecision ().GetInteger (), Now ().GetHighPrecision ().GetInteger ());
  54. NS_ASSERT (time.GetHighPrecision ().GetInteger () >= partition->Now ().GetHighPrecision ().GetInteger ());
  55. fflush (stderr);
  56. }
  57. else
  58. {
  59. fprintf (stderr, "ScheduleWithContext %u time : %lu, current 0\n", context, time.GetHighPrecision ().GetInteger ());
  60. fflush (stderr);
  61. TargettedEventMessage tmsg (context, ev);
  62. m_initialMessages.push (tmsg);
  63. }
  64. return EventId (event, ev.key.m_ts, ev.key.m_context, ev.key.m_uid);
  65. }
  66.  
  67. EventId
  68. MultiThreadedSimulatorImpl::ScheduleNow (EventImpl *event)
  69. {
  70. Ptr<MultiThreadingPartition> partition = GetCurrentMultiThreadingPartition ();
  71. fprintf (stderr, "ScheduleNow %u time : %lu current : %lu\n", partition->GetPartitionId (), partition->GetCurrentTs (), partition->GetCurrentTs ());
  72. fflush (stderr);
  73. Scheduler::Event ev;
  74. ev.impl = event;
  75. ev.key.m_ts = partition->GetCurrentTs ();
  76. ev.key.m_context = partition->GetPartitionId ();
  77. pthread_mutex_lock (&m_uidLock);
  78. ev.key.m_uid = m_uid;
  79. m_uid++;
  80. pthread_mutex_unlock (&m_uidLock);
  81. partition->Schedule (ev);
  82. return EventId (event, ev.key.m_ts, ev.key.m_context, ev.key.m_uid);
  83. }
  84.  
  85. EventId
  86. MultiThreadedSimulatorImpl::ScheduleDestroy (EventImpl *event)
  87. {
  88. EventId id (Ptr<EventImpl> (event, false), Now ().GetHighPrecision ().GetInteger (), 0xffffffff, 2);
  89. pthread_mutex_lock (&m_destroyEventsLock);
  90. m_destroyEvents.push_back (id);
  91. pthread_mutex_unlock (&m_destroyEventsLock);
  92. pthread_mutex_lock (&m_uidLock);
  93. m_uid++;
  94. pthread_mutex_unlock (&m_uidLock);
  95. return id;
  96. }
Add Comment
Please, Sign In to add comment