本文整理匯總了C++中EnQ函數的典型用法代碼示例。如果您正苦於以下問題:C++ EnQ函數的具體用法?C++ EnQ怎麽用?C++ EnQ使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EnQ函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: InitKernelData
void InitKernelData()
{
int i;
MyBzero((char *)&ready_q, sizeof(q_t));
MyBzero((char *)&free_q, sizeof(q_t));
//phase 3
MyBzero((char *)&sem_q, sizeof(q_t)); //clear the available semaphore queue
for(i = 0; i < Q_LEN; i++) // loop number i from 0 to 19
{
EnQ(i, &free_q); //call EnQ() to enqueue i to free_q
//phase 3
EnQ(i, &sem_q); //fill it with available semaphore ID's (from 0 to Q_SIZE-1).
MyBzero((char *) &pcb[i], sizeof(pcb_t));
}
running_pid = 0;//set running_pid to 0; none initially, need to chose by Scheduler()
//Phase 2
OS_clock = 0; //reset OS_clock to 0
MyBzero((char *)&sleep_q, sizeof(q_t)); //reset sleep_q
//phase 4
MyBzero((char *)&msg_q, sizeof(msg_q_t));
}
示例2: bfs
int bfs(int source, int dest){
int u, v;
int d[300+10] , visited[300+10];
for(int i=0;i<305;i++) {d[i] = 10000; visited[i] = 0;}
d[source] = 0;
parent[source] = -1;
visited[source] = 1;
EnQ(source);
while(Q_Empty()==0){
u = DeQ();
for(v=1; v<=Total_Router; v++){
if(routing_table[u][v]==1&&visited[v]==0){
d[v] = d[u] + 1;
visited[v] = 1;
parent[v] = u;
EnQ(v);
}
}
}
return d[dest];
}
示例3: TimerISR
void TimerISR()
{
outportb(0x20, 0x60); // dismiss timer interrupt
// deal with sleep items
sys_tick++;
while(!EmptyQ(&sleep_q) && (pcbs[sleep_q.q[sleep_q.head]].wake_tick <= sys_tick)) {
int tmpPID = DeQ(&sleep_q);
pcbs[tmpPID].state=READY;
EnQ(tmpPID, &ready_q);
}
if(cur_pid == 0) return; // if Idle process, no need to do this on it
pcbs[cur_pid].tick_count++;
if(pcbs[cur_pid].tick_count == TIME_SLICE) // running up time, preempt it?
{
pcbs[cur_pid].tick_count = 0; // reset (roll over) usage time
pcbs[cur_pid].total_tick_count += TIME_SLICE; // sum to total
pcbs[cur_pid].state = READY; // change its state
EnQ(cur_pid, &ready_q); // move it to ready_q
cur_pid = -1; // no longer running
}
}
示例4: InitData
void InitData()
{
int i;
// queue initializations, both queues are empty first
InitQ(&avail_q);
InitQ(&ready_q);
InitQ(&avail_sem_q);
for(i=2; i < NUM_PROC ; i++) // init pcbs[], skip 0 since it's Idle Proc
{
pcbs[i].state = AVAIL;
EnQ(i, &avail_q);
}
for(i=NUM_SEM-1; i >= 0; i--) // init pcbs[], skip 0 since it's Idle Proc
{
EnQ(i, &avail_sem_q);
}
cur_pid = -1; // no process is running initially
sys_tick = 0; // Set sys_tick to 0
InitQ(&sleep_q); // reset sleep_q to empty
}
示例5: TimerISR
void TimerISR()
{
int sleep_pid;
// dismiss IRQ 0 at PIC control reg (0x20), if IRQ 7, send 0x67)
outportb(0x20, 0x60);
sys_tick++;
while( !EmptyPQ(&sleep_q) && ( peek(&sleep_q) <= sys_tick )){
sleep_pid = DePQ(&sleep_q);
EnQ(sleep_pid, &ready_q);
pcbs[sleep_pid].state = READY;
}
if(cur_pid == 0) return; // if Idle process, no need to do this on it
pcbs[cur_pid].tick_count++;
if(pcbs[cur_pid].tick_count == TIME_SLICE) // running up time, preempt it?
{
pcbs[cur_pid].tick_count = 0; // reset (roll over) usage time
pcbs[cur_pid].total_tick_count += TIME_SLICE; // sum to total
pcbs[cur_pid].state = READY; // change its state
EnQ(cur_pid, &ready_q); // move it to ready_q
cur_pid = -1; // no longer running
}
}
示例6: InitData
void InitData()
{
int i;
char * nextFramePtr =
(char *) ( (int) (_topHeapMemory + PAGE_SIZE) //bump up
& ( ~(PAGE_SIZE-1) ) ) ; //mask down
cur_page = 0;
InitQ(&avail_q); // set queues initially empty
InitQ(&ready_q);
InitQ(&sleep_q);
InitQ(&avail_sem_q);
for(i=2; i<NUM_PROC; i++) // skip 0 (IdleProc) and 1 (Init)
{
pcbs[i].state = AVAIL;
EnQ(i, &avail_q);
}
for(i=NUM_SEM-1; i>=0; i--) EnQ(i, &avail_sem_q); // avail sem ID's 19-0
for(i = 0; i < NUM_PAGE; i++){
pages[i].available = 1;
pages[i].addr = nextFramePtr;
pages[i].pid = -1;
nextFramePtr += PAGE_SIZE;
}
}
示例7: MsgSndISR
void MsgSndISR()
{
int mid, pid;
msg_t *src, *dest;
mid = pcbs[cur_pid].tf_p->eax;
src = (msg_t *)pcbs[cur_pid].tf_p->ebx;
src->sender = cur_pid; // authenticate sender
src->time_stamp = sys_tick; // authenticate time_stamp
if(EmptyQ(&mboxes[mid].wait_q))
{
MsgEnQ( src, &( mboxes[mid].msg_q ) );
}
else
{
pid = DeQ(&mboxes[mid].wait_q);
pcbs[pid].state = READY;
EnQ(pid, &ready_q);
dest = (msg_t *)pcbs[pid].tf_p->eax; // eax since MsgRcv changed
*dest = *src;
}
}
示例8: MsgSndISR
////////////phase 4
void MsgSndISR(int msg_addr)
{
int msg_q_id;
int freed_pid;
msg_t *incoming_msg_ptr, *dst_msg_ptr;
incoming_msg_ptr = (msg_t *) msg_addr;
msg_q_id = incoming_msg_ptr->recipient;
incoming_msg_ptr->OS_clock = OS_clock;
incoming_msg_ptr->sender = running_pid;
if(msg_q[msg_q_id].wait_q.len == 0)
{
MsgEnQ(incoming_msg_ptr, &msg_q[msg_q_id]);
}
else
{
freed_pid = DeQ(&(msg_q[msg_q_id].wait_q));
EnQ(freed_pid, &ready_q);
pcb[freed_pid].state = READY;
dst_msg_ptr = (msg_t *) pcb[freed_pid].TF_ptr->eax;
*dst_msg_ptr = *incoming_msg_ptr;
}
}
示例9: TimerISR
void TimerISR() {
//just return if running PID is -1 (not any valid PID)
if(running_pid == -1){
cons_printf("PANIC MESSAGE: RUNNING PID = -1\n");
return;
}else{
//in PCB, upcount both runtime and total_runtime of running process
pcb[running_pid].runtime = pcb[running_pid].runtime+1;
pcb[running_pid].total_runtime = pcb[running_pid].total_runtime+1;
if(pcb[running_pid].runtime== TIME_LIMIT){ // If runtime has reached TIME_LIMIT
// Reset runtime
// Change the state to READY
// queue to ready_q
// Set pid to -1
pcb[running_pid].runtime = 0;
pcb[running_pid].state = READY;
EnQ(running_pid, &ready_q);
running_pid = -1;
Scheduler();
}
}
}
示例10: StartProcISR
void StartProcISR(int new_pid) {
//clear the PCB of the new pid
MyBzero((char *) &pcb[new_pid], sizeof(pcb_t));
//set its state to READY
pcb[new_pid].state = READY;
//if new pid is not 0 (IdleProc),
//then, enqueue this new pid into the ready queue*/
if(new_pid != 0){
EnQ(new_pid, &ready_q);
}
//Clears the stack
MyBzero((char *) &proc_stack[new_pid], PROC_STACK_SIZE);
//Set TF_ptr of PCB close to end (top) of stack, then fill out
pcb[new_pid].TF_ptr = (TF_t *) &proc_stack[new_pid][PROC_STACK_SIZE - sizeof(TF_t)];
pcb[new_pid].TF_ptr->eflags = EF_DEFAULT_VALUE|EF_INTR; // set INTR flag
pcb[new_pid].TF_ptr->cs = get_cs(); // standard fair
pcb[new_pid].TF_ptr->ds = get_ds(); // standard fair
pcb[new_pid].TF_ptr->es = get_es(); // standard fair
pcb[new_pid].TF_ptr->fs = get_fs(); // standard fair
pcb[new_pid].TF_ptr->gs = get_gs(); // standard fair
if(new_pid == 0){
pcb[new_pid].TF_ptr->eip = (unsigned int) IdleProc; // if pid is 0, points to IdleProc
}else{
pcb[new_pid].TF_ptr->eip = (unsigned int) UserProc; // or UserProc
}
}
示例11: StartProcISR
void StartProcISR(int new_pid, int func_addr)
{
MyBzero((char *) &pcb[new_pid], sizeof(pcb_t)); //clear the PCB of the new pid
//phase 5
MyBzero((char *) &msg_q[new_pid], sizeof(msg_q_t));
pcb[new_pid].state = READY; //set its state to READY
if(new_pid != 0) //if new pid is not 0 (IdleProc),
{
EnQ(new_pid, &ready_q); //then, enqueue this new pid into the ready queue
}
//build initial trapframe in proc stack
MyBzero((char *)&proc_stack[new_pid], PROC_STACK_SIZE); //call MyBzero() to clear the stack 1st
pcb[new_pid].TF_ptr = (TF_t *) &proc_stack[new_pid][PROC_STACK_SIZE - sizeof(TF_t)]; //set TF_ptr of PCB to close to end (top) of stack
pcb[new_pid].TF_ptr->eflags = EF_DEFAULT_VALUE|EF_INTR; //set INTR flag
pcb[new_pid].TF_ptr->cs = get_cs(); //standard fair
pcb[new_pid].TF_ptr->ds = get_ds(); //standard fair
pcb[new_pid].TF_ptr->es = get_es(); //standard fair
pcb[new_pid].TF_ptr->fs = get_fs(); //standard fair
pcb[new_pid].TF_ptr->gs = get_gs(); //standard fair
pcb[new_pid].TF_ptr->eip = func_addr;
}
示例12: MsgSndISR
void MsgSndISR()
{
int mid,pid,head;
msg_t *source, *destination;
mid = pcbs[cur_pid].tf_p ->eax;
source = (msg_t*)pcbs[cur_pid].tf_p -> ebx;
if(!EmptyQ(&mboxes[mid].wait_q))
{
pid = DeQ(&mboxes[mid].wait_q);
EnQ(pid,&ready_q);
pcbs[pid].state = READY;
destination = (msg_t *)pcbs[pid].tf_p -> ebx;
MyMemCpy((char*)destination,(char*)source,sizeof(msg_t));
}
else
{
EnQMsg(source, &mboxes[mid].msg_q);
head = mboxes[mid].msg_q.head;
destination = &mboxes[mid].msg_q.msgs[head];
}
destination->sender = cur_pid;
destination->send_tick = sys_tick;
}
示例13: SpawnISR
void SpawnISR(int pid, func_ptr_t addr)
{
MyBZero(user_stacks[pid], USER_STACK_SIZE);
MyBZero((char *) &mboxes[pid], sizeof(mbox_t));
// 1st. point to just above of user stack, then drop by 64 bytes (tf_t)
pcbs[pid].tf_p = (tf_t *)&user_stacks[pid][USER_STACK_SIZE];
pcbs[pid].tf_p--; // pointer arithmetic, now points to trapframe
// fill in CPU's register context
pcbs[pid].tf_p->eflags = EF_DEFAULT_VALUE|EF_INTR;
//pcbs[pid].tf_p->eip = (unsigned int)SimpleProc; // new process code
pcbs[pid].tf_p->eip = (unsigned int)addr;
pcbs[pid].tf_p->cs = get_cs();
pcbs[pid].tf_p->ds = get_ds();
pcbs[pid].tf_p->es = get_es();
pcbs[pid].tf_p->fs = get_fs();
pcbs[pid].tf_p->gs = get_gs();
pcbs[pid].tick_count = pcbs[pid].total_tick_count = 0;
pcbs[pid].state = READY;
if(pid != 0) EnQ(pid, &ready_q); // IdleProc (PID 0) is not queued
}
示例14: StartProcISR
void StartProcISR(int new_pid, int func_addr) {
MyBzero( (char*) &pcb[new_pid], sizeof (pcb_t));
//clear process msg queue
MyBzero( (char*) &msg_q[new_pid], sizeof (msg_q_t));
pcb[new_pid].state= READY;
if(new_pid > 0 ) {
EnQ(new_pid, &ready_q);
}
MyBzero( (char*) &proc_stack[new_pid], PROC_STACK_SIZE);
pcb[new_pid].TF_ptr =(TF_t*) &proc_stack[new_pid][PROC_STACK_SIZE];
pcb[new_pid].TF_ptr--;
pcb[new_pid].TF_ptr->eflags = EF_DEFAULT_VALUE|EF_INTR; // set INTR flag
pcb[new_pid].TF_ptr->cs = get_cs(); // standard fair
pcb[new_pid].TF_ptr->ds = get_ds(); // standard fair
pcb[new_pid].TF_ptr->es = get_es(); // standard fair
pcb[new_pid].TF_ptr->fs = get_fs(); // standard fair
pcb[new_pid].TF_ptr->gs = get_gs(); // standard fair
pcb[new_pid].TF_ptr->eip = (unsigned int) func_addr;
}
示例15: BFS
int BFS(void)
{
int r,c,d,cl;
Cost[sr][sc][0][0]=0;
EnQ(sr,sc,0,0);
while(DeQ(&r,&c,&d,&cl))
{
if(r==dr && c==dc && cl==0) return 1;
if(Valid(r,c,d,cl,r+Gr[d],c+Gc[d],d,(cl+1)%5,1))
EnQ(r+Gr[d],c+Gc[d],d,(cl+1)%5);
if(Valid(r,c,d,cl,r,c,(d+1)%4,cl,1))
EnQ(r,c,(d+1)%4,cl);
if(Valid(r,c,d,cl,r,c,(d+3)%4,cl,1))
EnQ(r,c,(d+3)%4,cl);
}
return 0;
}