Ignore:
Timestamp:
Oct 5, 2018, 12:21:52 AM (6 years ago)
Author:
alain
Message:

Cosmetic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libs/libpthread/pthread.c

    r477 r573  
    3131#include <syscalls_numbers.h>
    3232
    33 #define PTHREAD_MUTEX_DEBUG     0
    34 #define PTHREAD_BARRIER_DEBUG   1
     33#define PTHREAD_BARRIER_DEBUG   0
    3534
    3635////////////////////////////////////////////////////////////////////////////////////////////
     
    307306        if ( node->parent != NULL )  sqt_barrier_decrement( node->parent );
    308307
    309         // reset the current node
    310         node->sense = expected;
    311         node->count = node->arity;
    312 
    313308#if PTHREAD_BARRIER_DEBUG
    314309printf("\n[BARRIER] %s : core[%x,%d] reset SQT barrier node %x :\n"
     
    317312node->level , node->arity , node->sense , node->count );
    318313#endif
     314        // reset the current node
     315        node->sense = expected;
     316        node->count = node->arity;
     317
    319318        return;
    320319    }
     
    374373    }
    375374
    376     mutex->current = 0;
    377     mutex->free    = 0;
    378 
    379 #if PTHEAD_MUTEX_DEBUG
    380 unsigned int cxy;
    381 unsigned int lid;
    382 get_core( &cxy , &lid );
    383 printf("\n[MUTEX DEBUG] %s : core[%x,%d] initializes mutex %x\n",
    384 __FUNCTION__, cxy, lid, mutex );
    385 #endif
    386 
    387     return 0;
     375    return hal_user_syscall( SYS_MUTEX,
     376                             (reg_t)mutex,
     377                             MUTEX_INIT,
     378                             0, 0 );
     379}
     380
     381////////////////////////////////////////////////////
     382int pthread_mutex_destroy( pthread_mutex_t * mutex )
     383{
     384    return hal_user_syscall( SYS_MUTEX,
     385                             (reg_t)mutex,
     386                             MUTEX_DESTROY,
     387                             0, 0 );
    388388}
    389389
     
    391391int pthread_mutex_lock( pthread_mutex_t * mutex )
    392392{
    393     unsigned int          ticket;
    394 
    395     // get next free ticket
    396     ticket = (unsigned int)hal_user_atomic_add( (int *)&mutex->free, 1 );
    397 
    398 #if PTHREAD_MUTEX_DEBUG
    399 unsigned int cxy;
    400 unsigned int lid;
    401 get_core( &cxy , &lid );
    402 printf("\n[MUTEX DEBUG] %s : core[%x,%d] get ticket %d\n",
    403 " / mutex = %x / current = %d / free = %d\n",
    404 __FUNCTION__, cxy, lid, ticket, mutex, mutex->current, mutex->free );
    405 #endif
    406 
    407     // poll the current index
    408     while( 1 )
    409     {
    410         if( mutex->current == ticket) break;
    411     }
    412                
    413 #if PTHREAD_MUTEX_DEBUG
    414 printf("\n[MUTEX DEBUG] %s : core[%x,%d] get mutex %x / current = %d / free = %d\n",
    415 __FUNCTION__, cxy, lid, mutex, mutex->current, mutex->free );
    416 #endif
    417 
    418     return 0;
     393    return hal_user_syscall( SYS_MUTEX,
     394                             (reg_t)mutex,
     395                             MUTEX_LOCK,
     396                             0, 0 );
    419397}
    420398
     
    422400int pthread_mutex_trylock( pthread_mutex_t * mutex )
    423401{
    424     unsigned int          ticket;
    425 
    426     // get next free ticket
    427     ticket = (unsigned int)hal_user_atomic_add( (int *)&mutex->free, 1 );
    428 
    429 #if PTHREAD_MUTEX_DEBUG
    430 unsigned int    cxy;
    431 unsigned int    lid;
    432 get_core( &cxy, &lid );
    433 printf("\n[MUTEX DEBUG] %s : core[%x,%d] get ticket = %d"
    434 " / mutex = %x / current = %d / free = %d\n",
    435 __FUNCTION__, cxy, lid, ticket, mutex, mutex->current, mutex->free );
    436 #endif
    437 
    438     // test ticket
    439     if( ticket == mutex->current ) return 0;       // success
    440     else                           return -1;      // failure
     402    return hal_user_syscall( SYS_MUTEX,
     403                             (reg_t)mutex,
     404                             MUTEX_TRYLOCK,
     405                             0, 0 );
    441406}
    442407   
     
    444409int pthread_mutex_unlock( pthread_mutex_t * mutex )
    445410{
    446     hal_user_fence();
    447 
    448     mutex->current = mutex->current + 1;
    449 
    450 #if PTHREAD_MUTEX_DEBUG
    451 unsigned int    cxy;
    452 unsigned int    lid;
    453 get_core( &cxy , &lid );
    454 printf("\n[MUTEX_DEBUG] %s : core[%x,%d] releases mutex %x"
    455 " / current = %d / free = %d\n",
    456 __FUNCTION__, cxy, lid, mutex, mutex->current, mutex->free );
    457 #endif
    458 
    459     return 0;
    460 }
     411    return hal_user_syscall( SYS_MUTEX,
     412                             (reg_t)mutex,
     413                             MUTEX_UNLOCK,
     414                             0, 0 );
     415}
     416
     417////////////////////////////////////////////////////////////////////////////////////////////
     418//                               Condition variable
     419////////////////////////////////////////////////////////////////////////////////////////////
     420
     421///////////////////////////////////////////////
     422int pthread_cond_init( pthread_cond_t     * cond,
     423                       pthread_condattr_t * attr )
     424{
     425    if( attr )
     426    {
     427        printf("[ERROR] in %s ; <attr> argument must be NULL\n", __FUNCTION__ );
     428        return -1;
     429    }
     430
     431   return hal_user_syscall( SYS_CONDVAR,
     432                             (reg_t)cond,
     433                             CONDVAR_INIT,
     434                             0, 0 );
     435}
     436
     437/////////////////////////////////////////////////
     438int pthread_cond_destroy( pthread_cond_t * cond )
     439{
     440    return hal_user_syscall( SYS_CONDVAR,
     441                             (reg_t)cond,
     442                             CONDVAR_DESTROY,
     443                             0, 0 );
     444}
     445
     446//////////////////////////////////////////////
     447int pthread_cond_wait( pthread_cond_t  * cond,
     448                       pthread_mutex_t * mutex )
     449{
     450    return hal_user_syscall( SYS_CONDVAR,
     451                             (reg_t)cond,
     452                             CONDVAR_WAIT,
     453                             (reg_t)mutex,
     454                             0 );
     455}
     456
     457////////////////////////////////////////////////
     458int pthread_cond_signal( pthread_cond_t * cond )
     459{
     460    return hal_user_syscall( SYS_CONDVAR,
     461                             (reg_t)cond,
     462                             CONDVAR_SIGNAL,
     463                             0, 0 );
     464}
     465
     466///////////////////////////////////////////////////
     467int pthread_cond_broadcast( pthread_cond_t * cond )
     468{
     469    return hal_user_syscall( SYS_CONDVAR,
     470                             (reg_t)cond,
     471                             CONDVAR_BROADCAST,
     472                             0, 0 );
     473}
     474
     475
     476
     477
    461478
    462479
Note: See TracChangeset for help on using the changeset viewer.