void free_mom_hierarchy( mom_hierarchy_t *mh) { resizable_array *paths; resizable_array *levels; node_comm_t *nc; int paths_iter = -1; int levels_iter = -1; int node_iter = -1; while ((paths = (resizable_array *)next_thing(mh->paths, &paths_iter)) != NULL) { levels_iter = -1; /* free each level */ while ((levels = (resizable_array *)next_thing(paths, &levels_iter)) != NULL) { node_iter = -1; /* free each node_comm_t */ while ((nc = (node_comm_t *)next_thing(levels, &node_iter)) != NULL) { free(nc); } free_resizable_array(levels); } free_resizable_array(paths); } free(mh); } /* END free_mom_hierarchy() */
struct pbsnode *find_fitting_node( struct prop *needed) { struct pbsnode *pnode = NULL; login_node *ln; login_node *ordered_ln; int iter = -1; int ordered_iter; int index; resizable_array *ordered = initialize_resizable_array(logins.ra->num + 1); /* create a sorted list of the logins */ while ((ln = (login_node *)next_thing(logins.ra, &iter)) != NULL) { /* if ordered is empty just insert without attempting to sort */ if (ordered->num == 0) insert_thing(ordered, ln); else { ordered_iter = -1; index = ordered->slots[ALWAYS_EMPTY_INDEX].next; while ((ordered_ln = (login_node *)next_thing(ordered, &ordered_iter)) != NULL) { if (ln->times_used <= ordered_ln->times_used) { insert_thing_before(ordered, ln, index); break; } index = ordered_iter; } /* insert if it hasn't been inserted yet */ if (ordered_ln == NULL) insert_thing(ordered, ln); } } iter = -1; while ((ln = (login_node *)next_thing(ordered, &iter)) != NULL) { if ((pnode = check_node(ln, needed)) != NULL) { ln->times_used++; free_resizable_array(ordered); return(pnode); } } free_resizable_array(ordered); return(NULL); } /* END find_fitting_node() */
pbs_queue *next_queue( all_queues *aq, int *iter) { pbs_queue *pque; pthread_mutex_lock(aq->allques_mutex); pque = (pbs_queue *)next_thing(aq->ra,iter); if (pque != NULL) lock_queue(pque, "next_queue", (char *)NULL, LOGLEVEL); pthread_mutex_unlock(aq->allques_mutex); if (pque != NULL) { if (pque->q_being_recycled != FALSE) { unlock_queue(pque, __func__, (char *)"recycled queue", LOGLEVEL); pque = next_queue(aq, iter); } } return(pque); } /* END next_queue() */
/* * return the next task in this array using iter */ work_task *next_task( all_tasks *at, int *iter) { work_task *wt; pthread_mutex_lock(at->alltasks_mutex); wt = next_thing(at->ra,iter); if (wt != NULL) pthread_mutex_lock(wt->wt_mutex); pthread_mutex_unlock(at->alltasks_mutex); if (wt != NULL) { if (wt->wt_being_recycled == TRUE) { pthread_mutex_unlock(wt->wt_mutex); wt = next_task(at, iter); } } return(wt); } /* END next_task() */
job *next_job( struct all_jobs *aj, int *iter) { job *pjob; pthread_mutex_lock(aj->alljobs_mutex); pjob = (job *)next_thing(aj->ra,iter); pthread_mutex_unlock(aj->alljobs_mutex); if (pjob != NULL) { lock_ji_mutex(pjob, __func__, NULL, LOGLEVEL); if (pjob->ji_being_recycled == TRUE) { unlock_ji_mutex(pjob, __func__, "1", LOGLEVEL); pjob = next_job(aj,iter); } } return(pjob); } /* END next_job() */
pbs_queue *next_queue( all_queues *aq, int *iter) { pbs_queue *pque; lock_allques_mutex(aq, __func__, NULL, LOGLEVEL); pque = (pbs_queue *)next_thing(aq->ra,iter); if (pque != NULL) lock_queue(pque, "next_queue", NULL, LOGLEVEL); unlock_allques_mutex(aq, __func__, NULL, LOGLEVEL); if (pque != NULL) { if (pque->q_being_recycled != FALSE) { unlock_queue(pque, __func__, "recycled queue", LOGLEVEL); pque = next_queue(aq, iter); } } return(pque); } /* END next_queue() */
void update_menus(WMenuData *mdata) { WMenu *menu; menu=(WMenu*)subthing((WThing*)SCREEN, WTHING_MENU); while(menu!=NULL){ if(menu->data==mdata) update_menu(menu); menu=(WMenu*)next_thing((WThing*)menu, WTHING_MENU); } }
WThing *nth_thing(WThing *parent, int n, const WObjDescr *descr) { WThing *p; if(n<0) return NULL; p=first_thing(parent, descr); while(n-- && p!=NULL) p=next_thing(p, descr); return p; }
dynamic_string *get_reservation_command( resizable_array *host_req_list, char *username, char *jobid, char *apbasil_path, char *apbasil_protocol) { dynamic_string *command = get_dynamic_string(-1, NULL); dynamic_string *node_list = get_dynamic_string(-1, NULL); char buf[MAXLINE * 2]; unsigned int width = 0; unsigned int nppn = 0; int iter = -1; host_req *hr; /* place the top header */ snprintf(buf, sizeof(buf), APBASIL_RESERVE_REQ, (apbasil_protocol != NULL) ? apbasil_protocol : DEFAULT_APBASIL_PROTOCOL); append_dynamic_string(command, buf); /* place the reserve header */ snprintf(buf, sizeof(buf), APBASIL_RESERVE_ARRAY, username, jobid); append_dynamic_string(command, buf); while ((hr = (host_req *)next_thing(host_req_list, &iter)) != NULL) { width += hr->ppn; nppn = MAX(nppn,hr->ppn); if (node_list->used != 0) append_dynamic_string(node_list, ","); append_dynamic_string(node_list, hr->hostname); free_host_req(hr); } save_current_reserve_param(command, node_list, width, nppn); free_dynamic_string(node_list); /* pipe the output to apbasil */ snprintf(buf, sizeof(buf), "</ReserveParamArray></BasilRequest>\" | %s", (apbasil_path != NULL) ? apbasil_path : DEFAULT_APBASIL_PATH); append_dynamic_string(command, buf); return(command); } /* END get_reservation_command() */
job_array *next_array( int *iter) { job_array *pa = NULL; pthread_mutex_lock(allarrays.allarrays_mutex); pa = (job_array *)next_thing(allarrays.ra,iter); pthread_mutex_unlock(allarrays.allarrays_mutex); return(pa); } /* END next_array() */
work_task *next_task_from_recycler( all_tasks *at, int *iter) { work_task *wt = NULL; pthread_mutex_lock(at->alltasks_mutex); wt = (work_task *)next_thing(at->ra,iter); if (wt != NULL) pthread_mutex_lock(wt->wt_mutex); pthread_mutex_unlock(at->alltasks_mutex); return(wt); } /* END next_task_from_recycler() */
void *next_from_hash_map( hash_map *hm, int *iter) { void *obj; pthread_mutex_lock(hm->hm_mutex); obj = next_thing(hm->hm_ra, iter); pthread_mutex_unlock(hm->hm_mutex); return(obj); } /* END next_from_hash_map() */
job *next_job_from_recycler( struct all_jobs *aj, int *iter) { job *pjob; lock_alljobs_mutex(aj, __func__, NULL, LOGLEVEL); pjob = next_thing(aj->ra, iter); unlock_alljobs_mutex(aj, __func__, NULL, LOGLEVEL); if (pjob != NULL) lock_ji_mutex(pjob, __func__, NULL, LOGLEVEL); return(pjob); } /* END next_job_from_recycler() */
job *next_job_from_recycler( struct all_jobs *aj, int *iter) { job *pjob; pthread_mutex_lock(aj->alljobs_mutex); pjob = next_thing(aj->ra, iter); pthread_mutex_unlock(aj->alljobs_mutex); if (pjob != NULL) lock_ji_mutex(pjob, __func__, (char *)NULL, LOGLEVEL); return(pjob); } /* END next_job_from_recycler() */
job_array *next_array_check( int *iter, job_array *owned) { job_array *pa = NULL; pthread_mutex_lock(allarrays.allarrays_mutex); pa = (job_array *)next_thing(allarrays.ra,iter); pthread_mutex_unlock(allarrays.allarrays_mutex); if ((pa != NULL) && (pa != owned)) lock_ai_mutex(pa, __func__, NULL, LOGLEVEL); return(pa); } /* END next_array_check() */
int create_reserve_params_from_host_req_list( resizable_array *host_req_list, /* I */ char *apbasil_protocol, /* I */ int use_nppn, /* I */ int nppcu, /* I */ int mppdepth, /* I */ dynamic_string *command) /* O */ { dynamic_string *node_list = get_dynamic_string(-1, NULL); host_req *hr; unsigned int nppn = 0; unsigned int width = 0; int iter = -1; while ((hr = (host_req *)next_thing(host_req_list, &iter)) != NULL) { width += hr->ppn; nppn = MAX((unsigned int)nppn, hr->ppn); if (node_list->used != 0) append_dynamic_string(node_list, ","); append_dynamic_string(node_list, hr->hostname); free_host_req(hr); } if (use_nppn == FALSE) nppn = -1; adjust_for_depth(width, nppn, mppdepth); save_current_reserve_param(command, apbasil_protocol, node_list, width, nppn, nppcu, mppdepth); if (node_list != NULL) free(node_list); return(PBSE_NONE); } /* END create_reserve_params_from_host_req_list() */
void update_next_node_index( unsigned int to_beat) { int iter = -1; int prev_index = logins.ra->slots[ALWAYS_EMPTY_INDEX].next; login_node *ln; while ((ln = (login_node *)next_thing(logins.ra, &iter)) != NULL) { if (ln->times_used < to_beat) { /* don't break - there may be one lower */ to_beat = ln->times_used; logins.next_node = prev_index; } prev_index = iter; } } /* END update_next_node_index() */
job *next_job( struct all_jobs *aj, int *iter) { job *pjob; if (aj == NULL) { log_err(PBSE_BAD_PARAMETER, __func__, "null input pointer to all_jobs struct"); return(NULL); } if (iter == NULL) { log_err(PBSE_BAD_PARAMETER, __func__, "null input iterator"); return(NULL); } pthread_mutex_lock(aj->alljobs_mutex); pjob = (job *)next_thing(aj->ra,iter); pthread_mutex_unlock(aj->alljobs_mutex); if (pjob != NULL) { lock_ji_mutex(pjob, __func__, NULL, LOGLEVEL); if (pjob->ji_being_recycled == TRUE) { unlock_ji_mutex(pjob, __func__, "1", LOGLEVEL); pjob = next_job(aj,iter); } } return(pjob); } /* END next_job() */
static char *next_quoted_string(struct TestFile *tf, size_t *len) { size_t full_len; char *s; s = next_thing(tf, &full_len, quoted_string_end_finder); assert(s != NULL); if (s == END_OF_LINE || *s != '"') { fail(tf, s, "expected a quote (\") to begin a string"); return NULL; } if (tf->next_pos == s || *(tf->next_pos - 1) != '"') { fail(tf, tf->next_pos, "expected a quote(\") to end the string"); return NULL; } tf->read_pos++; // skip past leading " if (len) *len = tf->next_pos - tf->read_pos - 1; return tf->read_pos; }
static char *next_token(struct TestFile *tf, size_t *len) { return next_thing(tf, len, token_end_finder); }
END_TEST START_TEST(parse_exec_hosts_test) { resizable_array *hrl = parse_exec_hosts(eh1); int iter = -1; int host_count = 0; host_req *hr; while ((hr = (host_req *)next_thing(hrl, &iter)) != NULL) { snprintf(buf, sizeof(buf), "ppn should be %d but is %d", 2, hr->ppn); fail_unless(hr->ppn == 2, buf); host_count++; free(hr->hostname); } snprintf(buf, sizeof(buf), "Should be 2 hosts but there were %d", host_count); fail_unless(host_count == 2, buf); free_resizable_array(hrl); hrl = parse_exec_hosts(eh2); iter = -1; host_count = 0; while ((hr = (host_req *)next_thing(hrl, &iter)) != NULL) { if (host_count == 0) { snprintf(buf, sizeof(buf), "Hostname should be napali but is %s", hr->hostname); fail_unless(!strcmp(hr->hostname, "napali"), buf); snprintf(buf, sizeof(buf), "ppn should be 2 but is %d", hr->ppn); fail_unless(hr->ppn == 2, buf); } else { snprintf(buf, sizeof(buf), "Hostname should be l11 but is %s", hr->hostname); fail_unless(!strcmp(hr->hostname, "l11"), buf); snprintf(buf, sizeof(buf), "ppn should be 3 but is %d", hr->ppn); fail_unless(hr->ppn == 3, buf); } free(hr->hostname); host_count++; } snprintf(buf, sizeof(buf), "Should count 2 hosts but counted %d", host_count); fail_unless(host_count == 2, buf); free_resizable_array(hrl); hrl = parse_exec_hosts(eh3); iter = -1; host_count = 0; while ((hr = (host_req *)next_thing(hrl, &iter)) != NULL) { if (host_count < 2) { snprintf(buf, sizeof(buf), "ppn should be 2 but is %d", hr->ppn); fail_unless(hr->ppn == 2, buf); } else if (host_count >= 2) { snprintf(buf, sizeof(buf), "ppn should be 3 but is %d", hr->ppn); fail_unless(hr->ppn == 3, buf); } free(hr->hostname); host_count++; } snprintf(buf, sizeof(buf), "Should count 4 hosts but counted %d", host_count); fail_unless(host_count == 4, buf); free_resizable_array(hrl); }
static bool winlist_menudata_init(WMenuData *data, WThing *context) { WMenuEnt *ents; WFrame *frame; int ws; WClientWin *cwin; int nents, length, entryname_length, i=0; const char *winname; char *entryname; nents=SCREEN->n_clientwin; /* Some extra space will be allocated depending on number of dockapps */ ents=ALLOC_N(WMenuEnt, nents); if(ents==NULL){ warn_err(); return FALSE; } for(frame=(WFrame*)subthing((WThing*)SCREEN, WTHING_FRAME); frame!=NULL; frame=(WFrame*)next_thing((WThing*)frame, WTHING_FRAME)){ ws=workspace_of((WWinObj*)frame); /* Don't list active frame */ if(data==&attachlist_menudata){ if(context!=NULL && winobj_of(context)==(WWinObj*)frame) continue; } for(cwin=first_clientwin((WThing*)frame); cwin!=NULL; cwin=next_clientwin(cwin)){ if(!CWIN_HAS_FRAME(cwin)) continue; winname=clientwin_full_label(cwin); length=32+strlen(winname); entryname=ALLOC_N(char, length); if(entryname==NULL){ warn_err(); do_free_winlist(ents, i); return FALSE; } if(ws>=0){ entryname_length=snprintf(entryname+0, length, "%d%c", ws+1, (cwin==frame->current_cwin ? '+' : '-')); }else{ entryname_length=snprintf(entryname+0, length, "%c%c", (ws==WORKSPACE_STICKY ? '*' : '?'), (cwin==frame->current_cwin ? '+' : '-')); } snprintf(entryname + entryname_length, length - entryname_length, " %s", winname); ents[i].name=entryname; ents[i].flags=0; ents[i].u.winlist.clientwin=cwin; ents[i].u.winlist.sort=i; i++; } } nents=i; qsort(ents, nents, sizeof(WMenuEnt), menuent_cmp); data->entries=ents; data->nentries=nents; return TRUE; }
job *next_job(struct all_jobs *aj, int *iter) { return((job *)next_thing(aj->ra,iter)); }
static char *next_name(struct TestFile *tf, size_t *len) { return next_thing(tf, len, name_end_finder); }
WClientWin *next_clientwin(WClientWin *cwin) { return (WClientWin*)next_thing((WThing*)cwin, WTHING_CLIENTWIN); }