Beispiel #1
0
DLL_EXPORT int ptt_pthread_join(fthread_t tid, void **value, char *loc)
{
int result;
    PTTRACE ("join before", (void *)(uintptr_t)tid, value ? *value : NULL, loc, PTT_MAGIC);
    result = fthread_join(tid,value);
    PTTRACE ("join after", (void *)(uintptr_t)tid, value ? *value : NULL, loc, result);
    return result;
}
Beispiel #2
0
DLL_EXPORT int ptt_pthread_detach(fthread_t tid, char *loc)
{
int result;
    PTTRACE ("dtch before", (void *)(uintptr_t)tid, NULL, loc, PTT_MAGIC);
    result = fthread_detach(tid);
    PTTRACE ("dtch after", (void *)(uintptr_t)tid, NULL, loc, result);
    return result;
}
Beispiel #3
0
DLL_EXPORT int ptt_pthread_rwlock_trywrlock(RWLOCK *rwlock, char *loc)
{
int result;
    PTTRACE ("trywr before", rwlock, NULL, loc, PTT_MAGIC);
    result = pthread_rwlock_trywrlock(rwlock);
    PTTRACE ("trywr after", rwlock, NULL, loc, result);
    return result;
}
Beispiel #4
0
DLL_EXPORT int ptt_pthread_cond_wait(COND *cond, LOCK *mutex, char *loc)
{
int result;
    PTTRACE ("wait before", mutex, cond, loc, PTT_MAGIC);
    result = fthread_cond_wait(cond, mutex);
    PTTRACE ("wait after", mutex, cond, loc, result);
    return result;
}
Beispiel #5
0
DLL_EXPORT int ptt_pthread_mutex_trylock(LOCK *mutex, char *loc)
{
int result;
    PTTRACE ("try before", mutex, NULL, loc, PTT_MAGIC);
    result = fthread_mutex_trylock(mutex);
    PTTRACE ("try after", mutex, NULL, loc, result);
    return result;
}
Beispiel #6
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_detach_thread( TID tid, const char* location )
{
    int rc;
    PTTRACE( "dtch before", (void*) tid, NULL, location, PTT_MAGIC );
    rc = hthread_detach( tid );
    PTTRACE( "dtch after", (void*) tid, NULL, location, rc );
    return rc;
}
Beispiel #7
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_join_thread( TID tid, void** prc, const char* location )
{
    int rc;
    PTTRACE( "join before", (void*) tid, prc ? *prc : NULL, location, PTT_MAGIC );
    rc = hthread_join( tid, prc );
    PTTRACE( "join after",  (void*) tid, prc ? *prc : NULL, location, rc );
    return rc;
}
Beispiel #8
0
DLL_EXPORT int ptt_pthread_cond_timedwait(COND *cond, LOCK *mutex,
                                struct timespec *time, char *loc)
{
int result;
    PTTRACE ("tw before", mutex, cond, loc, PTT_MAGIC);
    result = fthread_cond_timedwait(cond, mutex, time);
    PTTRACE ("tw after", mutex, cond, loc, result);
    return result;
}
Beispiel #9
0
DLL_EXPORT int ptt_pthread_mutex_lock(LOCK *mutex, char *loc)
{
int result;

    PTTRACE ("lock before", mutex, NULL, loc, PTT_MAGIC);
    result = fthread_mutex_lock(mutex);
    if (result == EDEADLK)
        logmsg("\n          ++++++++++++++++ DEADLOCK! %s ++++++++++++++++\n\n",loc);
    PTTRACE ("lock after", mutex, NULL, loc, result);
    return result;
}
Beispiel #10
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_try_obtain_rdlock( RWLOCK* plk, const char* location )
{
    int rc;
    ILOCK* ilk;
    ilk = (ILOCK*) plk->ilk;
    PTTRACE( "tryrd before", plk, NULL, location, PTT_MAGIC );
    rc = hthread_rwlock_tryrdlock( &ilk->rwlock );
    PTTRACE( "tryrd after", plk, NULL, location, rc );
    if (rc && EBUSY != rc)
        loglock( ilk, rc, "try_obtain_rdlock", location );
    return rc;
}
Beispiel #11
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_wait_condition( COND* plc, LOCK* plk, const char* location )
{
    int rc;
    ILOCK* ilk;
    ilk = (ILOCK*) plk->ilk;
    PTTRACE( "wait before", plk, plc, location, PTT_MAGIC );
    rc = hthread_cond_wait( plc, &ilk->lock );
    PTTRACE( "wait after", plk, plc, location, rc );
    if (rc)
        loglock( ilk, rc, "wait_condition", location );
    return rc;
}
Beispiel #12
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_timed_wait_condition( COND* plc, LOCK* plk,
                                              const struct timespec* tm,
                                              const char* location )
{
    int rc;
    ILOCK* ilk;
    ilk = (ILOCK*) plk->ilk;
    PTTRACE( "tw before", plk, plc, location, PTT_MAGIC );
    rc = hthread_cond_timedwait( plc, &ilk->lock, tm );
    PTTRACE( "tw after", plk, plc, location, rc );
    if (rc && ETIMEDOUT != rc)
        loglock( ilk, rc, "timed_wait_condition", location );
    return rc;
}
Beispiel #13
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_obtain_wrlock( RWLOCK* plk, const char* location )
{
    int rc;
    U64 waitdur;
    ILOCK* ilk;
    TIMEVAL tv;
    ilk = (ILOCK*) plk->ilk;
    PTTRACE( "wrlock before", plk, NULL, location, PTT_MAGIC );
    rc = hthread_rwlock_trywrlock( &ilk->rwlock );
    if (EBUSY == rc)
    {
        waitdur = host_tod();
        rc = hthread_rwlock_wrlock( &ilk->rwlock );
        gettimeofday( &tv, NULL );
        waitdur = host_tod() - waitdur;
    }
    else
    {
        gettimeofday( &tv, NULL );
        waitdur = 0;
    }
    PTTRACE2( "wrlock after", plk, (void*) waitdur, location, rc, &tv );
    if (rc)
        loglock( ilk, rc, "obtain_wrlock", location );
    if (!rc || EOWNERDEAD == rc)
    {
        hthread_mutex_lock( &ilk->locklock );
        ilk->location = location;
        ilk->tid = hthread_self();
        memcpy( &ilk->time, &tv, sizeof( TIMEVAL ));
        hthread_mutex_unlock( &ilk->locklock );
    }
    return rc;
}
Beispiel #14
0
DLL_EXPORT int ptt_pthread_cond_signal(COND *cond, char *loc)
{
int result;
    result = fthread_cond_signal(cond);
    PTTRACE ("signal", NULL, cond, loc, result);
    return result;
}
Beispiel #15
0
DLL_EXPORT int ptt_pthread_mutex_unlock(LOCK *mutex, char *loc)
{
int result;
    result = fthread_mutex_unlock(mutex);
    PTTRACE ("unlock", mutex, NULL, loc, result);
    return result;
}
Beispiel #16
0
DLL_EXPORT int ptt_pthread_rwlock_unlock(RWLOCK *rwlock, char *loc)
{
int result;
    result = pthread_rwlock_unlock(rwlock);
    PTTRACE ("rwunlock", rwlock, NULL, loc, result);
    return result;
}
Beispiel #17
0
DLL_EXPORT int ptt_pthread_cond_broadcast(COND *cond, char *loc)
{
int result;
    result = fthread_cond_broadcast(cond);
    PTTRACE ("broadcast", NULL, cond, loc, result);
    return result;
}
Beispiel #18
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_broadcast_condition( COND* plc, const char* location )
{
    int rc;
    rc = hthread_cond_broadcast( plc );
    PTTRACE( "broadcast", NULL, plc, location, rc );
    return rc;
}
Beispiel #19
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_signal_thread( TID tid, int sig, const char* location )
{
    int rc;
    PTTRACE( "kill", (void*) tid, (void*)(long)sig, location, PTT_MAGIC );
    rc = hthread_kill( tid, sig );
    return rc;
}
Beispiel #20
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_signal_condition( COND* plc, const char* location )
{
    int rc;
    rc = hthread_cond_signal( plc );
    PTTRACE( "signal", NULL, plc, location, rc );
    return rc;
}
Beispiel #21
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_initialize_condition( COND* plc, const char* location )
{
    int rc;
    PTTRACE( "cond init", NULL, plc, location, PTT_MAGIC );
    rc = hthread_cond_init( plc );
    return rc;
}
Beispiel #22
0
DLL_EXPORT int ptt_pthread_create(fthread_t *tid, ATTR *attr,
                       PFT_THREAD_FUNC start, void *arg, char *nm, char *loc)
{
int result;
    result = fthread_create(tid, attr, start, arg, nm);
    PTTRACE ("create", (void *)(uintptr_t)(*tid), NULL, loc, result);
    return result;
}
Beispiel #23
0
DLL_EXPORT int ptt_pthread_create(pthread_t *tid, ATTR *attr,
                       void *(*start)(), void *arg, char *nm, char *loc)
{
int result;
    UNREFERENCED(nm);
    result = pthread_create(tid, attr, start, arg);
    PTTRACE ("create", (void *)*tid, NULL, loc, result);
    return result;
}
Beispiel #24
0
DLL_EXPORT int ptt_pthread_rwlock_wrlock(RWLOCK *rwlock, char *loc)
{
int result;
U64 s;
    PTTRACE ("wrlock before", rwlock, NULL, loc, PTT_MAGIC);
    result = pthread_rwlock_trywrlock(rwlock);
    if(result)
    {
        s = host_tod();
        result = pthread_rwlock_wrlock(rwlock);
        s = host_tod() - s;
        if (result == EDEADLK)
            logmsg("\n          ++++++++++++++++ DEADLOCK! %s ++++++++++++++++\n\n",loc);
    }
    else
        s = 0;
    PTTRACE ("wrlock after", rwlock, (void *) s, loc, result);
    return result;
}
Beispiel #25
0
DLL_EXPORT int ptt_pthread_mutex_lock(LOCK *mutex, char *loc)
{
int result;
U64 s;
    PTTRACE ("lock before", mutex, NULL, loc, PTT_MAGIC);
    result = pthread_mutex_trylock(mutex);
    if(result)
    {
        s = host_tod();
        result = pthread_mutex_lock(mutex);
        s = host_tod() - s;
        if (result == EDEADLK)
            logmsg("\n          ++++++++++++++++ DEADLOCK! %s ++++++++++++++++\n\n",loc);
    }
    else
        s = 0;
    PTTRACE ("lock after", mutex, (void *) s, loc, result);
    return result;
}
Beispiel #26
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_obtain_rdlock( RWLOCK* plk, const char* location )
{
    int rc;
    U64 waitdur;
    ILOCK* ilk;
    ilk = (ILOCK*) plk->ilk;
    PTTRACE( "rdlock before", plk, NULL, location, PTT_MAGIC );
    rc = hthread_rwlock_tryrdlock( &ilk->rwlock );
    if (EBUSY == rc)
    {
        waitdur = host_tod();
        rc = hthread_rwlock_rdlock( &ilk->rwlock );
        waitdur = host_tod() - waitdur;
    }
    else
        waitdur = 0;
    PTTRACE( "rdlock after", plk, (void*) waitdur, location, rc );
    if (rc)
        loglock( ilk, rc, "obtain_rdloc", location );
    return rc;
}
Beispiel #27
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);
}
Beispiel #28
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_release_rwlock( RWLOCK* plk, const char* location )
{
    int rc;
    ILOCK* ilk;
    ilk = (ILOCK*) plk->ilk;
    rc = hthread_rwlock_unlock( &ilk->rwlock );
    PTTRACE( "rwunlock", plk, NULL, location, rc );
    if (rc)
        loglock( ilk, rc, "release_rwlock", location );
    hthread_mutex_lock( &ilk->locklock );
    ilk->location = "null:0";
    ilk->tid = 0;
    hthread_mutex_unlock( &ilk->locklock );
    return rc;
}
Beispiel #29
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_create_thread( TID* ptid, ATTR* pat,
                                       THREAD_FUNC* pfn, void* arg,
                                       const char* name, const char* location )
{
    int rc;
    void** arg2;
    UNREFERENCED( name );               /* unref'ed on non-Windows   */
    pttthread = 1;                      /* Set a mark on the wall    */
    arg2 = malloc( 2 * sizeof( void* ));
    *(arg2+0) = (void*) pfn;
    *(arg2+1) = (void*) arg;
    rc = hthread_create( ptid, pat, hthread_func, arg2, name );
    PTTRACE( "create", (void*)*ptid, NULL, location, rc );
    return rc;
}
Beispiel #30
0
/*-------------------------------------------------------------------*/
DLL_EXPORT int  hthread_try_obtain_wrlock( RWLOCK* plk, const char* location )
{
    int rc;
    ILOCK* ilk;
    TIMEVAL tv;
    ilk = (ILOCK*) plk->ilk;
    PTTRACE( "trywr before", plk, NULL, location, PTT_MAGIC );
    rc = hthread_rwlock_trywrlock( &ilk->rwlock );
    gettimeofday( &tv, NULL );
    PTTRACE2( "trywr after", plk, NULL, location, rc, &tv );
    if (rc && EBUSY != rc)
        loglock( ilk, rc, "try_obtain_wrlock", location );
    if (!rc)
    {
        hthread_mutex_lock( &ilk->locklock );
        ilk->location = location;
        ilk->tid = hthread_self();
        memcpy( &ilk->time, &tv, sizeof( TIMEVAL ));
        hthread_mutex_unlock( &ilk->locklock );
    }
    return rc;
}