📄 equipment_mj.h
字号:
//设备初始化
void Initial_equp()
{
int i;
A1=0;//各设备状态初始化
for(i=0;i<2;i++)
{
B1[i]=0;
C1[i]=0;
}
//等待设备的进程队列初始化
InitList(&a_block_pcb);
InitList(&b_block_pcb);
InitList(&c_block_pcb);
//指向使用设备进程指针初始化
a_using=NULL;
for(i=0;i<2;i++)
{
b_using[i]=NULL;
c_using[i]=NULL;
}
}
Status IsA() //判断是否有A设备空闲
{
if(A1==0)
return TRUE;
else
return FALSE;
}
Status IsB(int &b) //判断是否有B设备空闲
{
for(int i=0;i<2;i++)
if(B1[i]==0)
{
b=i;
return TRUE;
}
return FALSE;
}
Status IsC(int &c) //判断是否有C设备空闲
{
for(int i=0;i<2;i++)
if(C1[i]==0)
{
c=i;
return TRUE;
}
return FALSE;
}
void assign()
{ //设备分配给进程;
int index;
//分配A设备给有需要得进程
if(a_block_pcb.len!=0&&IsA())
a_using=DeleteList(&a_block_pcb);
//分配B设备给有需要得进程
while(b_block_pcb.len!=0&&IsB(index))
b_using[index]=DeleteList(&b_block_pcb);
//分配C设备给有需要得进程
while((c_block_pcb.len!=0)&&(IsC(index)))
c_using[index]=DeleteList(&c_block_pcb);
}
void equipment()
{
link p;
assign(); //重新分配设备
//设备A运行
if(a_using)
{
a_using->ppc->a[2]--;
if(a_using->ppc->a[2]==0)
{
psw=3;
wake[0]=a_using;
wake[0]->ppc=wake[0]->ppc->next;
a_using=NULL;
A1=0;
}
}
//等待A设备时间增一
p=a_block_pcb.head;
while(p->next)
{
p=p->next;
p->wait_time++;
}
//设备B运行
if(b_using[0])
{ b_using[0]->ppc->a[2]--;
if(b_using[0]->ppc->a[2]==0)
{
psw=3;
wake[1]=b_using[0];
wake[1]->ppc=wake[1]->ppc->next;
b_using[0]=NULL;
B1[0]=0;
}
}
if(b_using[1])
{ b_using[1]->ppc->a[2]--;
if(b_using[1]->ppc->a[2]==0)
{
psw=3;
wake[2]=b_using[1];
wake[2]->ppc=wake[2]->ppc->next;
b_using[1]=NULL;
B1[1]=0;
}
}
//等待B设备时间增一
p=b_block_pcb.head;
while(p->next)
{
p=p->next;
p->wait_time++;
}
//设备C运行
if(c_using[0])
{ c_using[0]->ppc->a[2]--;
if(c_using[0]->ppc->a[2]==0)
{
psw=3;
wake[3]=c_using[0];
wake[3]->ppc=wake[3]->ppc->next;
c_using[0]=NULL;
C1[0]=0;
}
}
if(c_using[1])
{ c_using[1]->ppc->a[2]--;
if(c_using[1]->ppc->a[2]==0)
{
psw=3;
wake[4]=c_using[1];
wake[4]->ppc=wake[4]->ppc->next;
c_using[1]=NULL;
C1[1]=0;
}
}
//等待C设备时间增一
p=c_block_pcb.head;
while(p->next)
{
p=p->next;
p->wait_time++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -