Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/abs32le/include/atomic.h

    rb03a666 r50fda24  
    5454}
    5555
    56 static inline atomic_count_t atomic_postinc(atomic_t *val)
     56static inline long atomic_postinc(atomic_t *val)
    5757{
    5858        /* On real hardware both the storing of the previous
     
    6060           atomic action. */
    6161       
    62         atomic_count_t prev = val->count;
     62        long prev = val->count;
    6363       
    6464        val->count++;
     
    6666}
    6767
    68 static inline atomic_count_t atomic_postdec(atomic_t *val)
     68static inline long atomic_postdec(atomic_t *val)
    6969{
    7070        /* On real hardware both the storing of the previous
     
    7272           atomic action. */
    7373       
    74         atomic_count_t prev = val->count;
     74        long prev = val->count;
    7575       
    7676        val->count--;
     
    8181#define atomic_predec(val)  (atomic_postdec(val) - 1)
    8282
    83 static inline atomic_count_t test_and_set(atomic_t *val)
    84 {
    85         atomic_count_t prev = val->count;
    86         val->count = 1;
    87         return prev;
     83static inline uint32_t test_and_set(atomic_t *val) {
     84        uint32_t v;
     85       
     86        asm volatile (
     87                "movl $1, %[v]\n"
     88                "xchgl %[v], %[count]\n"
     89                : [v] "=r" (v), [count] "+m" (val->count)
     90        );
     91       
     92        return v;
    8893}
    8994
     95/** ia32 specific fast spinlock */
    9096static inline void atomic_lock_arch(atomic_t *val)
    9197{
    92         do {
    93                 while (val->count);
    94         } while (test_and_set(val));
     98        uint32_t tmp;
     99       
     100        preemption_disable();
     101        asm volatile (
     102                "0:\n"
     103                "pause\n"        /* Pentium 4's HT love this instruction */
     104                "mov %[count], %[tmp]\n"
     105                "testl %[tmp], %[tmp]\n"
     106                "jnz 0b\n"       /* lightweight looping on locked spinlock */
     107               
     108                "incl %[tmp]\n"  /* now use the atomic operation */
     109                "xchgl %[count], %[tmp]\n"
     110                "testl %[tmp], %[tmp]\n"
     111                "jnz 0b\n"
     112                : [count] "+m" (val->count), [tmp] "=&r" (tmp)
     113        );
     114        /*
     115         * Prevent critical section code from bleeding out this way up.
     116         */
     117        CS_ENTER_BARRIER();
    95118}
    96119
Note: See TracChangeset for help on using the changeset viewer.