void* consumer( void *arg ) { Hint num; Hint tot; Hint val; hthread_t id; // Cast the argument to a buffer structure buffer_t *data; data = (buffer_t*)arg; // Get the thread id of this thread id = hthread_self(); // Print out that we are starting TRACE3_PRINTF( "CONSUMER %d: (OP=START)\n", (int)id ); num = 0; while( 1 ) { // Read a value out of the buffer tot = buffer_get( data, &val ); // Check if there was an error reading the value if( tot < -1 ) DEBUG_PRINTF( "ERROR: (OP=BUFFER GET) (STA=0x%8.8x)\n", tot ); // Check to see if we should exit if( tot == -1 ) break; // Print out a message TRACE4_PRINTF( "CONSUMER %d: (READ=%d) (TOT=%d) (NUM=%d)\n", (int)id, val, tot, num ); // Increment the number of values that we have read num += 1; } // Print out that we are exiting TRACE3_PRINTF( "CONSUMER %d: (OP=EXIT)\n", (int)id ); // Print out how many value that we consumed TRACE1_PRINTF( "CONSUMER %d: (OP=NUM) (VAL=%d)\n", (int)id, num ); // Return the number of items we produced return (void*)num; }
void* producer( void *arg ) { Hint num; Hint tot; hthread_t id; // Cast the argument to a buffer structure buffer_t *data; data = (buffer_t*)arg; // Get the thread id of this thread id = hthread_self(); // Print out that we are starting TRACE3_PRINTF( "PRODUCER: %d: (OP=START)\n", (int)id ); num = 0; while( 1 ) { // Add a value into the buffer tot = buffer_put( data, num ); // Check if there was an error adding the value if( tot < -1 ) DEBUG_PRINTF( "ERROR: (OP=BUFFER PUT) (STA=0x%8.8x)\n", tot ); // Check to see if we should exit if( tot == -1 ) break; // Print out a message TRACE4_PRINTF( "PRODUCER %d: (SENT=%d) (TOT=%d) (NUM=%d)\n", (int)id, num, tot, num ); // Increment the number of values that we have added num += 1; } // Print out that we are exiting TRACE3_PRINTF( "PRODUCER: %d: (OP=EXIT)\n", (int)id ); // Print out how many values that we consumed TRACE1_PRINTF( "PRODUCER: %d: (OP=NUM) (VAL=%d)\n", (int)id, num ); return (void*)num; }