Ignore:
Timestamp:
Oct 4, 2018, 11:50:21 PM (6 years ago)
Author:
alain
Message:

Complete restructuration of kernel locks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_thread_join.c

    r506 r566  
    3131#include <errno.h>
    3232#include <printk.h>
    33 #include <remote_spinlock.h>
     33#include <remote_busylock.h>
    3434
    3535#include <syscalls.h>
     
    6767tm_start = hal_get_cycles();
    6868if( DEBUG_SYS_THREAD_JOIN < tm_start )
    69 printk("\n[DBG] %s : parent thread %x enter / process %x / target trdid %x / cycle %d\n",
    70 __FUNCTION__ , joining_ptr , process->pid , trdid , (uint32_t)tm_start );
     69printk("\n[DBG] %s : thread %x in process %x enter / target thread %x / cycle %d\n",
     70__FUNCTION__ , joining_ptr->trdid, process->pid, trdid , (uint32_t)tm_start );
    7171#endif
    7272
    7373    // check trdid argument
    74         if( (target_ltid >= CONFIG_THREAD_MAX_PER_CLUSTER) || cluster_is_undefined( target_cxy ) ) 
     74        if( (target_ltid >= CONFIG_THREADS_MAX_PER_CLUSTER) || cluster_is_undefined( target_cxy ) ) 
    7575        {
    7676
     
    126126
    127127    // check target thread joinable
    128     if( (hal_remote_lw( target_flags_xp ) & THREAD_FLAG_DETACHED) == 0 )
     128    if( (hal_remote_l32( target_flags_xp ) & THREAD_FLAG_DETACHED) != 0 )
    129129    {
    130130
     
    140140
    141141    // get the lock protecting the join in target thread
    142     remote_spinlock_lock( target_join_lock_xp );
     142    remote_busylock_acquire( target_join_lock_xp );
    143143
    144144    // test the kill_done flag from the target thread
    145     if( hal_remote_lw( target_flags_xp ) & THREAD_FLAG_KILL_DONE )  // killer thread is first
    146     {
     145    if( hal_remote_l32( target_flags_xp ) & THREAD_FLAG_KILL_DONE )  // killer thread is first
     146    {
     147
     148#if (DEBUG_SYS_THREAD_JOIN & 1)
     149if( DEBUG_SYS_THREAD_JOIN < tm_start )
     150printk("\n[DBG] %s : thread %x in process %x / killer thread arrived first\n",
     151__FUNCTION__ , joining_ptr->trdid, process->pid );
     152#endif
    147153        // get pointers on killer thread
    148         killer_xp  = (xptr_t)hal_remote_lwd( target_join_xp_xp );
     154        killer_xp  = (xptr_t)hal_remote_l64( target_join_xp_xp );
    149155
    150156        // reset the kill_done flag in target thread
     
    155161
    156162        // release the lock protecting join     
    157         remote_spinlock_unlock( target_join_lock_xp );
     163        remote_busylock_release( target_join_lock_xp );
    158164
    159165        // restore IRQs
     
    162168    else                                                          // joining thread is first
    163169    {
     170
     171#if (DEBUG_SYS_THREAD_JOIN & 1)
     172if( DEBUG_SYS_THREAD_JOIN < tm_start )
     173printk("\n[DBG] %s : thread %x in process %x / joining thread arrived first\n",
     174__FUNCTION__ , joining_ptr->trdid, process->pid );
     175#endif
    164176        // set the join_done flag in target thread
    165177        hal_remote_atomic_or( target_flags_xp , THREAD_FLAG_JOIN_DONE );
     
    169181
    170182        // register the joining thread extended pointer in target thread
    171         hal_remote_swd( target_join_xp_xp , joining_xp );
     183        hal_remote_s64( target_join_xp_xp , joining_xp );
    172184
    173185        // release the lock protecting the join     
    174         remote_spinlock_unlock( target_join_lock_xp );
    175 
     186        remote_busylock_release( target_join_lock_xp );
     187
     188#if (DEBUG_SYS_THREAD_JOIN & 1)
     189if( DEBUG_SYS_THREAD_JOIN < tm_start )
     190printk("\n[DBG] %s : thread %x in process %x / joining thread deschedule\n",
     191__FUNCTION__ , joining_ptr->trdid, process->pid );
     192#endif
    176193        // deschedule
    177194        sched_yield( "joining thread waiting killer thread" );
    178195   
     196#if (DEBUG_SYS_THREAD_JOIN & 1)
     197if( DEBUG_SYS_THREAD_JOIN < tm_start )
     198printk("\n[DBG] %s : thread %x in process %x / joining thread resume\n",
     199__FUNCTION__ , joining_ptr->trdid, process->pid );
     200#endif
    179201        // restore IRQs
    180202        hal_restore_irq( save_sr );
     
    184206tm_end = hal_get_cycles();
    185207if( DEBUG_SYS_THREAD_JOIN < tm_end )
    186 printk("\n[DBG] %s : parent thread %x exit / process %x / target trdid %x / cycle %d\n",
    187 __FUNCTION__, joining_ptr, process->pid, trdid, (uint32_t)tm_end );
     208printk("\n[DBG] %s : thread %x in process %x exit / target thread %x / cycle %d\n",
     209__FUNCTION__, joining_ptr->trdid, process->pid, (uint32_t)tm_end );
    188210#endif
    189211
Note: See TracChangeset for help on using the changeset viewer.