reset_sem.c
来自「虚拟地址空间基于文件的操作系统」· C语言 代码 · 共 27 行
C
27 行
#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 + =
减小字号Ctrl + -
显示快捷键?