📄 sem_al.c
字号:
#include"kernel.h"
#define WRONG_PROCESS_NUMBER -1
#define WRONG_PROCESS_STATE -2
#define WRONG_CAPABILITY -3
#define CREATE_TOO_MANY_SEMAPHORE -4
#define NO_SEMAPHORE -5
int allocate_semaphore(int process_id,int value,
struct capability *process_capability,
struct capability *semaphore_capability)
{
int sem_id;
struct process *p;
struct semaphore *s;
struct kernel_time my_time;
if((process_id<=0)||(process_id>=PROCESS_NUMBER))
return WRONG_PROCESS_NUMBER;
p=&(os->process[process_id]);
if(!KERNEL_COMPARE_CAPABILITY(p->capability,
(*process_capability)))
return WRONG_CAPABILITY;
if(p->semaphore_number>=p->max_semaphore_number)
return CREATE_TOO_MANY_SEMAPHORE;
if((sem_id=os->process[0].semaphore_ring)<0)
return NO_SEMAPHORE;
s=&(os->semaphore[sem_id]);
s->value=value;
s->thread_ring=-1;
s->thread_id=(-1);
COPY_CAPABILITY((*semaphore_capability),(s->capability));
move_semaphore(sem_id,process_id);
SET_MOST_TIME(my_time);
SET_MINIMAL_STEP(s->step);
s->v_value=(-1);
set_semaphore_time(sem_id,&my_time);
return sem_id;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -