예제 #1
0
int main( int argc, char *argv[] )
{
	hthread_t           tid[ CHILDREN ];
    hthread_mutex_t     mutex;
    hthread_mutexattr_t attr;
    Huint               i;

    hthread_mutexattr_init( &attr );
    hthread_mutexattr_settype( &attr, HTHREAD_MUTEX_FAST_NP );
    hthread_mutexattr_setnum( &attr, 1 );
    hthread_mutex_init( &mutex, &attr );
    
    for( i = 0; i < CHILDREN; i++ )
    {
        hthread_create( &tid[i], NULL, child, &mutex );
    }
    
    for( i = 0; i < CHILDREN; i++ )
    {
   	    hthread_join( tid[i], NULL );
    }

	printf( "--DONE--\n" );
	return 1;
}
예제 #2
0
/*-------------------------------------------------------------------*/
DLL_EXPORT void ptt_trace_init( int n, int init )
{
    if (n > 0)
        pttrace = calloc( n, PTT_TRACE_SIZE );
    else
        pttrace = NULL;

    pttracen = pttrace ? n : 0;
    pttracex = 0;

    if (init)       /* First time? */
    {
        int rc;
        MATTR attr;
        if ((rc = hthread_mutexattr_init( &attr )) != 0)
            BREAK_INTO_DEBUGGER();
        if ((rc = hthread_mutexattr_settype( &attr, HTHREAD_MUTEX_DEFAULT )) != 0)
            BREAK_INTO_DEBUGGER();
        if ((rc = hthread_mutex_init( &pttlock, &attr )) != 0)
            BREAK_INTO_DEBUGGER();
        if ((rc = hthread_mutex_init( &ptttolock, &attr )) != 0)
            BREAK_INTO_DEBUGGER();
        if ((rc = hthread_cond_init( &ptttocond )) != 0)
            BREAK_INTO_DEBUGGER();
        if ((rc = hthread_mutexattr_destroy( &attr )) != 0)
            BREAK_INTO_DEBUGGER();
        pttnolock = 0;
        pttnotod  = 0;
        pttnowrap = 0;
        pttto     = 0;
        ptttotid  = 0;
    }
}
예제 #3
0
int main(int argc, char *argv[]) {
    hthread_mutexattr_t mutexAttr;
    hthread_mutex_t     mutex;
	hthread_attr_t      threadAttr;
    hthread_t           thread;
	Huint               arg;
	log_t               log;

    //Initialize Log
	log_create( &log, 1024 );

	//Mutex operations
	printf( "Starting mutex operations\n" );
	hthread_mutexattr_init( &mutexAttr );
	hthread_mutexattr_setnum( &mutexAttr, 0 );
	hthread_mutexattr_getnum( &mutexAttr, &arg );
	hthread_mutexattr_destroy( &mutexAttr );

    hthread_mutex_init(&mutex, NULL);
	hthread_mutex_lock( &mutex );
	hthread_mutex_unlock( &mutex );

	hthread_mutex_trylock( &mutex );
	hthread_mutex_unlock( &mutex );
	hthread_mutex_destroy( &mutex );

    //Condition Variable operations
	/*
	printf( "Starting condition variable operations\n" );
	hthread_condattr_init( &condvarAttr );
	hthread_condattr_setnum( &condvarAttr, 0 );
	hthread_condattr_getnum( &condvarAttr, &arg );
	hthread_condattr_destroy( &condvarAttr );

	hthread_cond_init( &condvar, NULL );
	hthread_mutex_lock( &mutex );
	hthread_cond_wait( &condvar, &mutex );
	hthread_mutex_unlock( &mutex );
	hthread_cond_signal( &condvar );
	hthread_cond_broadcast( &condvar );
	hthread_cond_destroy( &condvar );
	*/

    //Thread operations
	printf( "Starting thread operations\n" );
	hthread_attr_init( &threadAttr );
    hthread_create( &thread, &threadAttr, foo, &log );
	hthread_attr_destroy( &threadAttr );

	hthread_join( thread, NULL );

    printf( " -- End of Program --\n" );
	log_close_ascii( &log );

	return 0;
}
예제 #4
0
void * testThread ( void * arg ) {
	int retVal;
	hthread_mutexattr_t * attr = (hthread_mutexattr_t *) arg;
	
	//Initialize an attribute, and check the return value
	retVal = hthread_mutexattr_init( attr );
	
	hthread_exit( (void *) retVal );
	return NULL;
}
예제 #5
0
파일: hthreads.c 프로젝트: herrold/hyperion
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_initialize_rwlock( RWLOCK* plk, const char* name,
                                           const char* location )
{
    int     rc;
    RWATTR  attr1;    /* for primary lock */
    MATTR   attr2;    /* for internal locklock */
    ILOCK*  ilk = hthreads_get_ILOCK( plk, name );

    /* Initialize the requested lock */

    rc = hthread_rwlockattr_init( &attr1 );
    if (rc)
        goto fatal;

    rc = hthread_mutexattr_init( &attr2 );
    if (rc)
        goto fatal;

    rc = hthread_rwlockattr_setpshared( &attr1, HTHREAD_RWLOCK_DEFAULT );
    if (rc)
        goto fatal;

    rc = hthread_mutexattr_settype( &attr2, HTHREAD_MUTEX_DEFAULT );
    if (rc)
        goto fatal;

    rc = hthread_rwlock_init( &ilk->rwlock, &attr1 );
    if (rc)
        goto fatal;

    rc = hthread_mutex_init( &ilk->locklock, &attr2 );
    if (rc)
        goto fatal;

    rc = hthread_rwlockattr_destroy( &attr1 );
    if (rc)
        goto fatal;

    rc = hthread_mutexattr_destroy( &attr2 );
    if (rc)
        goto fatal;

    plk->ilk = ilk;     /* (RWLOCK is now initialized) */
    PTTRACE( "rwlock init", plk, &attr1, location, PTT_MAGIC );
    return 0;

fatal:

    perror( "Fatal error in hthread_initialize_rwlock function" );
    exit(1);
}
예제 #6
0
void * testThread ( void * arg ) {
	int retVal;
	struct test_data * data = (struct test_data *) arg;
	
	//Initialize a mutexattr, then a mutex with the attr
	hthread_mutexattr_init( data->attr );
	hthread_mutex_init( data->mutex, data->attr );
	
	//Change the attr 
	data->attr->num = 1;
	
	//Get the num of the mutex, it should not have changed
	retVal = hthread_mutex_getnum( data->mutex );
	
	hthread_exit( (void *) retVal );
	return NULL;
}
예제 #7
0
파일: hthreads.c 프로젝트: herrold/hyperion
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_initialize_lock( LOCK* plk, const char* name,
                                         const char* location )
{
    int     rc;
    MATTR   attr;
    ILOCK*  ilk = hthreads_get_ILOCK( plk, name );

    /* Initialize the requested lock */

    rc = hthread_mutexattr_init( &attr );
    if (rc)
        goto fatal;

    rc = hthread_mutexattr_settype( &attr, HTHREAD_MUTEX_DEFAULT );
    if (rc)
        goto fatal;

    rc = hthread_mutex_init( &ilk->locklock, &attr );
    if (rc)
        goto fatal;

    rc = hthread_mutex_init( &ilk->lock, &attr );
    if (rc)
        goto fatal;

    rc = hthread_mutexattr_destroy( &attr );
    if (rc)
        goto fatal;

    plk->ilk = ilk; /* (LOCK is now initialized) */
    PTTRACE( "lock init", plk, 0, location, PTT_MAGIC );
    return 0;

fatal:

    perror( "Fatal error in hthread_initialize_lock function" );
    exit(1);
}
예제 #8
0
int main( int argc, char *argv[] )
{
	hthread_t           tid[ CHILDREN ];
    hthread_mutex_t     mutex[ MUTEXES ];
    hthread_mutexattr_t attr;
    Huint               i;
    Huint               j;
    Huint               c;

    hthread_mutexattr_init( &attr );
    hthread_mutexattr_settype( &attr, HTHREAD_MUTEX_FAST_NP );
    
    c = 0;
    for( i = 0; i < MUTEXES; i++ )
    {
        hthread_mutexattr_setnum( &attr, i );
        hthread_mutex_init( &mutex[i], &attr );
        
        for( j = 0; j < CHILDREN_PER_MUTEX; j++ )
        {
            hthread_create( &tid[c], NULL, child, &mutex[i] );
            printf( "Created Child %u\n", tid[c] );

            c++;
        }
    }
    
    for( i = 0; i < CHILDREN; i++ )
    {
        printf( "Join Child %u\n", tid[i] );
   	    hthread_join( tid[i], NULL );
    }
    
	printf( "--DONE--\n" );
	return 1;
}
예제 #9
0
파일: hthreads.c 프로젝트: herrold/hyperion
/*-------------------------------------------------------------------*/
static void hthreads_internal_init()
{
    static BYTE bDidInit = FALSE;

    if (!bDidInit)
    {
    MATTR attr;
    int rc, herc_high_pri, host_high_pri;

        /* Initialize our internal lock */

        rc = hthread_mutexattr_init( &attr );
        if (rc)
            goto fatal;

        rc = hthread_mutexattr_settype( &attr, HTHREAD_MUTEX_DEFAULT );
        if (rc)
            goto fatal;

        rc = hthread_mutex_init( &listlock, &attr );
        if (rc)
            goto fatal;

        rc = hthread_mutexattr_destroy( &attr );
        if (rc)
            goto fatal;

        /* Initialize our locks list anchor */

        InitializeListHead( &locklist );
        lockcount = 0;

        /* Initialize thread scheduling variables */

        herc_policy = HTHREAD_SCHED_DEF;

        herc_low_pri  = HTHREAD_MIN_PRI;
        herc_high_pri = HTHREAD_MAX_PRI;

        host_low_pri  = hthread_sched_get_priority_min( herc_policy );
        host_high_pri = hthread_sched_get_priority_max( herc_policy );

        herc_pri_rvrsd = (herc_high_pri < herc_low_pri);
        host_pri_rvrsd = (host_high_pri < host_low_pri);

        herc_pri_amt = herc_pri_rvrsd ? (herc_low_pri - herc_high_pri)
                                      : (herc_high_pri - herc_low_pri);

        host_pri_amt = host_pri_rvrsd ? (host_low_pri - host_high_pri)
                                      : (host_high_pri - host_low_pri);

        /* One-time initialization completed */

        bDidInit = TRUE;
        return;

fatal:
        perror( "Fatal error in hthreads_internal_init function" );
        exit(1);
    }
    return;
}
// Initialize all of the PR data
void init_PR_data() {
    // Initialize the ICAP
    hthread_mutexattr_t attr;
    if (hthread_mutexattr_init(&attr)) {
        printf("Error intializing mutex attribute\n");
        while(1);
    }

    // Set MID to maximum ID allowed    
    if (hthread_mutexattr_setnum(&attr,(Huint) HT_SEM_MAXNUM)) {
        printf("Error setting MID (%u) for mutex attribute\n", HT_SEM_MAXNUM);
        while(1);
    }
    
    if(hthread_mutex_init(&icap_mutex, &attr)) {
        printf("error initializing icap mutex\n");
        while(1);
    }

    #ifdef ICAP
    // Initialize the ICAP
    if(XHwIcap_CfgInitialize(&HwIcap, (XHwIcap_Config *) 0x1, ICAP_BASEADDR)) {
        printf("Error initializing the ICAP\n");
        while(1);
    }

    // Initialize the pointers
    // init CRC
    crc_bit[0] = (unsigned char *) (&crc0_bit[0]);
    crc_bit[1] = (unsigned char *) (&crc1_bit[0]);
    crc_bit[2] = (unsigned char *) (&crc2_bit[0]);
    crc_bit[3] = (unsigned char *) (&crc3_bit[0]);
    crc_bit[4] = (unsigned char *) (&crc4_bit[0]);
    crc_bit[5] = (unsigned char *) (&crc5_bit[0]);

    // init sort
    sort_bit[0] = (unsigned char *) (&sort0_bit[0]);
    sort_bit[1] = (unsigned char *) (&sort1_bit[0]);
    sort_bit[2] = (unsigned char *) (&sort2_bit[0]);
    sort_bit[3] = (unsigned char *) (&sort3_bit[0]);
    sort_bit[4] = (unsigned char *) (&sort4_bit[0]);
    sort_bit[5] = (unsigned char *) (&sort5_bit[0]);
    
    // init vector
    vector_bit[0] = (unsigned char *) (&vector0_bit[0]);
    vector_bit[1] = (unsigned char *) (&vector1_bit[0]);
    vector_bit[2] = (unsigned char *) (&vector2_bit[0]);
    vector_bit[3] = (unsigned char *) (&vector3_bit[0]);
    vector_bit[4] = (unsigned char *) (&vector4_bit[0]);
    vector_bit[5] = (unsigned char *) (&vector5_bit[0]);

    // Create accelerate profiles - containers that hold
    // pointers to each accelerator specific for each slave.
    unsigned int i;
    for (i = 0; i < NUM_AVAILABLE_HETERO_CPUS; i++) { 
        set_accelerator_structure((accelerator_list_t *) &accelerator_list[i], i);

        // -------------------------------------------------------------- //
        //         Write extra parameters for PR functionality            //
        // -------------------------------------------------------------- //
        _hwti_set_accelerator_ptr((Huint) hwti_array[i], (Huint)&accelerator_list[i]);

        // Write the ICAP Mutex
        _hwti_set_icap_mutex( (Huint) hwti_array[i], (Huint) &icap_mutex);

        // Write the ICAP Data Strucutre
        _hwti_set_icap_struct_ptr( (Huint) hwti_array[i], (Huint) &HwIcap);

        // Write pointer for last_used_accelerator so slave can update the table
        _hwti_set_last_accelerator_ptr( (Huint) hwti_array[i], (Huint) &slave_table[i].last_used_acc);
            
        // Write pointer to tuning_table
        _hwti_set_tuning_table_ptr((Huint) hwti_array[i], (Huint) &tuning_table);

    }
    #endif
   
    // Reset thread create statistical data 
    no_free_slaves_num = 0;
    possible_slaves_num = 0;
    best_slaves_num = 0;
}