static restrict_u * match_restrict4_addr( u_int32 addr, u_short port ) { const int v6 = 0; restrict_u * res; restrict_u * next; for (res = restrictlist4; res != NULL; res = next) { struct in_addr sia = { htonl(res->u.v4.addr) }; next = res->link; DPRINTF(2, ("match_restrict4_addr: Checking %s, port %d ... ", inet_ntoa(sia), port)); if ( res->expire && res->expire <= current_time) free_res(res, v6); /* zeroes the contents */ if ( res->u.v4.addr == (addr & res->u.v4.mask) && ( !(RESM_NTPONLY & res->mflags) || NTP_PORT == port)) { DPRINTF(2, ("MATCH: ippeerlimit %d\n", res->ippeerlimit)); break; } DPRINTF(2, ("doesn't match: ippeerlimit %d\n", res->ippeerlimit)); } return res; }
static restrict_u * match_restrict6_addr( const struct in6_addr * addr, u_short port ) { const int v6 = 1; restrict_u * res; restrict_u * next; struct in6_addr masked; for (res = restrictlist6; res != NULL; res = next) { next = res->link; INSIST(next != res); if (res->expire && res->expire <= current_time) free_res(res, v6); MASK_IPV6_ADDR(&masked, addr, &res->u.v6.mask); if (ADDR6_EQ(&masked, &res->u.v6.addr) && (!(RESM_NTPONLY & res->mflags) || NTP_PORT == (int)port)) break; } return res; }
/* * restrict_source - maintains dynamic "restrict source ..." entries as * peers come and go. */ void restrict_source( sockaddr_u * addr, int farewell, /* 0 to add, 1 to remove */ u_long expire /* 0 is infinite, valid until */ ) { sockaddr_u onesmask; restrict_u * res; int found_specific; if (!restrict_source_enabled || SOCK_UNSPEC(addr) || IS_MCAST(addr) || ISREFCLOCKADR(addr)) return; REQUIRE(AF_INET == AF(addr) || AF_INET6 == AF(addr)); SET_HOSTMASK(&onesmask, AF(addr)); if (farewell) { hack_restrict(RESTRICT_REMOVE, addr, &onesmask, 0, 0, 0); DPRINTF(1, ("restrict_source: %s removed", stoa(addr))); return; } /* * If there is a specific entry for this address, hands * off, as it is condidered more specific than "restrict * server ...". * However, if the specific entry found is a fleeting one * added by pool_xmit() before soliciting, replace it * immediately regardless of the expire value to make way * for the more persistent entry. */ if (IS_IPV4(addr)) { res = match_restrict4_addr(SRCADR(addr), SRCPORT(addr)); INSIST(res != NULL); found_specific = (SRCADR(&onesmask) == res->u.v4.mask); } else { res = match_restrict6_addr(&SOCK_ADDR6(addr), SRCPORT(addr)); INSIST(res != NULL); found_specific = ADDR6_EQ(&res->u.v6.mask, &SOCK_ADDR6(&onesmask)); } if (!expire && found_specific && res->expire) { found_specific = 0; free_res(res, IS_IPV6(addr)); } if (found_specific) return; hack_restrict(RESTRICT_FLAGS, addr, &onesmask, restrict_source_mflags, restrict_source_flags, expire); DPRINTF(1, ("restrict_source: %s host restriction added\n", stoa(addr))); }
int cmd_alter(int argc,const char **argv){ // check necessary param check_cmd_args(argc,argv); st_show_sql *stsql=(st_show_sql*)malloc(sizeof(st_show_sql)); char type[50]; char like[50]; const char *table=""; char sql[125]; while(*argv){ if(!strcmp(*argv,"--tables")){ stsql->type=*argv+2; argv++; }else if(!strcmp(*argv,"--columns")){ const char *t=*argv+2; argv++; if(!start_with(*argv,"--")){ usage("about show --columns table-name"); } sprintf(type,"%s FROM %s%s",t,DBPRE,*argv); stsql->type=type; argv++; }else if(!strcmp(*argv,"--create")){ const char *t=*argv+2; argv++; if(!start_with(*argv,"--")){ usage("about show --create table-name"); } sprintf(type,"%s TABLE %s%s",t,DBPRE,*argv); stsql->type=type; argv++; }else if(!strcmp(*argv,"--variables")){ stsql->type=*argv+2; argv++; }else if(!strcmp(*argv,"--like")){ argv++; cat_sql_like(*argv,like); argv++; }else{ argv++; } } stsql->table=table; stsql->like=like; parse_show_sql(stsql,sql); MYSQL_RES *res=select(sql); print_sql_result(res,1); free_res(res); return 0; }
Song::Song(int id) { MYSQL_RES* res = query("SELECT id, title, path, type FROM song WHERE id = '" + esc(intString(id)) + "'"); if (num_rows(res)) { MYSQL_ROW row = next_res(res); this->id = stringInt(row[0]); this->title = row[1]; this->path = row[2]; this->type = row[3]; } free_res(res); }
//--------------------------------------------------------------- void hxc_buttonpicker::destroy(hxc_buttonpicker *This) { if (This->XD==NULL) return; RemoveProp(This->XD,This->handle,cWinProc); RemoveProp(This->XD,This->handle,cWinThis); hxc::kill_timer(This->handle,HXC_TIMER_ALL_IDS); XDestroyWindow(This->XD,This->handle); free_res(This->XD); This->handle=0; This->XD=NULL; }
void hxc_scrollbar::destroy(hxc_scrollbar *This) { if (This->XD==NULL) return; This->UpBut.destroy(&(This->UpBut)); This->DownBut.destroy(&(This->DownBut)); RemoveProp(This->XD,This->handle,cWinProc); RemoveProp(This->XD,This->handle,cWinThis); XDestroyWindow(This->XD,This->handle); free_res(This->XD); This->handle=0; This->XD=NULL; }
int main(int argc, char **argv) { int op, ret; opts = INIT_OPTS; opts.options |= FT_OPT_SIZE; hints = fi_allocinfo(); if (!hints) return EXIT_FAILURE; while ((op = getopt(argc, argv, "h" CS_OPTS INFO_OPTS)) != -1) { switch (op) { default: ft_parseinfo(op, optarg, hints); ft_parsecsopts(op, optarg, &opts); break; case '?': case 'h': ft_csusage(argv[0], "Streaming RDM client-server using multi recv buffer."); return EXIT_FAILURE; } } if (optind < argc) opts.dst_addr = argv[optind]; hints->ep_attr->type = FI_EP_RDM; hints->caps = FI_MSG | FI_MULTI_RECV; hints->mode = FI_CONTEXT; hints->domain_attr->mr_mode = FI_MR_LOCAL | OFI_MR_BASIC_MAP; cq_attr.format = FI_CQ_FORMAT_DATA; ret = run(); free_res(); ft_free_res(); return ft_exit_code(ret); }
static restrict_u * match_restrict4_addr( u_int32 addr, u_short port ) { const int v6 = 0; restrict_u * res; restrict_u * next; for (res = restrictlist4; res != NULL; res = next) { next = res->link; if (res->expire && res->expire <= current_time) free_res(res, v6); if (res->u.v4.addr == (addr & res->u.v4.mask) && (!(RESM_NTPONLY & res->mflags) || NTP_PORT == port)) break; } return res; }
int main(int argc, char **argv) { int ret, op; opts = INIT_OPTS; opts.options = FT_OPT_SIZE; hints = fi_allocinfo(); if (!hints) return EXIT_FAILURE; while ((op = getopt(argc, argv, "h" ADDR_OPTS INFO_OPTS)) != -1) { switch (op) { default: ft_parse_addr_opts(op, optarg, &opts); ft_parseinfo(op, optarg, hints); break; case '?': case 'h': ft_usage(argv[0], "An RDM client-server example with scalable endpoints.\n"); return EXIT_FAILURE; } } if (optind < argc) opts.dst_addr = argv[optind]; hints->ep_attr->type = FI_EP_RDM; hints->caps = FI_MSG | FI_NAMED_RX_CTX; hints->mode = FI_LOCAL_MR; ret = run(); free_res(); /* Closes the scalable ep that was allocated in the test */ FT_CLOSE_FID(sep); ft_free_res(); return -ret; }
/* * hack_restrict - add/subtract/manipulate entries on the restrict list */ void hack_restrict( int op, sockaddr_u * resaddr, sockaddr_u * resmask, u_short mflags, u_short flags, u_long expire ) { int v6; restrict_u match; restrict_u * res; restrict_u ** plisthead; DPRINTF(1, ("restrict: op %d addr %s mask %s mflags %08x flags %08x\n", op, stoa(resaddr), stoa(resmask), mflags, flags)); if (NULL == resaddr) { REQUIRE(NULL == resmask); REQUIRE(RESTRICT_FLAGS == op); restrict_source_flags = flags; restrict_source_mflags = mflags; restrict_source_enabled = 1; return; } ZERO(match); #if 0 /* silence VC9 potentially uninit warnings */ // HMS: let's use a compiler-specific "enable" for this. res = NULL; v6 = 0; #endif if (IS_IPV4(resaddr)) { v6 = 0; /* * Get address and mask in host byte order for easy * comparison as u_int32 */ match.u.v4.addr = SRCADR(resaddr); match.u.v4.mask = SRCADR(resmask); match.u.v4.addr &= match.u.v4.mask; } else if (IS_IPV6(resaddr)) { v6 = 1; /* * Get address and mask in network byte order for easy * comparison as byte sequences (e.g. memcmp()) */ match.u.v6.mask = SOCK_ADDR6(resmask); MASK_IPV6_ADDR(&match.u.v6.addr, PSOCK_ADDR6(resaddr), &match.u.v6.mask); } else /* not IPv4 nor IPv6 */ REQUIRE(0); match.flags = flags; match.mflags = mflags; match.expire = expire; res = match_restrict_entry(&match, v6); switch (op) { case RESTRICT_FLAGS: /* * Here we add bits to the flags. If this is a * new restriction add it. */ if (NULL == res) { if (v6) { res = alloc_res6(); memcpy(res, &match, V6_SIZEOF_RESTRICT_U); plisthead = &restrictlist6; } else { res = alloc_res4(); memcpy(res, &match, V4_SIZEOF_RESTRICT_U); plisthead = &restrictlist4; } LINK_SORT_SLIST( *plisthead, res, (v6) ? res_sorts_before6(res, L_S_S_CUR()) : res_sorts_before4(res, L_S_S_CUR()), link, restrict_u); restrictcount++; if (RES_LIMITED & flags) inc_res_limited(); } else { if ((RES_LIMITED & flags) && !(RES_LIMITED & res->flags)) inc_res_limited(); res->flags |= flags; } break; case RESTRICT_UNFLAG: /* * Remove some bits from the flags. If we didn't * find this one, just return. */ if (res != NULL) { if ((RES_LIMITED & res->flags) && (RES_LIMITED & flags)) dec_res_limited(); res->flags &= ~flags; } break; case RESTRICT_REMOVE: case RESTRICT_REMOVEIF: /* * Remove an entry from the table entirely if we * found one. Don't remove the default entry and * don't remove an interface entry. */ if (res != NULL && (RESTRICT_REMOVEIF == op || !(RESM_INTERFACE & res->mflags)) && res != &restrict_def4 && res != &restrict_def6) free_res(res, v6); break; default: /* unknown op */ INSIST(0); break; } }
int cmd_select(int argc,const char **argv){ // check necessary param check_cmd_args(argc,argv); st_select_sql *stsql=(st_select_sql*)malloc(sizeof(st_select_sql)); stsql->select="*"; stsql->limit=" LIMIT 20"; char *from=""; char where[256]={""}; char order[128]={""}; char limit[16]={""}; char group[64]={""}; int has_limit=has_cmd_args(argv,"limit"); while(*argv){ if(!strcmp(*argv,"--table") || !strcmp(*argv,"-t")){ argv++; from=(char*)*argv; argv++; }else if(!strcmp(*argv,"--select")){ argv++; stsql->select=*argv; argv++; }else if(!strcmp(*argv,"--limit")){ argv++; stsql->limit=cat_sql_limit(*argv,limit); argv++; }else if(!strcmp(*argv,"--order")){ argv++; const char *field=*argv; argv++; if(*argv==NULL){ cat_sql_sort(field,"ASC",order); }else{ if(start_with(*argv,"--")){ cat_sql_sort(field,*argv,order); }else{ cat_sql_sort(field,"ASC",order); } } }else if(!strcmp(*argv,"--group")){ argv++; stsql->group=cat_sql_group(*argv,"",group); argv++; if(has_limit==0){ stsql->limit=""; } }else if(!start_with(*argv,"--")){ const char *name=*argv+2; if(!strcmp(name,"id")) name=get_primary_key(from); argv++; const char *value=*argv; cat_sql_where(name,value,where); argv++; }else{ argv++; } } stsql->from=from; stsql->where=where; stsql->order=order; stsql->group=group; char sql[512]; parse_select_sql(stsql,sql); MYSQL_RES *res=select(sql); print_sql_result(res,1); free_res(res); return 0; }
int main(int argc, char *argv[]) { // Load the dispatchlist // Add each process structure instance to the job dispatch list queue node_t *tmp_head = NULL; printf("Dispatch list: \n"); load_dispatch("dispatchlist", &tmp_head); print_list(tmp_head); // Iterate through each item in the job dispatch list, add each process // to the appropriate queues node_t *test = NULL; while(tmp_head != NULL) { proc current = pop(&tmp_head); // get a segfault, so this is currently commented out push(&head_dispatch_queues[current.priority], current); } // go through the queues from highest to lowest priority for(int i = 0; i < 4; i++) { // while this queue isn't empty // it will keep pushing resources to the end of the queue until this on is completely empty while(head_dispatch_queues[i] != NULL) { proc current = pop(head_dispatch_queues[i]); if(res_available(current, resources)) { // Allocate the resources for each process before it's executed int printer_start = alloc_res(&resources.printers, current.required_printers); int scanner_start = alloc_res(&resources.scanners, current.required_scanners); int modem_start = alloc_res(&resources.modems, current.required_modems); int cd_start = alloc_res(&resources.cd_drives, current.required_cds); int memory_start = alloc_res(&resources.memory, current.required_memory); // Execute the process binary using fork and exec // Perform the appropriate signal handling // decrease the current.processor_time by the amount of time this process ran run_for_time(¤t); // Deallocate the resources free_res(&resources.printers, printer_start, current.required_printers); free_res(&resources.scanners, scanner_start, current.required_scanners); free_res(&resources.modems, modem_start, current.required_modems); free_res(&resources.cd_drives, cd_start, current.required_cds); free_res(&resources.memory, memory_start, current.required_memory); } // if the process needs more time to run, add it back to the queue if(current.processor_time > 0) { push(head_dispatch_queues[i], current); } } } // make sure the queues are clear to avoid memory leaks for(int i = 0; i < 4; i++) while(head_dispatch_queues[i] != NULL) pop(head_dispatch_queues[i]); return EXIT_SUCCESS; }
/* * PSEUDO CODE: * * EXTRACT INFO FROM XML NODE * RETRIEVE PROBE DEFINITION RECORD FROM DATABASE * RETRIEVE PRECEDING RAW RECORD FROM DATABASE * STORE RAW RESULTS * IF THIS IS THE FIRST RESULT EVER FOR THIS PROBE * CREATE PR_STATUS RECORD * ELSE * IF WE HAVEN'T PROCESSED THIS RECORD BEFORE * IF COLOR DIFFERS FROM PRECEDING RAW RECORD * CREATE PR_HIST * RETRIEVE FOLLOWING RAW RECORD * IF FOUND AND COLOR OF FOLLOWING IS THE SAME AS CURRENT * DELETE POSSIBLE HISTORY RECORDS FOR FOLLOWING RECORD * ENDIF * IF THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED * WRITE NEW RECENT TIME INTO PROBE DEFINITION RECORD * UPDATE PR_STATUS * UPDATE SERVER COLOR * ENDIF * ELSE * IF THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED * WRITE NEW RECENT TIME INTO PROBE DEFINITION RECORD * ENDIF * ENDIF * IF CURRENT RAW RECORD IS THE MOST RECENT * FOR EACH PERIOD * IF WE ENTERED A NEW SLOT * SUMMARIZE PREVIOUS SLOT * ENDIF * ENDFOR * ELSE * FOR EACH PERIOD * IF THE LAST RECORD FOR THIS SLOT HAS BEEN SEEN * RE-SUMMARIZE CURRENT SLOT * ENDIF * ENDFOR * ENDIF * ENDIF * ENDIF * * returns: * 1 in case of success * 0 in case of database failure where trying again later might help * -1 in case of malformed input, never try again * -2 in case of a fatal error, just skip this batch */ int process(trx *t) { int must_update_def=0; struct probe_result *prv=NULL; int err = 1; /* default ok */ if (!realm_exists(t->res->realm)) { return -1; } if (t->res->realm && t->res->realm[0]) { t->probe->db = open_realm(t->res->realm); } else { if (t->probe->find_realm) { t->probe->find_realm(t); } else { t->probe->db = open_realm(NULL); } } if (!t->probe->db) return -2; if (t->probe->resultcount % 400 == 0) { update_last_seen(t->probe); } if (debug > 3) fprintf(stderr, "accept_result\n"); if (t->probe->accept_result) { t->probe->accept_result(t); // do some final calculations on the result } if (debug > 3) fprintf(stderr, "get_def\n"); if (t->probe->get_def) { if (debug > 3) fprintf(stderr, "RETRIEVE PROBE DEFINITION RECORD FROM DATABASE\n"); t->def = t->probe->get_def(t, trust(t->res->name)); // RETRIEVE PROBE DEFINITION RECORD FROM DATABASE } else { t->def = get_def(t, trust(t->res->name)); } if (!t->def) { // Oops, def record not found. Skip this probe if (debug > 3) fprintf(stderr, "def NOT found\n"); err = -1; /* malformed input FIXME should make distinction between db errors and def not found */ goto exit_with_res; } if (t->probe->adjust_result) { t->probe->adjust_result(t); } if (debug > 3) fprintf(stderr, "STORE RAW RESULTS\n"); if (t->probe->store_results) { int ret = t->probe->store_results(t); // STORE RAW RESULTS if (!ret) { /* error return? */ if (debug > 3) fprintf(stderr, "error in store_results\n"); err = -2; /* database fatal error - try again later */ goto exit_with_res; } } else { t->seen_before = FALSE; } if (t->res->stattime > t->def->newest) { // IF CURRENT RAW RECORD IS THE MOST RECENT if (debug > 3) fprintf(stderr, "CURRENT RAW RECORD IS THE MOST RECENT\n"); prv = g_malloc0(sizeof(struct probe_result)); prv->color = t->def->color; // USE PREVIOUS COLOR FROM DEF RECORD prv->stattime = t->def->newest; } else { if (debug > 3) fprintf(stderr, "RETRIEVE PRECEDING RAW RECORD FROM DATABASE\n"); prv = get_previous_record(t); // RETRIEVE PRECEDING RAW RECORD FROM DATABASE } set_result_prev_color(t, prv); // indicate previous color in result set if (t->def->email[0]) { // and if email address given, add simple notification record xmlNodePtr notify; notify = xmlNewChild(t->cur, NULL, "notify", NULL); xmlSetProp(notify, "proto", "smtp"); xmlSetProp(notify, "target", t->def->email); } if (t->def->newest == 0) { // IF THIS IS THE FIRST RESULT EVER FOR THIS PROBE if (debug > 3) fprintf(stderr, "THIS IS THE FIRST RESULT EVER FOR THIS PROBE\n"); insert_pr_status(t); must_update_def = TRUE; goto finish; } if (t->seen_before) { goto finish; } // Extra debugging, be sure what colors are processed here if ( debug > 3 ) fprintf(stderr, "PREVIOUS COLOR %d - NEW COLOR %d\n", prv->color, t->res->color); // IF COLOR DIFFERS FROM PRECEDING RAW RECORD if (t->res->color != prv->color) { struct probe_result *nxt; if (t->probe->fuse) { if (t->res->color > prv->color || prv->color == STAT_PURPLE) { if (debug > 3) fprintf(stderr, "FUSE WITH HIGHER COLOR - CREATE PR_HIST\n"); create_pr_hist(t, prv); // CREATE PR_HIST } } else { if (debug > 3) fprintf(stderr, "COLOR DIFFERS FROM PRECEDING RAW RECORD - CREATE PR_HIST\n"); create_pr_hist(t, prv); // CREATE PR_HIST } if (t->res->stattime > t->def->newest) { // IF THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED dbi_result result; if (debug > 3) fprintf(stderr, "THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED - UPDATE PR_STATUS\n"); result = update_pr_status(t, prv); // UPDATE PR_STATUS if (dbi_result_get_numrows_affected(result) == 0) { // nothing was actually updated, need to insert new insert_pr_status(t); } dbi_result_free(result); if (debug > 3) fprintf(stderr, "UPDATE SERVER COLOR\n"); update_server_color(t, prv); // UPDATE SERVER COLOR must_update_def = TRUE; } else { if (debug > 3) fprintf(stderr, "RETRIEVE FOLLOWING RAW RECORD\n"); nxt = get_following_record(t); // RETRIEVE FOLLOWING RAW RECORD if (nxt && nxt->color) { // IF FOUND if (debug > 3) fprintf(stderr, "FOLLOWING RECORD IS FOUND\n"); if (nxt->color == t->res->color) { // IF COLOR OF FOLLOWING IS THE SAME AS CURRENT if (debug > 3) fprintf(stderr, "SAME COLOR: DELETE POSSIBLE HISTORY RECORDS\n"); delete_history(t, nxt); // DELETE POSSIBLE HISTORY RECORDS FOR FOLLOWING RECORD } g_free(nxt); } } } else { if (debug > 3) fprintf(stderr, "COLOR SAME AS PRECEDING RAW RECORD\n"); if (t->res->stattime > t->def->newest) { // IF THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED dbi_result result; if (debug > 3) fprintf(stderr, "THIS RAW RECORD IS THE MOST RECENT EVER RECEIVED - UPDATE PR_STATUS\n"); result = update_pr_status(t, prv); // UPDATE PR_STATUS (not for the color, but for the expiry time) if (dbi_result_get_numrows_affected(result) == 0) { // nothing was actually updated, need to insert new insert_pr_status(t); } dbi_result_free(result); must_update_def = TRUE; } } if (t->def->email[0] || t->def->sms[0]) { // if we have an address // RETRIEVE LAST HIST ENTRY FOR THIS PROBE get_previous_pr_hist(t); // notify if needed if (strcmp(t->res->notified, "yes")) { // not already notified if (notify(t)) { set_pr_hist_notified(t); } } } if (t->probe->summarize && t->res->color != STAT_PURPLE) { if (t->res->stattime > t->def->newest) { // IF CURRENT RAW RECORD IS THE MOST RECENT guint cur_slot, prev_slot; gulong slotlow, slothigh; gulong dummy_low, dummy_high; gint i; if (debug > 3) fprintf(stderr, "SUMMARIZING. CURRENT RAW RECORD IS THE MOST RECENT\n"); for (i=0; summ_info[i].period != -1; i++) { // FOR EACH PERIOD prev_slot = uw_slot(summ_info[i].period, prv->stattime, &slotlow, &slothigh); cur_slot = uw_slot(summ_info[i].period, t->res->stattime, &dummy_low, &dummy_high); if (cur_slot != prev_slot) { // IF WE ENTERED A NEW SLOT, SUMMARIZE PREVIOUS SLOT if (debug > 3) fprintf(stderr, "cur(%u for %u) != prv(%u for %u), summarizing %s from %lu to %lu", cur_slot, t->res->stattime, prev_slot, prv->stattime, summ_info[i].from, slotlow, slothigh); t->probe->summarize(t, summ_info[i].from, summ_info[i].to, cur_slot, slotlow, slothigh, 0); } } } else { guint cur_slot; gulong slotlow, slothigh; gulong not_later_then = UINT_MAX; gint i; if (debug > 3) { fprintf(stderr, "SUMMARIZING. CURRENT RAW RECORD IS AN OLD ONE\n"); LOG(LOG_DEBUG, "stattime = %u, newest = %u for %s %u", t->res->stattime, t->def->newest, t->res->name, t->def->probeid); } for (i=0; summ_info[i].period != -1; i++) { // FOR EACH PERIOD cur_slot = uw_slot(summ_info[i].period, t->res->stattime, &slotlow, &slothigh); if (slothigh > not_later_then) continue; // we already know there are none later then this // IF THIS SLOT IS COMPLETE if (slot_is_complete(t, i, slotlow, slothigh)) { // RE-SUMMARIZE CURRENT SLOT if (debug > 3) fprintf(stderr, "SLOT IS COMPLETE - RE-SUMMARIZE CURRENT SLOT\n"); t->probe->summarize(t, summ_info[i].from, summ_info[i].to, cur_slot, slotlow, slothigh, 0); } else { not_later_then = slothigh; } } } } finish: if (must_update_def) { t->def->newest = t->res->stattime; t->def->color = t->res->color; } g_free(prv); exit_with_res: if (t->probe->end_result) { t->probe->end_result(t); } // free the result block if (t->res) { if (t->probe->free_res) { t->probe->free_res(t->res); // the probe specific part... } free_res(t->res); // .. and the generic part } // note we don't free the *t->def here, because that structure is owned by the hashtable // except if the module does not use caching, we try to free it ourselves if (!t->probe->needs_cache) { if (t->probe->free_def) { t->probe->free_def(t->def); } else { free(t->def); } } return err; }
void BaseSequentialSolver::solve_impl(vec& res, const system_type& sys, const vec& rhs, bool correct) const { assert( response ); // reset bench if needed if( this->bench ) { bench->clear(); bench->restart(); } // free velocity vec free_res( sys.m ); sub.solve(*response, free_res, rhs.head( sys.m )); // we're done if( blocks.empty() ) { res = free_res; return; } // lagrange multipliers TODO reuse res.tail( sys.n ) ? vec lambda = res.tail(sys.n); // net constraint velocity correction vec net = mapping_response * lambda; // lambda change work vector vec delta = vec::Zero(sys.n); // lcp rhs vec constant = rhs.tail(sys.n) - JP * free_res.head(sys.m); // lcp error vec error = vec::Zero(sys.n); const real epsilon = relative.getValue() ? constant.norm() * precision.getValue() : precision.getValue(); if( this->bench ) this->bench->lcp(sys, constant, *response, lambda); // outer loop unsigned k = 0, max = iterations.getValue(); // vec primal; for(k = 0; k < max; ++k) { real estimate2 = step( lambda, net, sys, constant, error, delta, correct ); if( this->bench ) this->bench->lcp(sys, constant, *response, lambda); // stop if we only gain one significant digit after precision if( std::sqrt(estimate2) / sys.n <= epsilon ) break; } res.head( sys.m ) = free_res + net; res.tail( sys.n ) = lambda; if( this->f_printLog.getValue() ) serr << "iterations: " << k << ", (abs) residual: " << (net - mapping_response * lambda).norm() << sendl; }