Fork us on GitHub Follow us on Facebook Follow us on Twitter

Ignore:
Timestamp:
2012-07-11T05:45:48Z (10 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial
Children:
b68ae24
Parents:
9f8745c5
Message:

preemption_disable: Replaced memory barriers with compiler barriers. Added checks if reschedule is needed once preemption is enabled.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/preempt/preemption.c

    r9f8745c5 rb23c88e  
    3838#include <preemption.h>
    3939#include <arch.h>
    40 #include <arch/asm.h>
    41 #include <arch/barrier.h>
     40#include <compiler/barrier.h>
    4241#include <debug.h>
     42#include <proc/scheduler.h>
    4343
    4444/** Increment preemption disabled counter. */
     
    4646{
    4747        THE->preemption_disabled++;
    48         memory_barrier();
     48        compiler_barrier();
    4949}
    5050
     
    5252void preemption_enable(void)
    5353{
     54        preemption_enable_noresched();
     55       
     56        if (PREEMPTION_ENABLED && THREAD && THREAD->need_resched) {
     57                preemption_enabled_scheduler();
     58        }
     59}
     60
     61/** Decrement preemption disabled counter. */
     62void preemption_enable_noresched(void)
     63{
    5464        ASSERT(PREEMPTION_DISABLED);
    55         memory_barrier();
     65        compiler_barrier();
    5666        THE->preemption_disabled--;
     67}
     68
     69/** Preemption was enabled. Calls scheduler(). */
     70void preemption_enabled_scheduler(void)
     71{
     72        ASSERT(PREEMPTION_ENABLED);
     73       
     74        /*
     75         * Avoid a race between a thread about to invoke the scheduler()
     76         * after checking THREAD->need_resched and an interrupt that
     77         * occurs right after the check.
     78         *
     79         * Also ensures that code that relies on disabled interrupts
     80         * to suppress preemption continues to work.
     81         */
     82        if (!interrupts_disabled()) {
     83                scheduler();
     84        }
    5785}
    5886
Note: See TracChangeset for help on using the changeset viewer.