/*=============================================+ * disp_list -- Display list contents * used for drilldown in variable debugger * list: list to display *============================================*/ static void disp_list (LIST list) { struct dbgsymtab_s sdata; INT nels = length_list(list); if (!nels) { msg_info(_("list is empty")); return; } init_dbgsymtab_arrays(&sdata, nels); /* loop thru list building display array */ { LIST_ITER listit = begin_list(list); VPTR ptr = 0; while (next_list_ptr(listit, &ptr)) { PVALUE val = ptr; char key[10]; snprintf(key, sizeof(key), "%d", sdata.current+1); format_dbgsymtab_val(key, val, &sdata); } end_list_iter(&listit); } disp_dbgsymtab(_("LIST contents"), &sdata); free_dbgsymtab_arrays(&sdata); }
void sem_pend(sem_struct *sem) { cpu_sr_t cpu_sr; list_node_t *pnode; thread_struct *pthread; cpu_sr = save_cpu_sr(); if (sem->value == 0) { if (!is_empty_list(&sem->wait_list)) { for (pnode = begin_list(&sem->wait_list); pnode != end_list(&sem->wait_list); pnode = next_list(pnode)) { pthread = entry_list(pnode, thread_struct, node); if (current_thread->prio < pthread->prio) { current_thread->state = EVENT_WAIT; insert_before_list( pnode, ¤t_thread->node); break; } } } if (current_thread->state != EVENT_WAIT) { current_thread->state = EVENT_WAIT; insert_back_list(&sem->wait_list, ¤t_thread->node); } schedule(SCHED_THREAD_REQUEST); return; } sem->value--; restore_cpu_sr(cpu_sr); }
/** * @brief time tick advanced * Maintain time_quantum */ void advance_time_tick() { cpu_sr_t cpu_sr; list_node_t *pnode; thread_struct *pthread; thread_struct *readyed_thread = NULL; cpu_sr = save_cpu_sr(); os_time_tick++; /* If there are delays in the list of threads... */ if (!is_empty_list(&delayed_list)) { for (pnode = begin_list(&delayed_list); pnode != end_list(&delayed_list); pnode = next_list(pnode) ) { pthread = entry_list(pnode, thread_struct, node); pthread->delayed_time--; /* ready to change the status */ if (readyed_thread != NULL) { delete_list(&readyed_thread->node); readyed_thread->state = READY; readyed_thread->time_quantum = TIME_QUANTUM; insert_back_list( &ready_list[readyed_thread->prio], &readyed_thread->node); prio_exist_flag[readyed_thread->prio] = true; readyed_thread = NULL; } if (pthread->delayed_time <= 0) { readyed_thread = pthread; } } if (readyed_thread != NULL) { delete_list(&readyed_thread->node); readyed_thread->state = READY; readyed_thread->time_quantum = TIME_QUANTUM; insert_back_list( &ready_list[readyed_thread->prio], &readyed_thread->node); prio_exist_flag[readyed_thread->prio] = true; } } current_thread->time_quantum--; restore_cpu_sr(cpu_sr); }
void insert_front_list(list_t *plist, list_node_t *pnode) { insert_after_list(begin_list(plist), pnode); }
bool is_empty_list(list_t *plist) { return (begin_list(plist) == end_list(plist)); }