Esempio n. 1
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;
    }
}
Esempio n. 2
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;
}
Esempio n. 3
0
/*-------------------------------------------------------------------*/
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);
}
Esempio n. 4
0
/*-------------------------------------------------------------------*/
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);
}
Esempio n. 5
0
/*-------------------------------------------------------------------*/
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;
}