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); }
int ResourceDebugInterface::getCount(const QString &module) const { SugarSession *session = mResource->mSession; KDSoapGenerated::Sugarsoap *soap = session->soap(); const QString sessionId = session->sessionId(); if (sessionId.isEmpty()) { qCWarning(FATCRM_SUGARCRMRESOURCE_LOG) << "No session! Need to login first."; } // for notes and emails, use this: //const QString query = QString("parent_type=\"Opportunities\""); const QString query = QString(); KDSoapGenerated::TNS__Get_entries_count_result response = soap->get_entries_count(sessionId, module, query, 0); qCDebug(FATCRM_SUGARCRMRESOURCE_LOG) << response.result_count() << "entries"; // Let's also take a peek at the first entry KDSoapGenerated::TNS__Select_fields fields; fields.setItems(availableFields(module)); const auto listResponse = soap->get_entry_list(sessionId, module, query, QString() /*orderBy*/, 0 /*offset*/, fields, {}, 1 /*maxResults*/, 0 /*fetchDeleted*/, false /*favorites*/); const QList<KDSoapGenerated::TNS__Entry_value> items = listResponse.entry_list().items(); if (!items.isEmpty()) { QList<KDSoapGenerated::TNS__Name_value> values = items.at(0).name_value_list().items(); Q_FOREACH (const KDSoapGenerated::TNS__Name_value &value, values) { qCDebug(FATCRM_SUGARCRMRESOURCE_LOG) << value.name() << "=" << value.value(); }
/* select the next thread in the ready list with top_prio */ static void select_next_thread(int top_prio) { list_node_t *pnode; /* otherwise, threads in a ready state, then run the highest * priority one. */ pnode = delete_front_list(&ready_list[top_prio]); if (is_empty_list(&ready_list[top_prio])) prio_exist_flag[top_prio] = false; next_thread = entry_list(pnode, thread_struct, node); next_thread->state = RUNNING; next_thread->time_quantum = TIME_QUANTUM; }
void start_curt() { cpu_sr_t cpu_sr; list_node_t *pnode; int top_prio; cpu_sr = save_cpu_sr(); is_start_os = true; /* examine the highest priority thread executed */ top_prio = get_top_prio(); pnode = delete_front_list(&ready_list[top_prio]); if (is_empty_list(&ready_list[top_prio])) prio_exist_flag[top_prio] = false; current_thread = entry_list(pnode, thread_struct, node); current_thread->state = RUNNING; restore_cpu_sr(cpu_sr); restore_context(); }
/** * @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 sem_post(sem_struct *sem) { thread_struct *pthread; cpu_sr_t cpu_sr; cpu_sr = save_cpu_sr(); if (!is_empty_list(&sem->wait_list)) { pthread = entry_list(delete_front_list(&sem->wait_list), thread_struct, node); pthread->state = READY; insert_back_list(&ready_list[pthread->prio], &pthread->node); prio_exist_flag[pthread->prio] = true; restore_cpu_sr(cpu_sr); schedule(SCHED_THREAD_REQUEST); return; } sem->value++; restore_cpu_sr(cpu_sr); }
/** * @brief rountine for idle thread * @param data */ void idle_thread_func(void *data) { cpu_sr_t cpu_sr; thread_struct *pthread; list_node_t *pnode; while (1) { cpu_sr = save_cpu_sr(); /* check if there is any terminated thread to be recycled */ if (!is_empty_list(&termination_wait_list)) { pnode = delete_front_list(&termination_wait_list); pthread = entry_list(pnode, thread_struct, node); thread_table[pthread->tid] = NULL; total_thread_cnt--; } restore_cpu_sr(cpu_sr); /* always does this */ thread_yield(); } }
Index TripletToCSRConverter::InitializeConverter(Index dim, Index nonzeros, const Index* airn, const Index* ajcn) { DBG_START_METH("TSymLinearSolver::InitializeStructure", dbg_verbosity); DBG_ASSERT(dim>0); DBG_ASSERT(nonzeros>0); delete[] ia_; delete[] ja_; delete[] ipos_first_; delete[] ipos_double_triplet_; delete[] ipos_double_compressed_; dim_ = dim; nonzeros_triplet_ = nonzeros; // Create a list with all triplet entries std::list<TripletEntry> entry_list(nonzeros); std::list<TripletEntry>::iterator list_iterator = entry_list.begin(); for (Index i=0; i<nonzeros; i++) { list_iterator->Set(airn[i], ajcn[i], i); list_iterator++; } DBG_ASSERT(list_iterator == entry_list.end()); if (DBG_VERBOSITY()>=2) { for (Index i=0; i<nonzeros; i++) { DBG_PRINT((2, "airn[%5d] = %5d acjn[%5d] = %5d\n", i, airn[i], i, ajcn[i])); } } // sort the list entry_list.sort(); // Now got through the list and compute ipos_ arrays and the // number of elements in the compressed format Index* ja_tmp = new Index[nonzeros]; // overestimate memory requirement Index* rc_tmp = NULL; if (hf_ == Full_Format) { rc_tmp = new Index[dim_+1]; } ia_ = new Index[dim_+1]; Index* ipos_first_tmp = new Index[nonzeros]; // overestimate memory requirement Index* ipos_double_triplet_tmp = new Index[nonzeros]; // overestimate memory requirement Index* ipos_double_compressed_tmp = new Index[nonzeros]; // overestimate memory requirement Index nonzeros_compressed_full = 0; nonzeros_compressed_ = 0; Index cur_row = 1; if (hf_ == Full_Format) { // Zero row counts for (Index i=0; i<dim_+1; i++) { rc_tmp[i] = 0; } } // Take care of possible emply rows list_iterator = entry_list.begin(); while (cur_row < list_iterator->IRow()) { ia_[cur_row-1] = 0; cur_row++; } ia_[cur_row-1] = 0; ja_tmp[0] = list_iterator->JCol(); ipos_first_tmp[0] = list_iterator->PosTriplet(); if (hf_ == Full_Format) { // Count in both lower and upper triangles. Count diagonal only once. nonzeros_compressed_full++; rc_tmp[cur_row-1]++; if (cur_row!=list_iterator->JCol()) { nonzeros_compressed_full++; rc_tmp[list_iterator->JCol()-1]++; } } list_iterator++; Index idouble = 0; Index idouble_full = 0; while (list_iterator != entry_list.end()) { Index irow = list_iterator->IRow(); Index jcol = list_iterator->JCol(); if (cur_row == irow && ja_tmp[nonzeros_compressed_] == jcol) { // This element appears repeatedly, add to the double list ipos_double_triplet_tmp[idouble] = list_iterator->PosTriplet(); ipos_double_compressed_tmp[idouble] = nonzeros_compressed_; idouble++; idouble_full++; if (hf_==Full_Format && irow!=jcol) { idouble_full++; } } else { // This is a new element if (hf_==Full_Format) { // Count in both lower and upper triangles. Count diagonal only once. nonzeros_compressed_full++; rc_tmp[jcol-1]++; if (irow!=jcol) { nonzeros_compressed_full++; rc_tmp[irow-1]++; } } nonzeros_compressed_++; ja_tmp[nonzeros_compressed_] = jcol; ipos_first_tmp[nonzeros_compressed_] = list_iterator->PosTriplet(); if (cur_row != irow) { // this is in a new row ia_[cur_row] = nonzeros_compressed_; cur_row++; } } list_iterator++; } nonzeros_compressed_++; for (Index i=cur_row; i<=dim_; i++) { ia_[i] = nonzeros_compressed_; } DBG_ASSERT(idouble == nonzeros_triplet_-nonzeros_compressed_); // Now copy the ja_tmp array to the (shorter) final one and make // sure that the correct offset is used if (hf_==Triangular_Format) { ja_ = new Index[nonzeros_compressed_]; if (offset_==0) { for (Index i=0; i<nonzeros_compressed_; i++) { ja_[i] = ja_tmp[i] - 1; } } else { for (Index i=0; i<nonzeros_compressed_; i++) { ja_[i] = ja_tmp[i]; } for (Index i=0; i<=dim_; i++) { ia_[i] = ia_[i] + 1; } } delete[] ja_tmp; // Reallocate memory for the "first" array ipos_first_ = new Index[nonzeros_compressed_]; for (Index i=0; i<nonzeros_compressed_; i++) { ipos_first_[i] = ipos_first_tmp[i]; } delete[] ipos_first_tmp; // Reallocate memory for the "double" arrays ipos_double_triplet_ = new Index[idouble]; ipos_double_compressed_ = new Index[idouble]; for (Index i=0; i<idouble; i++) { ipos_double_triplet_[i] = ipos_double_triplet_tmp[i]; ipos_double_compressed_[i] = ipos_double_compressed_tmp[i]; } delete[] ipos_double_triplet_tmp; delete[] ipos_double_compressed_tmp; num_doubles_ = nonzeros_triplet_ - nonzeros_compressed_; } else { // hf_==Full_Format // Setup ia_tmp to contain insert position for column i as ia_tmp[i+1] Index *ia_tmp = new Index[dim_+1]; ia_tmp[0] = 0; ia_tmp[1] = 0; for (Index i=1; i<dim_; i++) { ia_tmp[i+1] = ia_tmp[i] + rc_tmp[i-1]; } delete[] rc_tmp; // Loop over elements of matrix, copying them and duplicating as required ja_ = new Index[nonzeros_compressed_full]; ipos_first_ = new Index[nonzeros_compressed_full]; ipos_double_triplet_ = new Index[idouble_full]; ipos_double_compressed_ = new Index[idouble_full]; Index jd1=0; // Entry into ipos_double_compressed_tmp Index jd2=0; // Entry into ipos_double_compressed_ for (Index i=0; i<dim_; i++) { for (Index j=ia_[i]; j<ia_[i+1]; j++) { Index jrow = ja_tmp[j]-1; ja_[ia_tmp[i+1]] = jrow + offset_; ipos_first_[ia_tmp[i+1]] = ipos_first_tmp[j]; while (jd1<idouble && j==ipos_double_compressed_tmp[jd1]) { ipos_double_triplet_[jd2] = ipos_double_triplet_tmp[jd1]; ipos_double_compressed_[jd2] = ia_tmp[i+1]; jd2++; if (jrow!=i) { ipos_double_triplet_[jd2] = ipos_double_triplet_tmp[jd1]; ipos_double_compressed_[jd2] = ia_tmp[jrow+1]; } jd1++; } ia_tmp[i+1]++; if (jrow!=i) { ja_[ia_tmp[jrow+1]] = i + offset_; ipos_first_[ia_tmp[jrow+1]] = ipos_first_tmp[j]; ia_tmp[jrow+1]++; } } } delete[] ja_tmp; delete[] ipos_first_tmp; delete[] ipos_double_triplet_tmp; delete[] ipos_double_compressed_tmp; // Copy ia_tmp to ia_ with offset_ adjustment for (Index i=0; i<dim_+1; i++) { ia_[i] = ia_tmp[i] + offset_; } delete[] ia_tmp; // Set nonzeros_compressed_ to correct size nonzeros_compressed_ = nonzeros_compressed_full; num_doubles_ = idouble_full; } initialized_ = true; if (DBG_VERBOSITY()>=2) { for (Index i=0; i<=dim_; i++) { DBG_PRINT((2, "ia[%5d] = %5d\n", i, ia_[i])); } for (Index i=0; i<nonzeros_compressed_; i++) { DBG_PRINT((2, "ja[%5d] = %5d ipos_first[%5d] = %5d\n", i, ja_[i], i, ipos_first_[i])); } for (Index i=0; i<nonzeros_triplet_-nonzeros_compressed_; i++) { DBG_PRINT((2, "ipos_double_triplet[%5d] = %5d ipos_double_compressed[%5d] = %5d\n", i, ipos_double_triplet_[i], i, ipos_double_compressed_[i])); } } return nonzeros_compressed_; }
Index TripletToCSRConverter::InitializeConverter(Index dim, Index nonzeros, const Index* airn, const Index* ajcn) { DBG_START_METH("TSymLinearSolver::InitializeStructure", dbg_verbosity); DBG_ASSERT(dim>0); DBG_ASSERT(nonzeros>0); delete[] ia_; delete[] ja_; delete[] ipos_first_; delete[] ipos_double_triplet_; delete[] ipos_double_compressed_; dim_ = dim; nonzeros_triplet_ = nonzeros; // Create a list with all triplet entries std::list<TripletEntry> entry_list(nonzeros); std::list<TripletEntry>::iterator list_iterator = entry_list.begin(); for (Index i=0; i<nonzeros; i++) { list_iterator->Set(airn[i], ajcn[i], i); ++list_iterator; } DBG_ASSERT(list_iterator == entry_list.end()); if (DBG_VERBOSITY()>=2) { for (Index i=0; i<nonzeros; i++) { DBG_PRINT((2, "airn[%5d] = %5d acjn[%5d] = %5d\n", i, airn[i], i, ajcn[i])); } } // sort the list entry_list.sort(); // Now got through the list and compute ipos_ arrays and the // number of elements in the compressed format Index* ja_tmp = new Index[nonzeros]; // overestimate memory requirement ia_ = new Index[dim_+1]; Index* ipos_first_tmp = new Index[nonzeros]; // overestimate memory requirement Index* ipos_double_triplet_tmp = new Index[nonzeros]; // overestimate memory requirement Index* ipos_double_compressed_tmp = new Index[nonzeros]; // overestimate memory requirement nonzeros_compressed_ = 0; Index cur_row = 1; // The first element must be the first diagonal element list_iterator = entry_list.begin(); DBG_ASSERT(list_iterator->IRow()==1); DBG_ASSERT(list_iterator->JCol()==1); ia_[0] = 0; ja_tmp[0] = 1; ipos_first_tmp[0] = list_iterator->PosTriplet(); ++list_iterator; Index idouble = 0; while (list_iterator != entry_list.end()) { Index irow = list_iterator->IRow(); Index jcol = list_iterator->JCol(); if (cur_row == irow && ja_tmp[nonzeros_compressed_] == jcol) { // This element appears repeatedly, add to the double list ipos_double_triplet_tmp[idouble] = list_iterator->PosTriplet(); ipos_double_compressed_tmp[idouble] = nonzeros_compressed_; idouble++; } else { // This is a new element nonzeros_compressed_++; ja_tmp[nonzeros_compressed_] = jcol; ipos_first_tmp[nonzeros_compressed_] = list_iterator->PosTriplet(); if (cur_row != irow) { // this is in a new row // make sure that the diagonal element is given and that no // row is omitted DBG_ASSERT(irow==jcol); DBG_ASSERT(cur_row+1==irow); ia_[cur_row] = nonzeros_compressed_; cur_row++; } } ++list_iterator; } nonzeros_compressed_++; ia_[dim_] = nonzeros_compressed_; DBG_ASSERT(cur_row == dim_); DBG_ASSERT(idouble == nonzeros_triplet_-nonzeros_compressed_); // Now copy the ja_tmp array to the (shorter) final one and make // sure that the correct offset is used ja_ = new Index[nonzeros_compressed_]; if (offset_==0) { for (Index i=0; i<nonzeros_compressed_; i++) { ja_[i] = ja_tmp[i] - 1; } } else { for (Index i=0; i<nonzeros_compressed_; i++) { ja_[i] = ja_tmp[i]; } for (Index i=0; i<=dim_; i++) { ia_[i] = ia_[i] + 1; } } delete[] ja_tmp; // Reallocate memory for the "first" array ipos_first_ = new Index[nonzeros_compressed_]; for (Index i=0; i<nonzeros_compressed_; i++) { ipos_first_[i] = ipos_first_tmp[i]; } delete[] ipos_first_tmp; // Reallocate memory for the "double" arrays ipos_double_triplet_ = new Index[idouble]; ipos_double_compressed_ = new Index[idouble]; for (Index i=0; i<idouble; i++) { ipos_double_triplet_[i] = ipos_double_triplet_tmp[i]; ipos_double_compressed_[i] = ipos_double_compressed_tmp[i]; } delete[] ipos_double_triplet_tmp; delete[] ipos_double_compressed_tmp; initialized_ = true; if (DBG_VERBOSITY()>=2) { for (Index i=0; i<=dim_; i++) { DBG_PRINT((2, "ia[%5d] = %5d\n", i, ia_[i])); } for (Index i=0; i<nonzeros_compressed_; i++) { DBG_PRINT((2, "ja[%5d] = %5d ipos_first[%5d] = %5d\n", i, ja_[i], i, ipos_first_[i])); } for (Index i=0; i<nonzeros_triplet_-nonzeros_compressed_; i++) { DBG_PRINT((2, "ipos_double_triplet[%5d] = %5d ipos_double_compressed[%5d] = %5d\n", i, ipos_double_triplet_[i], i, ipos_double_compressed_[i])); } } return nonzeros_compressed_; }