Commit 50a1ffb3 by malcolm

mutexes. not very pretty atm

parent cc18f318
Showing with 42 additions and 0 deletions
#include "mutex.h"
uint32_t mutex_lock(mutex m)
{
asm volatile
(
"mov $1, %%eax; \
xchg %[lock], %%eax; \
mov %%eax, %[value]"
:[value] "=r" (m.value)
:[lock] "r" (m.lock_var)
);
return m.value;
}
uint32_t mutex_unlock(mutex m)
{
asm volatile
(
"mov $0, %%eax; \
xchg %[lock], %%eax; \
mov %%eax, %[value]"
:[value] "=r" (m.value)
:[lock] "r" (m.lock_var)
);
return m.value;
}
#ifndef _MUTEX_INC
#define _MUTEX_INC
#include <stdint.h>
typedef struct
{
uint32_t lock_var;
uint32_t value;
}__attribute__((packed)) mutex;
uint32_t mutex_lock(mutex m);
uint32_t mutex_unlock(mutex m);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment