⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reset_sem.c

📁 国内一位牛人自己开发的操作系统
💻 C
字号:
#include"kernel.h"
#define WRONG_SEMAPHORE_ID 	(-1)
#define WRONG_CAPABILITY	(-2)
int reset_semaphore_value(int sem_id,struct capability *cap)
{
	struct semaphore *s;
	struct kernel_time new_time,new_step;

	if((sem_id<=0)||(sem_id>=SEMAPHORE_NUMBER))
		return WRONG_SEMAPHORE_ID;
	s=&(os->semaphore[sem_id]);
	if(!KERNEL_COMPARE_CAPABILITY(s->capability,(*cap)))
		return WRONG_CAPABILITY;
	if(s->value<0){
		int value=(-1);
		system_call_v(sem_id,&value,&(os->system_capability));
	}
	if(s->value>0)
		s->value=0;
	SET_MOST_TIME(new_time);
	SET_MINIMAL_STEP(new_step);
	set_semaphore_time_system_call(sem_id,0,
		&new_time,&new_step,&(s->capability));
	return sem_id;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -