49 lines
764 B
C
49 lines
764 B
C
#include <sys/spinlock.h>
|
|
|
|
#if defined(DEBUG_SPINLOCK)
|
|
#pragma message "SPINLOCK: DEBUG MODE"
|
|
#endif
|
|
|
|
void spinlock_lock(spinlock_t *spinlock){
|
|
while (1){
|
|
ATOMIC
|
|
if (!*spinlock){
|
|
*spinlock |= 0x01;
|
|
return;
|
|
};
|
|
};
|
|
};
|
|
|
|
void spinlock_release(spinlock_t *spinlock){
|
|
ATOMIC
|
|
*spinlock = 0x00;
|
|
};
|
|
|
|
void spinlock_lock_irq(spinlock_t *spinlock,cpustate_t *state){
|
|
*state = SREG & 0x80;
|
|
|
|
#if defined(DEBUG_SPINLOCK)
|
|
rt_dbg->spinlock_ip = getPC();
|
|
#endif
|
|
|
|
while (1){
|
|
SREG &= 0x7F;
|
|
|
|
if (!*spinlock){
|
|
*spinlock |= 0x01;
|
|
return;
|
|
};
|
|
|
|
SREG = *state;
|
|
};
|
|
};
|
|
|
|
void spinlock_release_irq(spinlock_t *spinlock,cpustate_t *state){
|
|
*spinlock = 0x00;
|
|
|
|
#if defined(DEBUG_SPINLOCK)
|
|
rt_dbg->spinlock_ip = 0;
|
|
#endif
|
|
|
|
SREG = (SREG & 0x7F) | *state;
|
|
}; |