Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Schedule an event for a _relative_ time in the future.
- //
- EventId
- MultiThreadedSimulatorImpl::Schedule (Time const &time, EventImpl *event)
- {
- Ptr<MultiThreadingPartition> partition = GetCurrentMultiThreadingPartition ();
- Time tAbsolute = time + partition->Now ();
- fprintf (stderr, "Schedule %u time : %lu current %lu\n", partition->GetPartitionId (), tAbsolute.GetHighPrecision ().GetInteger (), partition->GetCurrentTs ());
- fflush (stderr);
- NS_ASSERT (tAbsolute.IsPositive ());
- NS_ASSERT (tAbsolute >= partition->Now ());
- Scheduler::Event ev;
- ev.impl = event;
- ev.key.m_ts = (uint64_t) tAbsolute.GetTimeStep ();
- ev.key.m_context = partition->GetPartitionId ();
- pthread_mutex_lock (&m_uidLock);
- ev.key.m_uid = m_uid;
- m_uid++;
- pthread_mutex_unlock (&m_uidLock);
- partition->Schedule (ev);
- return EventId (event, ev.key.m_ts, ev.key.m_context, ev.key.m_uid);
- }
- //
- // Schedule an event with the given context to occur at the given _absolute_ time.
- //
- EventId
- MultiThreadedSimulatorImpl::ScheduleWithContext (uint32_t context, Time const &time, EventImpl *event)
- {
- MultiThreadingPartitions::iterator it = m_partitions.find (context);
- NS_ASSERT ((m_running && it != m_partitions.end ()) || !m_running);
- Ptr<MultiThreadingPartition> partition;
- if (it != m_partitions.end ())
- {
- partition = it->second;
- }
- Scheduler::Event ev;
- ev.impl = event;
- ev.key.m_ts = (uint64_t) time.GetTimeStep ();
- ev.key.m_context = context;
- pthread_mutex_lock (&m_uidLock);
- ev.key.m_uid = m_uid;
- m_uid++;
- pthread_mutex_unlock (&m_uidLock);
- if (partition)
- {
- fprintf (stderr, "Scheduling...\n");
- fflush (stderr);
- partition->Schedule (ev);
- fprintf (stderr, "ScheduleWithContext %u time : %lu, current at %lu, current here %lu\n", context, time.GetHighPrecision ().GetInteger (), partition->Now ().GetHighPrecision ().GetInteger (), Now ().GetHighPrecision ().GetInteger ());
- NS_ASSERT (time.GetHighPrecision ().GetInteger () >= partition->Now ().GetHighPrecision ().GetInteger ());
- fflush (stderr);
- }
- else
- {
- fprintf (stderr, "ScheduleWithContext %u time : %lu, current 0\n", context, time.GetHighPrecision ().GetInteger ());
- fflush (stderr);
- TargettedEventMessage tmsg (context, ev);
- m_initialMessages.push (tmsg);
- }
- return EventId (event, ev.key.m_ts, ev.key.m_context, ev.key.m_uid);
- }
- EventId
- MultiThreadedSimulatorImpl::ScheduleNow (EventImpl *event)
- {
- Ptr<MultiThreadingPartition> partition = GetCurrentMultiThreadingPartition ();
- fprintf (stderr, "ScheduleNow %u time : %lu current : %lu\n", partition->GetPartitionId (), partition->GetCurrentTs (), partition->GetCurrentTs ());
- fflush (stderr);
- Scheduler::Event ev;
- ev.impl = event;
- ev.key.m_ts = partition->GetCurrentTs ();
- ev.key.m_context = partition->GetPartitionId ();
- pthread_mutex_lock (&m_uidLock);
- ev.key.m_uid = m_uid;
- m_uid++;
- pthread_mutex_unlock (&m_uidLock);
- partition->Schedule (ev);
- return EventId (event, ev.key.m_ts, ev.key.m_context, ev.key.m_uid);
- }
- EventId
- MultiThreadedSimulatorImpl::ScheduleDestroy (EventImpl *event)
- {
- EventId id (Ptr<EventImpl> (event, false), Now ().GetHighPrecision ().GetInteger (), 0xffffffff, 2);
- pthread_mutex_lock (&m_destroyEventsLock);
- m_destroyEvents.push_back (id);
- pthread_mutex_unlock (&m_destroyEventsLock);
- pthread_mutex_lock (&m_uidLock);
- m_uid++;
- pthread_mutex_unlock (&m_uidLock);
- return id;
- }
Add Comment
Please, Sign In to add comment