trick/trick_source/sim_services/Executive/Executive_thread_sync.cpp
Alex Lin e3759ac594 Move the loop that waits for scheduled threads to finish out of advance_sim_time #292
When we moved the thread sync code, a loop to clear all job complete flags was left out
causing unit test errors.
2016-08-29 08:42:53 -05:00

66 lines
2.3 KiB
C++

#include <iostream>
#include "trick/Executive.hh"
#include "trick/release.h"
/**
@design
-# Loop through all child threads
-# If the thread is asynchronous must finish and the next sync time matches the sim time
-# Wait for the thread to finish
-# Reset the thread queue of jobs
-# clear all job complete flags
-# If the thread is asynchronous and the thread is finished
-# If the thread has a cycle time advance the next sync time beyond the current time
by multiples of the cycle time.
-# Reset the thread queue of jobs
-# clear all job complete flags
-# Set the job complete flag for all jobs on thread 0.
*/
int Trick::Executive::thread_sync() {
unsigned int ii ;
/* Wait for async_must finish to complete at the current time_tics */
for (ii = 1; ii < threads.size() ; ii++) {
Threads * curr_thread = threads[ii] ;
if ( (curr_thread->process_type == PROCESS_TYPE_AMF_CHILD) &&
(curr_thread->amf_next_tics == time_tics )) {
while (curr_thread->child_complete == false ) {
if (rt_nap == true) {
RELEASE();
}
}
curr_thread->job_queue.reset_curr_index();
while ( (curr_job = curr_thread->job_queue.find_job(time_tics)) != NULL ) {
curr_job->complete = false;
}
}
else if ( curr_thread->process_type == PROCESS_TYPE_ASYNC_CHILD ) {
if ( curr_thread->child_complete == true ) {
if (curr_thread->amf_cycle_tics != 0 ) {
// catch up async next_tic time to a time greater than the time last pass
while ( curr_thread->amf_next_tics < time_tics ) {
curr_thread->amf_next_tics += curr_thread->amf_cycle_tics ;
}
}
curr_thread->job_queue.reset_curr_index();
while ( (curr_job = curr_thread->job_queue.find_job(time_tics)) != NULL ) {
curr_job->complete = false;
}
}
}
}
/* reset the job complete flags on thread 0 (master thread) */
threads[0]->job_queue.reset_curr_index();
while ( (curr_job = threads[0]->job_queue.find_job(time_tics)) != NULL ) {
curr_job->complete = false;
}
return(0) ;
}