Changeset 518dd43 in mainline for kernel/generic/src/proc/thread.c


Ignore:
Timestamp:
2012-07-06T13:06:44Z (12 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8a64e81e
Parents:
46a5b37
Message:

thread: thread_ready() new prefers cpus where thread last ran. Added thread_interrupt().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/thread.c

    r46a5b37 r518dd43  
    272272       
    273273        ASSERT(thread->state != Ready);
    274        
     274
    275275        int i = (thread->priority < RQ_COUNT - 1) ?
    276276            ++thread->priority : thread->priority;
    277        
    278         cpu_t *cpu;
    279         if (thread->wired || thread->nomigrate || thread->fpu_context_engaged) {
    280                 ASSERT(thread->cpu != NULL);
    281                 cpu = thread->cpu;
    282         } else
     277
     278        /* Check that thread->cpu is set whenever it needs to be. */
     279        ASSERT(thread->cpu != NULL ||
     280                (!thread->wired && !thread->nomigrate && !thread->fpu_context_engaged));
     281
     282        /*
     283         * Prefer to run on the same cpu as the last time. Used by wired
     284         * threads as well as threads with disabled migration.
     285         */
     286        cpu_t *cpu = thread->cpu;
     287        if (cpu == NULL)
    283288                cpu = CPU;
    284289       
     
    518523        /* Not reached */
    519524        while (true);
     525}
     526
     527/** Interrupts an existing thread so that it may exit as soon as possible.
     528 *
     529 * Threads that are blocked waiting for a synchronization primitive
     530 * are woken up with a return code of ESYNCH_INTERRUPTED if the
     531 * blocking call was interruptable. See waitq_sleep_timeout().
     532 *
     533 * The caller must guarantee the thread object is valid during the entire
     534 * function, eg by holding the threads_lock lock.
     535 *
     536 * Interrupted threads automatically exit when returning back to user space.
     537 *
     538 * @param thread A valid thread object. The caller must guarantee it
     539 *               will remain valid until thread_interrupt() exits.
     540 */
     541void thread_interrupt(thread_t *thread)
     542{
     543        ASSERT(thread != NULL);
     544       
     545        irq_spinlock_lock(&thread->lock, true);
     546       
     547        thread->interrupted = true;
     548        bool sleeping = (thread->state == Sleeping);
     549       
     550        irq_spinlock_unlock(&thread->lock, true);
     551       
     552        if (sleeping)
     553                waitq_interrupt_sleep(thread);
     554}
     555
     556/** Returns true if the thread was interrupted.
     557 *
     558 * @param thread A valid thread object. User must guarantee it will
     559 *               be alive during the entire call.
     560 * @return true if the thread was already interrupted via thread_interrupt().
     561 */
     562bool thread_interrupted(thread_t *thread)
     563{
     564        ASSERT(thread != NULL);
     565       
     566        bool interrupted;
     567       
     568        irq_spinlock_lock(&thread->lock, true);
     569        interrupted = thread->interrupted;
     570        irq_spinlock_unlock(&thread->lock, true);
     571       
     572        return interrupted;
    520573}
    521574
Note: See TracChangeset for help on using the changeset viewer.