Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/synch/spinlock.c

    r90c8b8d r98000fb  
    4545#include <symtab.h>
    4646
     47#ifdef CONFIG_FB
     48#include <genarch/fb/fb.h>
     49#endif
     50
    4751#ifdef CONFIG_SMP
    4852
    4953/** Initialize spinlock
    5054 *
     55 * Initialize spinlock.
     56 *
    5157 * @param sl Pointer to spinlock_t structure.
    52  *
    5358 */
    54 void spinlock_initialize(spinlock_t *lock, char *name)
     59void spinlock_initialize(spinlock_t *sl, char *name)
    5560{
    56         atomic_set(&lock->val, 0);
     61        atomic_set(&sl->val, 0);
    5762#ifdef CONFIG_DEBUG_SPINLOCK
    58         lock->name = name;
    59 #endif
     63        sl->name = name;
     64#endif 
    6065}
    61 
    62 #ifdef CONFIG_DEBUG_SPINLOCK
    6366
    6467/** Lock spinlock
     
    6871 * possible occurence of deadlock.
    6972 *
    70  * @param lock Pointer to spinlock_t structure.
    71  *
     73 * @param sl Pointer to spinlock_t structure.
    7274 */
    73 void spinlock_lock_debug(spinlock_t *lock)
     75#ifdef CONFIG_DEBUG_SPINLOCK
     76void spinlock_lock_debug(spinlock_t *sl)
    7477{
    7578        size_t i = 0;
    7679        bool deadlock_reported = false;
    77        
     80
    7881        preemption_disable();
    79         while (test_and_set(&lock->val)) {
     82        while (test_and_set(&sl->val)) {
     83
    8084                /*
    81                  * We need to be careful about particular locks
    82                  * which are directly used to report deadlocks
    83                  * via printf() (and recursively other functions).
    84                  * This conserns especially printf_lock and the
    85                  * framebuffer lock.
     85                 * We need to be careful about printf_lock and fb_lock.
     86                 * Both of them are used to report deadlocks via
     87                 * printf() and fb_putchar().
    8688                 *
    87                  * Any lock whose name is prefixed by "*" will be
    88                  * ignored by this deadlock detection routine
    89                  * as this might cause an infinite recursion.
    9089                 * We trust our code that there is no possible deadlock
    91                  * caused by these locks (except when an exception
    92                  * is triggered for instance by printf()).
     90                 * caused by these two locks (except when an exception
     91                 * is triggered for instance by printf() or fb_putchar()).
     92                 * However, we encountered false positives caused by very
     93                 * slow VESA framebuffer interaction (especially when
     94                 * run in a simulator) that caused problems with both
     95                 * printf_lock and fb_lock.
    9396                 *
    94                  * We encountered false positives caused by very
    95                  * slow framebuffer interaction (especially when
    96                  * run in a simulator) that caused problems with both
    97                  * printf_lock and the framebuffer lock.
    98                  *
     97                 * Possible deadlocks on both printf_lock and fb_lock
     98                 * are therefore not reported as they would cause an
     99                 * infinite recursion.
    99100                 */
    100                 if (lock->name[0] == '*')
     101                if (sl == &printf_lock)
    101102                        continue;
    102                
     103#ifdef CONFIG_FB
     104                if (sl == &fb_lock)
     105                        continue;
     106#endif
    103107                if (i++ > DEADLOCK_THRESHOLD) {
    104108                        printf("cpu%u: looping on spinlock %" PRIp ":%s, "
    105                             "caller=%" PRIp "(%s)\n", CPU->id, lock, lock->name,
     109                            "caller=%" PRIp "(%s)\n", CPU->id, sl, sl->name,
    106110                            CALLER, symtab_fmt_name_lookup(CALLER));
    107111                       
     
    110114                }
    111115        }
    112        
     116
    113117        if (deadlock_reported)
    114118                printf("cpu%u: not deadlocked\n", CPU->id);
    115        
     119
    116120        /*
    117121         * Prevent critical section code from bleeding out this way up.
     
    119123        CS_ENTER_BARRIER();
    120124}
    121 
    122125#endif
    123126
     
    128131 * signal failure.
    129132 *
    130  * @param lock Pointer to spinlock_t structure.
     133 * @param sl Pointer to spinlock_t structure.
    131134 *
    132135 * @return Zero on failure, non-zero otherwise.
    133  *
    134136 */
    135 int spinlock_trylock(spinlock_t *lock)
     137int spinlock_trylock(spinlock_t *sl)
    136138{
     139        int rc;
     140       
    137141        preemption_disable();
    138         int rc = !test_and_set(&lock->val);
    139        
     142        rc = !test_and_set(&sl->val);
     143
    140144        /*
    141145         * Prevent critical section code from bleeding out this way up.
    142146         */
    143147        CS_ENTER_BARRIER();
    144        
     148
    145149        if (!rc)
    146150                preemption_enable();
Note: See TracChangeset for help on using the changeset viewer.