@@ -79,16 +79,17 @@ static inline union x86_rflags local_irq_disable_save(void) {
79
79
80
80
static inline void local_irq_restore (union x86_rflags flags ) {
81
81
if (flags .__packed .irqs_enabled ) {
82
- set_rflags (flags );
82
+ //set_rflags(flags);
83
+ asm("sti" );
83
84
}
84
85
}
85
86
86
87
void spinlock_acquire (spinlock_t * lock ) {
87
88
if (!lock ) return ;
88
89
assert (lock -> name , "Spinlock was used without assigning a name" );
89
90
90
- // Keep track of whether we had to wait to acquire the lock
91
91
/*
92
+ // Keep track of whether we had to wait to acquire the lock
92
93
uint32_t contention_start = 0;
93
94
94
95
if (lock->flag != 0) {
@@ -125,18 +126,19 @@ void spinlock_acquire(spinlock_t* lock) {
125
126
}
126
127
127
128
// Spin until the lock is released
128
- /*
129
129
while (!atomic_compare_exchange(&lock->flag, 0, 1)) {
130
130
//task_switch();
131
131
}
132
132
*/
133
+
133
134
union x86_rflags rflags = local_irq_disable_save ();
134
135
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
136
138
while (lock -> flag == 1 ) {
137
- asm volatile ("pause" :::"memory" );
139
+ // asm volatile ("pause":::"memory");
138
140
}
139
- local_irq_disable ();
141
+ // local_irq_disable();
140
142
}
141
143
lock -> rflags = rflags ;
142
144
lock -> owner_pid = getpid ();
@@ -159,7 +161,8 @@ void spinlock_acquire(spinlock_t* lock) {
159
161
else {
160
162
//printf("Spinlock: Proc %d received uncontended lock 0x%08x %s\n", getpid(), lock, lock->name);
161
163
}
162
- */
164
+ */
165
+ //spinlock_acquire_spin(lock);
163
166
}
164
167
165
168
void spinlock_release (spinlock_t * lock ) {
@@ -176,9 +179,11 @@ void spinlock_release(spinlock_t* lock) {
176
179
asm("sti");
177
180
}
178
181
//printf("Spinlock: Proc %d freed lock 0x%08x %s\n", getpid(), lock, lock->name);
179
- */
182
+ */
183
+
180
184
union x86_rflags rflags = lock -> rflags ;
181
185
asm volatile ("" :::"memory" );
182
186
lock -> flag = 0 ;
183
187
local_irq_restore (rflags );
188
+ //spinlock_release_spin(lock);
184
189
}
0 commit comments