📄 evtbackup.c
字号:
/* Loop through list of indexes modified since last accepted timepoint */ num_modified = msg_data->num_modified; for(i = 0; i < num_modified; i++) { /* Get the port index */ port_index = msg_data->modified_index[i]; /* Scan data for this port from last_step to determine new setting */ /* for tail, and splice later data into the free list */ msg_ptr = msg_data->last_step[port_index]; msg = *msg_ptr; while(1) { if((msg->next == NULL) || (msg->next->step > new_time)) { /* Splice rest of list, if any, into free list */ head = msg->next; if(head) { tail = *(msg_data->tail[port_index]); free_head = msg_data->free[port_index]; msg_data->free[port_index] = head; tail->next = free_head; } /* Set the tail */ msg_data->tail[port_index] = msg_ptr; msg->next = NULL; break; } msg_ptr = &(msg->next); msg = msg->next; } } /* end for number modified */ /* Update/compact the modified list */ for(i = 0, j = 0; i < num_modified; i++) { port_index = msg_data->modified_index[i]; /* If nothing after last_step, remove this index from the modified list */ if((*(msg_data->last_step[port_index]))->next == NULL) { msg_data->modified[port_index] = MIF_FALSE; (msg_data->num_modified)--; } /* else, keep the index */ else { msg_data->modified_index[j] = msg_data->modified_index[i]; j++; } }}/*EVTbackup_inst_queue()Backup data in inst queue.*/static void EVTbackup_inst_queue( CKTcircuit *ckt, /* the main circuit structure */ double new_time) /* the time to backup to */{ int i; int j; int num_modified; int num_pending; int inst_index; Evt_Inst_Queue_t *inst_queue; Evt_Inst_Event_t **inst_ptr; Evt_Inst_Event_t *inst; double next_time; double event_time; /* Get pointers for quick access */ inst_queue = &(ckt->evt->queue.inst); /* Loop through list of indexes modified since last accepted timepoint */ /* and remove events with posted time > new_time */ num_modified = inst_queue->num_modified; for(i = 0; i < num_modified; i++) { /* Get the inst index */ inst_index = inst_queue->modified_index[i]; /* Scan forward from last_step and cut out data with posted time */ /* > new_time and add it to the free list */ inst_ptr = inst_queue->last_step[inst_index]; inst = *inst_ptr; while(inst) { if(inst->posted_time > new_time) { *inst_ptr = inst->next; inst->next = inst_queue->free[inst_index]; inst_queue->free[inst_index] = inst; inst = *inst_ptr; } else { inst_ptr = &(inst->next); inst = *inst_ptr; } } /* Scan forward from last_step and set current to first */ /* event with event_time > new_time */ inst_ptr = inst_queue->last_step[inst_index]; inst = *inst_ptr; while(inst) { if(inst->event_time > new_time) break; inst_ptr = &((*inst_ptr)->next); inst = *inst_ptr; } inst_queue->current[inst_index] = inst_ptr; } /* Add set of items modified to set of items pending before updating the */ /* pending list because things may have been pulled from the pending list */ for(i = 0; i < num_modified; i++) { j = inst_queue->modified_index[i]; if(! inst_queue->pending[j]) { inst_queue->pending[j] = MIF_TRUE; inst_queue->pending_index[(inst_queue->num_pending)++] = j; } } /* Update the pending list and the next time by seeing if there */ /* is anything at the location pointed to by current */ next_time = 1e30; num_pending = inst_queue->num_pending; for(i = 0, j = 0; i < num_pending; i++) { inst_index = inst_queue->pending_index[i]; inst = *(inst_queue->current[inst_index]); /* If nothing in queue at last_step, remove this index from the pending list */ if(! inst) { inst_queue->pending[inst_index] = MIF_FALSE; (inst_queue->num_pending)--; } /* else, keep the index and update the next time */ else { inst_queue->pending_index[j] = inst_queue->pending_index[i]; j++; event_time = inst->event_time; if(event_time < next_time) next_time = event_time; } } inst_queue->next_time = next_time; /* Update the modified list by looking for any queued events */ /* with posted time > last_time */ for(i = 0, j = 0; i < num_modified; i++) { inst_index = inst_queue->modified_index[i]; inst = *(inst_queue->last_step[inst_index]); while(inst) { if(inst->posted_time > inst_queue->last_time) break; inst = inst->next; } if(! inst) { inst_queue->modified[inst_index] = MIF_FALSE; (inst_queue->num_modified)--; } else { inst_queue->modified_index[j] = inst_queue->modified_index[i]; j++; } }}/*EVTbackup_output_queue()Backup data in output queue.*/static void EVTbackup_output_queue( CKTcircuit *ckt, /* the main circuit structure */ double new_time) /* the time to backup to */{ int i; int j; int num_modified; int num_pending; int output_index; Evt_Output_Queue_t *output_queue; Evt_Output_Event_t **output_ptr; Evt_Output_Event_t *output; double next_time; double event_time; /* Get pointers for quick access */ output_queue = &(ckt->evt->queue.output); /* Loop through list of indexes modified since last accepted timepoint */ /* and remove events with posted time > new_time */ num_modified = output_queue->num_modified; for(i = 0; i < num_modified; i++) { /* Get the output index */ output_index = output_queue->modified_index[i]; /* Scan forward from last_step and cut out data with posted time */ /* > new_time and add it to the free list */ /* Also, unremove anything with removed time > new_time */ output_ptr = output_queue->last_step[output_index]; output = *output_ptr; while(output) { if(output->posted_time > new_time) { *output_ptr = output->next; output->next = output_queue->free[output_index]; output_queue->free[output_index] = output; output = *output_ptr; } else { if(output->removed && (output->removed_time > new_time)) output->removed = MIF_FALSE; output_ptr = &(output->next); output = *output_ptr; } } /* Scan forward from last_step and set current to first */ /* event with event_time > new_time */ output_ptr = output_queue->last_step[output_index]; output = *output_ptr; while(output) { if(output->event_time > new_time) break; output_ptr = &((*output_ptr)->next); output = *output_ptr; } output_queue->current[output_index] = output_ptr; } /* Add set of items modified to set of items pending before updating the */ /* pending list because things may have been pulled from the pending list */ for(i = 0; i < num_modified; i++) { j = output_queue->modified_index[i]; if(! output_queue->pending[j]) { output_queue->pending[j] = MIF_TRUE; output_queue->pending_index[(output_queue->num_pending)++] = j; } } /* Update the pending list and the next time by seeing if there */ /* is anything at the location pointed to by current */ next_time = 1e30; num_pending = output_queue->num_pending; for(i = 0, j = 0; i < num_pending; i++) { output_index = output_queue->pending_index[i]; output = *(output_queue->current[output_index]); /* If nothing in queue at last_step, remove this index from the pending list */ if(! output) { output_queue->pending[output_index] = MIF_FALSE; (output_queue->num_pending)--; } /* else, keep the index and update the next time */ else { output_queue->pending_index[j] = output_queue->pending_index[i]; j++; event_time = output->event_time; if(event_time < next_time) next_time = event_time; } } output_queue->next_time = next_time; /* Update the modified list by looking for any queued events */ /* with posted time > last_time */ for(i = 0, j = 0; i < num_modified; i++) { output_index = output_queue->modified_index[i]; output = *(output_queue->last_step[output_index]); while(output) { if(output->posted_time > output_queue->last_time) break; output = output->next; } if(! output) { output_queue->modified[output_index] = MIF_FALSE; (output_queue->num_modified)--; } else { output_queue->modified_index[j] = output_queue->modified_index[i]; j++; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -