Ignore:
Timestamp:
Oct 10, 2018, 3:11:53 PM (6 years ago)
Author:
alain
Message:

1) Improve the busylock debug infrastructure.
2) introduce a non-distributed, but portable implementation for the pthread_barrier.

File:
1 edited

Legend:

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

    r573 r581  
    3131#include <syscalls_numbers.h>
    3232
    33 #define PTHREAD_BARRIER_DEBUG   0
    3433
    3534////////////////////////////////////////////////////////////////////////////////////////////
     
    7372}
    7473
    75 ///////////////////
     74/////////////////////////
    7675int pthread_yield( void )
    7776{
     
    8079
    8180////////////////////////////////////////////////////////////////////////////////////////////
     81//                               Mutexes
     82////////////////////////////////////////////////////////////////////////////////////////////
     83
     84//////////////////////////////////////////////////////////
     85int pthread_mutex_init( pthread_mutex_t           * mutex,
     86                        const pthread_mutexattr_t * attr )
     87{
     88    if( attr != NULL )
     89    {
     90        printf("\n[ERROR] in %s : <attr> argument not supported\n", __FUNCTION__);
     91        return -1;
     92    }
     93
     94    return hal_user_syscall( SYS_MUTEX,
     95                             (reg_t)mutex,
     96                             MUTEX_INIT,
     97                             0, 0 );
     98}
     99
     100////////////////////////////////////////////////////
     101int pthread_mutex_destroy( pthread_mutex_t * mutex )
     102{
     103    return hal_user_syscall( SYS_MUTEX,
     104                             (reg_t)mutex,
     105                             MUTEX_DESTROY,
     106                             0, 0 );
     107}
     108
     109/////////////////////////////////////////////////
     110int pthread_mutex_lock( pthread_mutex_t * mutex )
     111{
     112    return hal_user_syscall( SYS_MUTEX,
     113                             (reg_t)mutex,
     114                             MUTEX_LOCK,
     115                             0, 0 );
     116}
     117
     118////////////////////////////////////////////////////
     119int pthread_mutex_trylock( pthread_mutex_t * mutex )
     120{
     121    return hal_user_syscall( SYS_MUTEX,
     122                             (reg_t)mutex,
     123                             MUTEX_TRYLOCK,
     124                             0, 0 );
     125}
     126   
     127///////////////////////////////////////////////////
     128int pthread_mutex_unlock( pthread_mutex_t * mutex )
     129{
     130    return hal_user_syscall( SYS_MUTEX,
     131                             (reg_t)mutex,
     132                             MUTEX_UNLOCK,
     133                             0, 0 );
     134}
     135
     136////////////////////////////////////////////////////////////////////////////////////////////
     137//                               Condvars
     138////////////////////////////////////////////////////////////////////////////////////////////
     139
     140///////////////////////////////////////////////
     141int pthread_cond_init( pthread_cond_t     * cond,
     142                       pthread_condattr_t * attr )
     143{
     144    if( attr )
     145    {
     146        printf("[ERROR] in %s ; <attr> argument must be NULL\n", __FUNCTION__ );
     147        return -1;
     148    }
     149
     150   return hal_user_syscall( SYS_CONDVAR,
     151                             (reg_t)cond,
     152                             CONDVAR_INIT,
     153                             0, 0 );
     154}
     155
     156/////////////////////////////////////////////////
     157int pthread_cond_destroy( pthread_cond_t * cond )
     158{
     159    return hal_user_syscall( SYS_CONDVAR,
     160                             (reg_t)cond,
     161                             CONDVAR_DESTROY,
     162                             0, 0 );
     163}
     164
     165//////////////////////////////////////////////
     166int pthread_cond_wait( pthread_cond_t  * cond,
     167                       pthread_mutex_t * mutex )
     168{
     169    return hal_user_syscall( SYS_CONDVAR,
     170                             (reg_t)cond,
     171                             CONDVAR_WAIT,
     172                             (reg_t)mutex,
     173                             0 );
     174}
     175
     176////////////////////////////////////////////////
     177int pthread_cond_signal( pthread_cond_t * cond )
     178{
     179    return hal_user_syscall( SYS_CONDVAR,
     180                             (reg_t)cond,
     181                             CONDVAR_SIGNAL,
     182                             0, 0 );
     183}
     184
     185///////////////////////////////////////////////////
     186int pthread_cond_broadcast( pthread_cond_t * cond )
     187{
     188    return hal_user_syscall( SYS_CONDVAR,
     189                             (reg_t)cond,
     190                             CONDVAR_BROADCAST,
     191                             0, 0 );
     192}
     193
     194
     195////////////////////////////////////////////////////////////////////////////////////////////
    82196//                            Barriers
    83197////////////////////////////////////////////////////////////////////////////////////////////
     198
     199////////////////////////////////////////////////////////////////
     200int pthread_barrier_init( pthread_barrier_t           * barrier,
     201                          const pthread_barrierattr_t * attr,
     202                          unsigned int                  count )
     203{
     204    return hal_user_syscall( SYS_BARRIER,
     205                             (reg_t)barrier,
     206                             BARRIER_INIT,
     207                             (reg_t)count,
     208                             0 );
     209}
     210
     211//////////////////////////////////////////////////////////
     212int pthread_barrier_destroy( pthread_barrier_t * barrier )
     213{
     214    return hal_user_syscall( SYS_BARRIER,
     215                             (reg_t)barrier,
     216                             BARRIER_DESTROY,
     217                             0, 0 );
     218}
     219   
     220///////////////////////////////////////////////////////
     221int pthread_barrier_wait( pthread_barrier_t * barrier )
     222{
     223    return hal_user_syscall( SYS_BARRIER,
     224                             (reg_t)barrier,
     225                             BARRIER_WAIT,
     226                             0, 0 );
     227}
     228
     229/*
     230
     231////////////////////////////////////////////////////////////////////////////////////////////
     232// The following functions define another implementation for the POSX barrier
     233// based on a distributed quadtree implemented in user space, and relying
     234// on a busy waiting policy.
     235////////////////////////////////////////////////////////////////////////////////////////////
     236
    84237
    85238////////////////////////////////////////////////////////////////////////////////////////////
     
    359512}  // end pthread_barrier_wait()
    360513
    361 ////////////////////////////////////////////////////////////////////////////////////////////
    362 //                               Mutexes
    363 ////////////////////////////////////////////////////////////////////////////////////////////
    364 
    365 //////////////////////////////////////////////////////////
    366 int pthread_mutex_init( pthread_mutex_t           * mutex,
    367                         const pthread_mutexattr_t * attr )
    368 {
    369     if( attr != NULL )
    370     {
    371         printf("\n[ERROR] in %s : <attr> argument not supported\n", __FUNCTION__);
    372         return -1;
    373     }
    374 
    375     return hal_user_syscall( SYS_MUTEX,
    376                              (reg_t)mutex,
    377                              MUTEX_INIT,
    378                              0, 0 );
    379 }
    380 
    381 ////////////////////////////////////////////////////
    382 int 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 );
    388 }
    389 
    390 /////////////////////////////////////////////////
    391 int pthread_mutex_lock( pthread_mutex_t * mutex )
    392 {
    393     return hal_user_syscall( SYS_MUTEX,
    394                              (reg_t)mutex,
    395                              MUTEX_LOCK,
    396                              0, 0 );
    397 }
    398 
    399 ////////////////////////////////////////////////////
    400 int pthread_mutex_trylock( pthread_mutex_t * mutex )
    401 {
    402     return hal_user_syscall( SYS_MUTEX,
    403                              (reg_t)mutex,
    404                              MUTEX_TRYLOCK,
    405                              0, 0 );
    406 }
    407    
    408 ///////////////////////////////////////////////////
    409 int pthread_mutex_unlock( pthread_mutex_t * mutex )
    410 {
    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 ///////////////////////////////////////////////
    422 int 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 /////////////////////////////////////////////////
    438 int 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 //////////////////////////////////////////////
    447 int 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 ////////////////////////////////////////////////
    458 int 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 ///////////////////////////////////////////////////
    467 int 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 
     514*/
    477515
    478516
Note: See TracChangeset for help on using the changeset viewer.