mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-10 03:56:49 +00:00
🆕 具有中断管理功能的自旋锁
This commit is contained in:
parent
c120a0e992
commit
77d4854db7
@ -635,9 +635,9 @@ static void putchar(uint *fb, int Xsize, int x, int y, unsigned int FRcolor, uns
|
|||||||
* @param font 字符的bitmap
|
* @param font 字符的bitmap
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#if DEBUG
|
//#if DEBUG
|
||||||
uart_send(COM1, font);
|
uart_send(COM1, font);
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
unsigned char *font_ptr = font_ascii[font];
|
unsigned char *font_ptr = font_ascii[font];
|
||||||
unsigned int *addr;
|
unsigned int *addr;
|
||||||
@ -664,24 +664,23 @@ static void putchar(uint *fb, int Xsize, int x, int y, unsigned int FRcolor, uns
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 格式化打印字符串
|
||||||
|
*
|
||||||
|
* @param FRcolor 前景色
|
||||||
|
* @param BKcolor 背景色
|
||||||
|
* @param ... 格式化字符串
|
||||||
|
*/
|
||||||
int printk_color(unsigned int FRcolor, unsigned int BKcolor, const char *fmt, ...)
|
int printk_color(unsigned int FRcolor, unsigned int BKcolor, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @brief 格式化打印字符串
|
|
||||||
*
|
|
||||||
* @param FRcolor 前景色
|
|
||||||
* @param BKcolor 背景色
|
|
||||||
* @param ... 格式化字符串
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (get_rflags() & 0x200UL)
|
uint64_t rflags = 0; // 加锁后rflags存储到这里
|
||||||
spin_lock(&printk_lock); // 不是中断处理程序调用printk,加锁
|
spin_lock_irqsave(&printk_lock, rflags);
|
||||||
*/
|
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
char buf[4096]; // vsprintf()的缓冲区
|
||||||
int len = vsprintf(buf, fmt, args);
|
int len = vsprintf(buf, fmt, args);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
@ -734,10 +733,7 @@ int printk_color(unsigned int FRcolor, unsigned int BKcolor, const char *fmt, ..
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
spin_unlock_irqrestore(&printk_lock, rflags);
|
||||||
if (get_rflags() & 0x200UL)
|
|
||||||
spin_unlock(&printk_lock);
|
|
||||||
*/
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -838,7 +834,7 @@ int scroll(bool direction, int pixels, bool animation)
|
|||||||
do_scroll(direction, delta_x);
|
do_scroll(direction, delta_x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ struct screen_info
|
|||||||
|
|
||||||
extern unsigned char font_ascii[256][16]; //导出ascii字体的bitmap(8*16大小) ps:位于font.h中
|
extern unsigned char font_ascii[256][16]; //导出ascii字体的bitmap(8*16大小) ps:位于font.h中
|
||||||
|
|
||||||
char buf[4096]; // vsprintf()的缓冲区
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化printk的屏幕信息
|
* @brief 初始化printk的屏幕信息
|
||||||
|
@ -76,4 +76,57 @@ long spin_trylock(spinlock_t *lock)
|
|||||||
if (!tmp_val)
|
if (!tmp_val)
|
||||||
preempt_enable();
|
preempt_enable();
|
||||||
return tmp_val;
|
return tmp_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存当前rflags的值到变量x内并关闭中断
|
||||||
|
#define local_irq_save(x) __asm__ __volatile__("pushfq ; popq %0 ; cli" \
|
||||||
|
: "=g"(x)::"memory")
|
||||||
|
// 恢复先前保存的rflags的值x
|
||||||
|
#define local_irq_restore(x) __asm__ __volatile__("pushq %0 ; popfq" ::"g"(x) \
|
||||||
|
: "memory")
|
||||||
|
#define local_irq_disable() cli();
|
||||||
|
#define local_irq_enable() sti();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 保存中断状态,关闭中断,并自旋锁加锁
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define spin_lock_irqsave(lock, flags) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
local_irq_save(flags); \
|
||||||
|
spin_lock(lock); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 恢复rflags以及中断状态并解锁自旋锁
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define spin_unlock_irqrestore(lock, flags) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
spin_unlock(lock); \
|
||||||
|
local_irq_restore(flags); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 关闭中断并加锁
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define spin_lock_irq(lock) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
local_irq_disable(); \
|
||||||
|
spin_lock(lock); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 解锁并开启中断
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define spin_unlock_irq(lock) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
spin_unlock(lock); \
|
||||||
|
local_irq_enable(); \
|
||||||
|
} while (0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user