Currently I'm implementing some synchronization methods such as spinlock, semaphore, mutex, ...
But those are not working correctly,. so I paste some codes from my kernel to here.
Would you let me know what I've missed?
Thank you..
Code: Select all
void spinlock_lock(spin_lock_t *handle)
{
// while (handle->lock) DbgPrint("a %p\n", kthread_get_current());
// handle->lock = 1;
// return;
// cursor_set_pos(0, 0);
// DbgPrint("===== [Task %p] =====\n", kthread_get_current());
asm __volatile__ (
// "cli\n"
"clc\n"
"1:\n"
"lock; btsl $0, %0\n"
// "sti\n"
// "nop; nop; nop; nop\n"
// "nop; nop; nop; nop\n"
// "cli\n"
"jc 1b\n"
// "sti\n"
:
: "m"(handle->lock)
: "memory"
);
// PANIC("Locked %d\n", handle->lock);
// if (handle->lock > 1) PANIC("Error\n");
}
but if I disable "nop" instruction, no threads are woking,. and the kernel starting to busy-waiting.