So... no... there not working...
At first I tried to use a struct per mutex... and failed miserably...
Now I am try something much simpler:
Code:
unsigned long fetch_and_increment(volatile unsigned long *mem)
{
unsigned long val = 1;
asm volatile ("lock; xadd %1, (%2)"
: "=r"(val)
: "r"(val), "r"(mem)
: "%1","memory");
return val;
}
int entries = 0;
int exits = 0;
void mutex_lock(volatile mutex_t mt)
{
int ticket = fetch_and_increment(&entries);
kprintf("GOT TICKET: %d\n",ticket);
while (ticket != exits)
{
//schedule(); // or anything else you can do while waiting for your turn
}
}
void mutex_unlock(volatile mutex_t mt)
{
exits = exits + 1;
kprintf("MADE EXIT: %d\n",exits);
}
It runs for a brief while giving and closing tickets... but it usually locks up pretty quick...
After about 10 - 100 tickets...
However, I actually think that the tickets are all on the same thread and after the switch the switch it blows up.
Ignore the function headers the volatile mutex_t mt was for something else I was testing and failed... Also if I turn entries and exits volatile, I get two grabs for ticket 1 and no exits...
If you think it matters, I post my scheduler code... but I am attaching screen shots of the output.
Thanks,
Rich