Skip to content

Commit cf729a1

Browse files
committed
[Kernel] Check in spinlock changes
1 parent b61e948 commit cf729a1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

kernel/kernel/util/spinlock/spinlock.c

+13-8
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,17 @@ static inline union x86_rflags local_irq_disable_save(void) {
7979

8080
static inline void local_irq_restore(union x86_rflags flags) {
8181
if (flags.__packed.irqs_enabled) {
82-
set_rflags(flags);
82+
//set_rflags(flags);
83+
asm("sti");
8384
}
8485
}
8586

8687
void spinlock_acquire(spinlock_t* lock) {
8788
if (!lock) return;
8889
assert(lock->name, "Spinlock was used without assigning a name");
8990

90-
// Keep track of whether we had to wait to acquire the lock
9191
/*
92+
// Keep track of whether we had to wait to acquire the lock
9293
uint32_t contention_start = 0;
9394
9495
if (lock->flag != 0) {
@@ -125,18 +126,19 @@ void spinlock_acquire(spinlock_t* lock) {
125126
}
126127
127128
// Spin until the lock is released
128-
/*
129129
while (!atomic_compare_exchange(&lock->flag, 0, 1)) {
130130
//task_switch();
131131
}
132132
*/
133+
133134
union x86_rflags rflags = local_irq_disable_save();
134135
while (atomic_bit_test_and_set(&lock->flag) == 1) {
135-
local_irq_restore(rflags);
136+
//local_irq_restore(rflags);
137+
// Wait until the lock looks unlocked before retrying
136138
while (lock->flag == 1) {
137-
asm volatile ("pause":::"memory");
139+
//asm volatile ("pause":::"memory");
138140
}
139-
local_irq_disable();
141+
//local_irq_disable();
140142
}
141143
lock->rflags = rflags;
142144
lock->owner_pid = getpid();
@@ -159,7 +161,8 @@ void spinlock_acquire(spinlock_t* lock) {
159161
else {
160162
//printf("Spinlock: Proc %d received uncontended lock 0x%08x %s\n", getpid(), lock, lock->name);
161163
}
162-
*/
164+
*/
165+
//spinlock_acquire_spin(lock);
163166
}
164167

165168
void spinlock_release(spinlock_t* lock) {
@@ -176,9 +179,11 @@ void spinlock_release(spinlock_t* lock) {
176179
asm("sti");
177180
}
178181
//printf("Spinlock: Proc %d freed lock 0x%08x %s\n", getpid(), lock, lock->name);
179-
*/
182+
*/
183+
180184
union x86_rflags rflags = lock->rflags;
181185
asm volatile ("":::"memory");
182186
lock->flag = 0;
183187
local_irq_restore(rflags);
188+
//spinlock_release_spin(lock);
184189
}

0 commit comments

Comments
 (0)