Пример #1
0
void setkind( Huint kind )
{
    Huint mid;

    // Set the kind for all of the mutexes
    for( mid = 0; mid < MUTEX_MAX; mid++ )
    {
        _mutex_setkind( mid, kind );
    }
}
Пример #2
0
/** \brief  Initialize a mutex object given a mutex attribute object.
  *
  * \author Wesley Peck <*****@*****.**>
  *
  * This function will initialize a mutex object given a mutex attribute
  * object. If the mutex attribute object is NULL then the default values
  * for the mutex will be used.
  *
  * This function must be called before any other mutex functions may be
  * used on the mutex object.
  *
  * \param mutex    This parameter is the mutex object which is going to
  *                 be initialized. This parameter should be a pointer to a
  *                 valid memory location.
  * \param attr     This parameter is the mutex attribute object which
  *                 contains the attributes to use with the given mutex
  *                 object.
  * \return         The return value is one of the following:
  *                 - HTHREAD_SUCCESS\n
  *                     The mutex object was successfully initialized.
  *                 - HTHREAD_FAILURE\n
  *                     The mutex object was not initialized and should not
  *                     be used in any other mutex operations.
  */
Hint hthread_mutex_init(hthread_mutex_t *mutex, const hthread_mutexattr_t *attr)
{
    if( attr == NULL )
    {
        mutex->num  = 0;
        mutex->type = HTHREAD_MUTEX_DEFAULT;
    }
    else
    {
        mutex->num  = attr->num;
        mutex->type = attr->type;
    }

    _mutex_setkind( mutex->num, mutex->type );
    return SUCCESS;
}
Пример #3
0
void run( Huint kind )
{
    Huint mid;
    Huint sta;

    // Print out a banner for the first attempt
    printf( "----------------------------------------------------------------------\n" );
    printf( "- Kind Lock: Set Kind                                                -\n" );
    printf( "----------------------------------------------------------------------\n" );

    // Lock all of the mutexes
    for( mid = 0; mid < MUTEX_MAX; mid++ )
    {
        // Attempt to acquire the mutex for thread id 0
        _mutex_setkind( mid, kind );

        // Print out the status information that was returned
        printf( "SET KIND: (MID=%d) (KND=0x%8.8x)\n", mid, kind );
    }

    // Print out a banner for the second attempt
    printf( "----------------------------------------------------------------------\n" );
    printf( "- Kind Lock: Read Back Kind                                          -\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_kind( mid );

        // Print out the status information that was returned
        printf( "KIND:     (MID=%d) (KND=0x%8.8x)\n", mid, sta );
    }
    
}