Subversion Repositories HelenOS

Rev

Rev 109 | Rev 113 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 109 Rev 111
Line 40... Line 40...
40
#include <panic.h>
40
#include <panic.h>
41
#include <typedefs.h>
41
#include <typedefs.h>
42
#include <mm/page.h>
42
#include <mm/page.h>
43
#include <synch/spinlock.h>
43
#include <synch/spinlock.h>
44
#include <arch/faddr.h>
44
#include <arch/faddr.h>
45
 
-
 
46
#ifdef __SMP__
-
 
47
#include <arch/smp/atomic.h>
45
#include <arch/atomic.h>
48
#endif /* __SMP__ */
-
 
49
 
46
 
50
/*
47
/*
51
 * NOTE ON ATOMIC READS:
48
 * NOTE ON ATOMIC READS:
52
 * Some architectures cannot read __u32 atomically.
49
 * Some architectures cannot read __u32 atomically.
53
 * For that reason, all accesses to nrdy and the likes must be protected by spinlock.
50
 * For that reason, all accesses to nrdy and the likes must be protected by spinlock.
54
 */
51
 */
55
 
52
 
56
spinlock_t nrdylock;
-
 
57
volatile int nrdy;
53
volatile int nrdy;
58
 
54
 
59
 
55
 
60
/** Initialize context switching
56
/** Initialize context switching
61
 *
57
 *
Line 75... Line 71...
75
 * Initialize kernel scheduler.
71
 * Initialize kernel scheduler.
76
 *
72
 *
77
 */
73
 */
78
void scheduler_init(void)
74
void scheduler_init(void)
79
{
75
{
80
    spinlock_initialize(&nrdylock);
-
 
81
}
76
}
82
 
77
 
83
 
78
 
84
/** Get thread to be scheduled
79
/** Get thread to be scheduled
85
 *
80
 *
Line 138... Line 133...
138
             */
133
             */
139
            spinlock_unlock(&r->lock);
134
            spinlock_unlock(&r->lock);
140
            continue;
135
            continue;
141
        }
136
        }
142
   
137
   
143
        spinlock_lock(&nrdylock);
138
        atomic_dec(&nrdy);
144
        nrdy--;
-
 
145
        spinlock_unlock(&nrdylock);    
-
 
146
 
139
 
147
        spinlock_lock(&CPU->lock);
140
        spinlock_lock(&CPU->lock);
148
        CPU->nrdy--;
141
        CPU->nrdy--;
149
        spinlock_unlock(&CPU->lock);
142
        spinlock_unlock(&CPU->lock);
150
 
143
 
Line 496... Line 489...
496
                        goto restart;
489
                        goto restart;
497
                    }
490
                    }
498
                    cpu->nrdy--;
491
                    cpu->nrdy--;
499
                    spinlock_unlock(&cpu->lock);
492
                    spinlock_unlock(&cpu->lock);
500
 
493
 
501
                    spinlock_lock(&nrdylock);
494
                    atomic_dec(&nrdy);
502
                    nrdy--;
-
 
503
                    spinlock_unlock(&nrdylock);                
-
 
504
 
495
 
505
                        r->n--;
496
                        r->n--;
506
                    list_remove(&t->rq_link);
497
                    list_remove(&t->rq_link);
507
 
498
 
508
                    break;
499
                    break;