Changeset 592


Ignore:
Timestamp:
Nov 1, 2018, 7:27:14 PM (3 years ago)
Author:
alain
Message:

Simplify the sched_handle°signals() function:
The rwlock protecting the process th_tbl[]
is no more used when handling a THREAD_DELETE request.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/scheduler.c

    r583 r592  
    145145
    146146////////////////////////////////////////////////////////////////////////////////////////////
    147 // This static function is the only function that can actually delete a thread.
     147// This static function is the only function that can actually delete a thread,
     148// and the associated process descriptor, if required.
    148149// It is private, because it is called by the sched_yield() public function.
    149150// It scan all threads attached to a given scheduler, and executes the relevant
    150151// actions for two types of pending requests:
     152//
    151153// - REQ_ACK : it checks that target thread is blocked, decrements the response counter
    152154//   to acknowledge the client thread, and reset the pending request.
     
    177179    sched = &core->scheduler;
    178180
     181    // take the lock protecting sheduler state
     182    busylock_acquire( &sched->lock );
     183
    179184    ////// scan user threads to handle both ACK and DELETE requests
    180185    root = &sched->u_root;
     
    193198
    194199// check thread blocked
    195 assert( (thread->blocked & THREAD_BLOCKED_GLOBAL) ,
    196 "thread not blocked" );
     200assert( (thread->blocked & THREAD_BLOCKED_GLOBAL) , "thread not blocked" );
    197201 
    198202            // decrement response counter
     
    211215            // get thread ltid
    212216            ltid = LTID_FROM_TRDID( thread->trdid);
    213 
    214             // take the lock protecting th_tbl[]
    215             rwlock_wr_acquire( &process->th_lock );
    216 
    217             // take the lock protecting sheduler state
    218             busylock_acquire( &sched->lock );
    219217
    220218            // update scheduler state
     
    238236            }
    239237
    240             // release the lock protecting sheduler state
    241             busylock_release( &sched->lock );
    242 
    243             // get number of threads in local process
    244             count = process->th_nr;
    245 
    246238// check th_nr value
    247 assert( (count > 0) , "process th_nr cannot be 0\n" );
     239assert( (process->th_nr > 0) , "process th_nr cannot be 0\n" );
    248240
    249241            // remove thread from process th_tbl[]
    250242            process->th_tbl[ltid] = NULL;
    251             process->th_nr = count - 1;
     243            hal_atomic_add( &process->th_nr , - 1 );
    252244 
    253             // release the lock protecting th_tbl[]
    254             rwlock_wr_release( &process->th_lock );
    255 
    256245            // release memory allocated for thread descriptor
    257246            thread_destroy( thread );
     
    299288            // get thread ltid
    300289            ltid = LTID_FROM_TRDID( thread->trdid);
    301 
    302             // take the lock protecting th_tbl[]
    303             rwlock_wr_acquire( &process_zero.th_lock );
    304 
    305             // take lock protecting sheduler state
    306             busylock_acquire( &sched->lock );
    307290
    308291            // update scheduler state
     
    326309            }
    327310
    328             // release lock protecting scheduler state
    329             busylock_release( &sched->lock );
    330 
    331311            // get number of threads in local kernel process
    332312            count = process_zero.th_nr;
    333313
    334314// check th_nr value
    335 assert( (count > 0) , "kernel process th_nr cannot be 0\n" );
     315assert( (process_zero.th_nr > 0) , "kernel process th_nr cannot be 0\n" );
    336316
    337317            // remove thread from process th_tbl[]
    338318            process_zero.th_tbl[ltid] = NULL;
    339             process_zero.th_nr = count - 1;
     319            hal_atomic_add( &process_zero.th_nr , - 1 );
    340320 
    341             // release the lock protecting th_tbl[]
    342             rwlock_wr_release( &process_zero.th_lock );
    343 
    344321            // delete thread descriptor
    345322            thread_destroy( thread );
     
    353330        }
    354331    }
     332
     333    // release the lock protecting sheduler state
     334    busylock_release( &sched->lock );
     335
    355336} // end sched_handle_signals()
    356337
Note: See TracChangeset for help on using the changeset viewer.