void* _idle_thread( void *arg ) { while( 1 ) { // Print out a trace message about the idle thread TRACE5_PRINTF( "IDLE THREAD RUNNING\n" ); // Invoke the scheduler hthread_sched(); } // This statement should never be reached return NULL; }
int main( int argc, char *argv[] ) { Huint i; Huint j; Huint t; //clock_t s; //clock_t e; Huint sta; Huint prodcs; Huint consms; void *retval; hthread_t *consm; hthread_t *prodc; buffer_t buffers[ STREAMS ]; // Capture the start time //s = clock(); // Initialize the children information children_init( &consm, &prodc, &consms, &prodcs ); // Create the bounded buffers TRACE2_PRINTF( "Initializing Streams...\n" ); for( i = 0; i < STREAMS; i++ ) { // Attempt the initialize the buffer sta = buffer_init( &buffers[i], STREAM_SIZES[i], STREAM_ENDS[i] ); // Check if there was an error during initialization if( sta < 0 ) DEBUG_PRINTF( "ERROR: (OP=BUFFER INIT) (STA=0x%8.8x)\n", sta ); } // Initialize the tid counter t = 0; // Create the consumers for each buffer TRACE2_PRINTF( "Initializing Consumers...\n" ); for( i = 0; i < STREAMS; i++ ) { for( j = 0; j < STREAM_CONSM[i]; j++ ) { // Attempt to create the consumer sta = create_consumer( &buffers[i], &consm[t++] ); TRACE5_PRINTF( "CONSUMER ID: %d\n", (int)consm[t-1] ); // Check if there was an error during initialization if( sta < 0 ) DEBUG_PRINTF( "ERROR: (OP=CONSUMER) (STA=0x%8.8x)\n", sta ); } } // Initialize the tid counter t = 0; // Create the producers for each buffer TRACE2_PRINTF( "Initializing Producers...\n" ); for( i = 0; i < STREAMS; i++ ) { for( j = 0; j < STREAM_PRODC[i]; j++ ) { // Attempt to create the consumer sta = create_producer( &buffers[i], &prodc[t++] ); TRACE5_PRINTF( "PRODUCER ID: %d\n", (int)prodc[t-1] ); // Check if there was an error during initialization if( sta < 0 ) DEBUG_PRINTF( "ERROR: (OP=PRODUCER) (STA=0x%8.8x)\n", sta ); } } // Join all of the producers TRACE2_PRINTF( "Waiting for Producers...\n" ); for( i = 0; i < prodcs; i++ ) { // Join the producer sta = hthread_join( prodc[i], &retval ); // Check if there was an error during initialization if( sta != 0 ) DEBUG_PRINTF( "ERROR: (OP=JOIN) (STA=0x%8.8x)\n", sta ); // Print out its return value printf( "PRODUCER %d: %d values produced\n", i, (Huint)retval ); } // Join all of the consumers TRACE2_PRINTF( "Waiting for Consumers...\n" ); for( i = 0; i < consms; i++ ) { // Join the producer sta = hthread_join( consm[i], &retval ); // Check if there was an error during initialization if( sta != 0 ) DEBUG_PRINTF( "ERROR: (OP=JOIN) (STA=0x%8.8x)\n", sta ); // Print out its return value printf( "CONSUMER %d: %d values consumed\n", i, (Huint)retval ); } // Capture the end time //e = clock(); //printf( "Start Time: %ld\n", (long)s ); //printf( "End Time: %ld\n", (long)e ); // Print out a message that we are done printf( "-- QED --\n" ); // Exit the program return 0; }