Changeset 58775d30 in mainline for kernel/generic/src/proc/thread.c


Ignore:
Timestamp:
2015-03-16T16:07:21Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2003739
Parents:
6069061 (diff), 795e2bf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Mainline changes

File:
1 edited

Legend:

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

    r6069061 r58775d30  
    4646#include <synch/spinlock.h>
    4747#include <synch/waitq.h>
     48#include <synch/workqueue.h>
     49#include <synch/rcu.h>
    4850#include <cpu.h>
    4951#include <str.h>
     
    263265}
    264266
     267/** Invoked right before thread_ready() readies the thread. thread is locked. */
     268static void before_thread_is_ready(thread_t *thread)
     269{
     270        ASSERT(irq_spinlock_locked(&thread->lock));
     271        workq_before_thread_is_ready(thread);
     272}
     273
    265274/** Make thread ready
    266275 *
     
    275284       
    276285        ASSERT(thread->state != Ready);
     286
     287        before_thread_is_ready(thread);
    277288       
    278289        int i = (thread->priority < RQ_COUNT - 1) ?
    279290            ++thread->priority : thread->priority;
    280        
    281         cpu_t *cpu;
    282         if (thread->wired || thread->nomigrate || thread->fpu_context_engaged) {
    283                 ASSERT(thread->cpu != NULL);
    284                 cpu = thread->cpu;
    285         } else
     291
     292        /* Check that thread->cpu is set whenever it needs to be. */
     293        ASSERT(thread->cpu != NULL ||
     294                (!thread->wired && !thread->nomigrate && !thread->fpu_context_engaged));
     295
     296        /*
     297         * Prefer to run on the same cpu as the last time. Used by wired
     298         * threads as well as threads with disabled migration.
     299         */
     300        cpu_t *cpu = thread->cpu;
     301        if (cpu == NULL)
    286302                cpu = CPU;
    287303       
     
    377393        thread->task = task;
    378394       
     395        thread->workq = NULL;
     396       
    379397        thread->fpu_context_exists = false;
    380398        thread->fpu_context_engaged = false;
     
    391409        /* Might depend on previous initialization */
    392410        thread_create_arch(thread);
     411       
     412        rcu_thread_init(thread);
    393413       
    394414        if ((flags & THREAD_FLAG_NOATTACH) != THREAD_FLAG_NOATTACH)
     
    501521                         */
    502522                        ipc_cleanup();
    503                         futex_cleanup();
     523                        futex_task_cleanup();
    504524                        LOG("Cleanup of task %" PRIu64" completed.", TASK->taskid);
    505525                }
     
    521541        /* Not reached */
    522542        while (true);
     543}
     544
     545/** Interrupts an existing thread so that it may exit as soon as possible.
     546 *
     547 * Threads that are blocked waiting for a synchronization primitive
     548 * are woken up with a return code of ESYNCH_INTERRUPTED if the
     549 * blocking call was interruptable. See waitq_sleep_timeout().
     550 *
     551 * The caller must guarantee the thread object is valid during the entire
     552 * function, eg by holding the threads_lock lock.
     553 *
     554 * Interrupted threads automatically exit when returning back to user space.
     555 *
     556 * @param thread A valid thread object. The caller must guarantee it
     557 *               will remain valid until thread_interrupt() exits.
     558 */
     559void thread_interrupt(thread_t *thread)
     560{
     561        ASSERT(thread != NULL);
     562       
     563        irq_spinlock_lock(&thread->lock, true);
     564       
     565        thread->interrupted = true;
     566        bool sleeping = (thread->state == Sleeping);
     567       
     568        irq_spinlock_unlock(&thread->lock, true);
     569       
     570        if (sleeping)
     571                waitq_interrupt_sleep(thread);
     572}
     573
     574/** Returns true if the thread was interrupted.
     575 *
     576 * @param thread A valid thread object. User must guarantee it will
     577 *               be alive during the entire call.
     578 * @return true if the thread was already interrupted via thread_interrupt().
     579 */
     580bool thread_interrupted(thread_t *thread)
     581{
     582        ASSERT(thread != NULL);
     583       
     584        bool interrupted;
     585       
     586        irq_spinlock_lock(&thread->lock, true);
     587        interrupted = thread->interrupted;
     588        irq_spinlock_unlock(&thread->lock, true);
     589       
     590        return interrupted;
    523591}
    524592
Note: See TracChangeset for help on using the changeset viewer.