作者在 2013-12-15 21:31:20 发布以下内容
#include<iostream>
#include<string>
using namespace std;
struct CHCT;
struct COCT;
struct shebei{ //设备的模拟结构体
};
struct qudong{ //驱动程序模拟结构体
};
struct tongdao{ //通道队列结点结构体
int state;
tongdao *next; //队列指针
};
struct kongzhiqi{ //控制器队列结点结构体
int state;
kongzhiqi *next;
};
struct CHCT{ //通道控制表结构体
string tongdaobiaoshifu;
int state; //0为空闲,1为繁忙;下同
COCT * link_COCT;
CHCT * next;
tongdao *front;
tongdao *rear;
};
struct COCT{ //控制器控制表结构体
string kongzhiqibiaoshifu;
int state;
CHCT *link_CHCT;
COCT *next;
kongzhiqi *front;
kongzhiqi *rear;
};
struct DCT{ //设备控制表结构体
string shebeileixing;
string shebeibiaoshifu;
int state;
//COCT *link_COCT;
DCT *next;
int times; //重复执行次数
int time; //执行时间
shebei *link_shebei;
};
struct SDT{ //系统设备表结构体
int biaomu;
string shebeilei;
string biaoshifu;
DCT *link_DCT;
SDT *next;
qudong *link_qudong;
};
int main()
{
int temp1=1;
string re;
CHCT h1,h2,h3,h4,h5,h6,*ph;
COCT o1,o2,o3,*po;
DCT d1,d2,d3,d4,d5,d6,*pd;
SDT s1,s2,s3,*ps;
h1.link_COCT=h2.link_COCT=h3.link_COCT=h4.link_COCT=h5.link_COCT=h6.link_COCT=&o1;
h1.next=&h2;h2.next=NULL;h3.next=&h4;h4.next=NULL;h5.next=&h6;h6.next=NULL;
h1.state=h2.state=h6.state=0;h3.state=h4.state=h5.state=1;
h1.tongdaobiaoshifu="channelid1";h2.tongdaobiaoshifu="channelid2";h3.tongdaobiaoshifu="channelid3";h4.tongdaobiaoshifu="channelid4";h5.tongdaobiaoshifu="channelid5";h6.tongdaobiaoshifu="channelid6";
o1.state=1;o2.state =0;o3.state =0;
o1.kongzhiqibiaoshifu="controlleried1";o2.kongzhiqibiaoshifu="controlleried2";o3.kongzhiqibiaoshifu="controlleried3";
o1.next=&o2;o2.next=&o3;o3.next=NULL;
o1.link_CHCT=&h1;o2.link_CHCT=&h3;o3.link_CHCT=&h5;
d1.state=1;d2.state=0;d3.state=1;d4.state=1;d5.state=0;d6.state=1;
d1.next=&d2;d2.next=NULL;d3.next=&d4;d4.next=NULL;d5.next=&d6;d6.next=NULL;
d1.shebeileixing=d2.shebeileixing="type";d3.shebeileixing=d4.shebeileixing="input";d5.shebeileixing=d6.shebeileixing="output";
//d1.link_COCT=d2.link_COCT=d3.link_COCT=d4.link_COCT=d5.link_COCT=d6.link_COCT=&o1;
d1.shebeibiaoshifu="1000011";d2.shebeibiaoshifu="1000012";d3.shebeibiaoshifu="1001011";d4.shebeibiaoshifu="1001012";d5.shebeibiaoshifu="1008611";d6.shebeibiaoshifu="1008612";
s1.biaomu=1;s2.biaomu=2;s3.biaomu=3;
s1.shebeilei="type";s2.shebeilei="input";s3.shebeilei ="output";
s1.biaoshifu="10000";s2.biaoshifu="10010";s3.biaoshifu="10086";
s1.next=&s2;s2.next=&s3;s3.next=NULL;
s1.link_DCT=&d1;s2.link_DCT=&d3;s3.link_DCT=&d5;
while(temp1==1)
{
cout<<"当前可申请设备类为:type input output"<<endl;
cout<<"请申请一个类型的设备:";
cin>>re;
ps=&s1;
while(re!=ps->shebeilei&&ps->next!=NULL)
{ps=ps->next;}
if(re==ps->shebeilei)
{cout<<"进入"<<re<<"设备的设备控制表;"<<endl;temp1--;}
else {cout<<"不存在该设备"<<endl;/*return 0;*/}
}
pd=ps->link_DCT;
while(pd->state==1&&pd->next!=NULL)
{
cout<<pd->shebeibiaoshifu<<"号设备正忙,查找下一个同类设备;"<<endl;pd=pd->next;
}
if(pd->state==0){cout<<"已分配"<<pd->shebeibiaoshifu<<"号设备;"<<endl;pd->state=1;}
else {cout<<"设备正忙,插入到等待设备队列;"<<endl;/*return 0;*/}
cout<<"开始查找COCT表"<<endl;
po=&o1;
ph=po->link_CHCT;
while(po->state==1||ph->state==1)
{
while(po->state==1&&po->next!=NULL)
{cout<<"标识符为"<<po->kongzhiqibiaoshifu<<"的控制器正忙,查找下一个;"<<endl;po=po->next;}
if(po->state==0)
{cout<<"已分配标识符为"<<po->kongzhiqibiaoshifu<<"的控制器;"<<endl;po->state=1;}
else {cout<<"当前控制器正忙,插入到等待控制器队列;"<<endl;return 0;}
cout<<"开始查找通道表"<<endl;
ph=po->link_CHCT;
while(ph->state==1&&ph->next!=NULL)
{cout<<"标识符为"<<ph->tongdaobiaoshifu<<"的通道正忙,查找下一个;"<<endl;ph=ph->next;}
if(ph->state==0)
{cout<<"已分配标识符为"<<ph->tongdaobiaoshifu<<"的通道;"<<endl;
cout<<"发出IO指令,启动IO设备传输数据,驱动程序进行阻塞;"<<endl;
return 0;}
else {cout<<"标识符为"<<ph->tongdaobiaoshifu<<"的通道正忙,返回控制器控制表;"<<endl;po->state=0;po=po->next;}
}
cout<<"进入通道等待队列;"<<endl;
return 0;
}
#include<string>
using namespace std;
struct CHCT;
struct COCT;
struct shebei{ //设备的模拟结构体
};
struct qudong{ //驱动程序模拟结构体
};
struct tongdao{ //通道队列结点结构体
int state;
tongdao *next; //队列指针
};
struct kongzhiqi{ //控制器队列结点结构体
int state;
kongzhiqi *next;
};
struct CHCT{ //通道控制表结构体
string tongdaobiaoshifu;
int state; //0为空闲,1为繁忙;下同
COCT * link_COCT;
CHCT * next;
tongdao *front;
tongdao *rear;
};
struct COCT{ //控制器控制表结构体
string kongzhiqibiaoshifu;
int state;
CHCT *link_CHCT;
COCT *next;
kongzhiqi *front;
kongzhiqi *rear;
};
struct DCT{ //设备控制表结构体
string shebeileixing;
string shebeibiaoshifu;
int state;
//COCT *link_COCT;
DCT *next;
int times; //重复执行次数
int time; //执行时间
shebei *link_shebei;
};
struct SDT{ //系统设备表结构体
int biaomu;
string shebeilei;
string biaoshifu;
DCT *link_DCT;
SDT *next;
qudong *link_qudong;
};
int main()
{
int temp1=1;
string re;
CHCT h1,h2,h3,h4,h5,h6,*ph;
COCT o1,o2,o3,*po;
DCT d1,d2,d3,d4,d5,d6,*pd;
SDT s1,s2,s3,*ps;
h1.link_COCT=h2.link_COCT=h3.link_COCT=h4.link_COCT=h5.link_COCT=h6.link_COCT=&o1;
h1.next=&h2;h2.next=NULL;h3.next=&h4;h4.next=NULL;h5.next=&h6;h6.next=NULL;
h1.state=h2.state=h6.state=0;h3.state=h4.state=h5.state=1;
h1.tongdaobiaoshifu="channelid1";h2.tongdaobiaoshifu="channelid2";h3.tongdaobiaoshifu="channelid3";h4.tongdaobiaoshifu="channelid4";h5.tongdaobiaoshifu="channelid5";h6.tongdaobiaoshifu="channelid6";
o1.state=1;o2.state =0;o3.state =0;
o1.kongzhiqibiaoshifu="controlleried1";o2.kongzhiqibiaoshifu="controlleried2";o3.kongzhiqibiaoshifu="controlleried3";
o1.next=&o2;o2.next=&o3;o3.next=NULL;
o1.link_CHCT=&h1;o2.link_CHCT=&h3;o3.link_CHCT=&h5;
d1.state=1;d2.state=0;d3.state=1;d4.state=1;d5.state=0;d6.state=1;
d1.next=&d2;d2.next=NULL;d3.next=&d4;d4.next=NULL;d5.next=&d6;d6.next=NULL;
d1.shebeileixing=d2.shebeileixing="type";d3.shebeileixing=d4.shebeileixing="input";d5.shebeileixing=d6.shebeileixing="output";
//d1.link_COCT=d2.link_COCT=d3.link_COCT=d4.link_COCT=d5.link_COCT=d6.link_COCT=&o1;
d1.shebeibiaoshifu="1000011";d2.shebeibiaoshifu="1000012";d3.shebeibiaoshifu="1001011";d4.shebeibiaoshifu="1001012";d5.shebeibiaoshifu="1008611";d6.shebeibiaoshifu="1008612";
s1.biaomu=1;s2.biaomu=2;s3.biaomu=3;
s1.shebeilei="type";s2.shebeilei="input";s3.shebeilei ="output";
s1.biaoshifu="10000";s2.biaoshifu="10010";s3.biaoshifu="10086";
s1.next=&s2;s2.next=&s3;s3.next=NULL;
s1.link_DCT=&d1;s2.link_DCT=&d3;s3.link_DCT=&d5;
while(temp1==1)
{
cout<<"当前可申请设备类为:type input output"<<endl;
cout<<"请申请一个类型的设备:";
cin>>re;
ps=&s1;
while(re!=ps->shebeilei&&ps->next!=NULL)
{ps=ps->next;}
if(re==ps->shebeilei)
{cout<<"进入"<<re<<"设备的设备控制表;"<<endl;temp1--;}
else {cout<<"不存在该设备"<<endl;/*return 0;*/}
}
pd=ps->link_DCT;
while(pd->state==1&&pd->next!=NULL)
{
cout<<pd->shebeibiaoshifu<<"号设备正忙,查找下一个同类设备;"<<endl;pd=pd->next;
}
if(pd->state==0){cout<<"已分配"<<pd->shebeibiaoshifu<<"号设备;"<<endl;pd->state=1;}
else {cout<<"设备正忙,插入到等待设备队列;"<<endl;/*return 0;*/}
cout<<"开始查找COCT表"<<endl;
po=&o1;
ph=po->link_CHCT;
while(po->state==1||ph->state==1)
{
while(po->state==1&&po->next!=NULL)
{cout<<"标识符为"<<po->kongzhiqibiaoshifu<<"的控制器正忙,查找下一个;"<<endl;po=po->next;}
if(po->state==0)
{cout<<"已分配标识符为"<<po->kongzhiqibiaoshifu<<"的控制器;"<<endl;po->state=1;}
else {cout<<"当前控制器正忙,插入到等待控制器队列;"<<endl;return 0;}
cout<<"开始查找通道表"<<endl;
ph=po->link_CHCT;
while(ph->state==1&&ph->next!=NULL)
{cout<<"标识符为"<<ph->tongdaobiaoshifu<<"的通道正忙,查找下一个;"<<endl;ph=ph->next;}
if(ph->state==0)
{cout<<"已分配标识符为"<<ph->tongdaobiaoshifu<<"的通道;"<<endl;
cout<<"发出IO指令,启动IO设备传输数据,驱动程序进行阻塞;"<<endl;
return 0;}
else {cout<<"标识符为"<<ph->tongdaobiaoshifu<<"的通道正忙,返回控制器控制表;"<<endl;po->state=0;po=po->next;}
}
cout<<"进入通道等待队列;"<<endl;
return 0;
}