int main( int argc, char *argv[] ) { Huint mid; Huint sta; // Set the mutexes to fast locking semantics setkind( HTHREAD_MUTEX_ERRORCHECK_NP ); // Print out a banner for the first attempt printf( "----------------------------------------------------------------------\n" ); printf( "- Error Lock: First Lock Attempt -\n" ); printf( "----------------------------------------------------------------------\n" ); // Lock all of the mutexes for( mid = 0; mid < MUTEX_MAX; mid++ ) { // Attempt to acquire the mutex for thread id 0 sta = _mutex_acquire( 0, mid ); // Print out the status information that was returned printf( "LOCK: (MID=%d) (STA=0x%8.8x)\n", mid, sta ); } // Print out a banner for the second attempt printf( "----------------------------------------------------------------------\n" ); printf( "- Error Lock: Second Lock Attempt -\n" ); printf( "----------------------------------------------------------------------\n" ); // Try to lock all of the mutexes again for( mid = 0; mid < MUTEX_MAX; mid++ ) { // Attempt to acquire the mutex for thread id 0 sta = _mutex_acquire( 0, mid ); // Print out the status information that was returned printf( "LOCK: (MID=%d) (STA=0x%8.8x)\n", mid, sta ); } // Finish the program printf( "-- QED --\n" ); return 1; }
void lock( void ) { Huint mid; Huint sta; // Lock all of the mutexes for( mid = 0; mid < MUTEX_MAX; mid++ ) { // Attempt to acquire the mutex for thread id 0 sta = _mutex_acquire( mid, mid ); // Print out the status information that was returned //printf( "LOCK: (MID=%d) (STA=0x%8.8x)\n", mid, sta ); } }
/** \internal * \brief Acquire a mutex lock. * * \author Wesley Peck <*****@*****.**> * * This function is used to acquire a lock for the given mutex. * * \param mutex The mutex to acquire the lock for. */ Hint _syscall_mutex_lock( hthread_mutex_t *mutex ) { Huint cur; Hint sta; // Print out a trace message about this system call TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL: (OP=LOCK) (MTX=%d)\n", (Huint)mutex->num ); cur = _current_thread(); sta = _mutex_acquire( cur, mutex->num ); // Print out a trace message about this system call TRACE_PRINTF( TRACE_FINE, TRACE_SYSCALL, "SYSCALL DONE: (OP=LOCK) (MTX=%d) (CUR=%u) (STA=%8.8X)\n", (Huint)mutex->num, cur, sta ); if( sta == HT_MUTEX_BLOCK ) { _run_sched( Htrue ); return SUCCESS; } if( sta == SUCCESS ) return SUCCESS; else return FAILURE; }