static void _process_assoc_type( ListIterator itr, slurmdb_report_cluster_rec_t *slurmdb_report_cluster, char *cluster_name, cluster_report_t type) { slurmdb_assoc_rec_t *assoc = NULL; /* now add the associations of interest here by user */ while((assoc = list_next(itr))) { if (!assoc->accounting_list || !list_count(assoc->accounting_list) || ((type == CLUSTER_REPORT_UA) && !assoc->user)) { list_delete_item(itr); continue; } if (xstrcmp(cluster_name, assoc->cluster)) continue; if (type == CLUSTER_REPORT_UA) _process_ua(slurmdb_report_cluster->user_list, assoc); else if (type == CLUSTER_REPORT_AU) _process_au(slurmdb_report_cluster->assoc_list, assoc); list_delete_item(itr); } }
static void test_DeleteItem(void) { const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; int nr_elements = sizeof(data)/sizeof(data[0]); const test_struct data_noFirst[] = {{-3, -4}, {21, 56}, {0, 0}, {12, 12345}}; const test_struct data_noLast[] = {{-3, -4}, {21, 56}, {0, 0}}; const test_struct data_noMiddle[] = {{-3, -4}, {0, 0}}; TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, 0)); for(int i = 0; i < nr_elements; i++) { TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i]))); } TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 0)); nr_elements--; TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); check_n_list_elements_ok(mylist, nr_elements, data_noFirst); TEST_ASSERT_EQUAL(0, list_delete_item(mylist, nr_elements-1)); nr_elements--; TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); check_n_list_elements_ok(mylist, nr_elements, data_noLast); TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 1)); nr_elements--; TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist)); check_n_list_elements_ok(mylist, nr_elements, data_noMiddle); }
static void _process_wckey_type( ListIterator itr, slurmdb_report_cluster_rec_t *slurmdb_report_cluster, char *cluster_name, cluster_report_t type) { slurmdb_wckey_rec_t *wckey = NULL; /* now add the wckeyiations of interest here by user */ while((wckey = list_next(itr))) { if (!wckey->accounting_list || !list_count(wckey->accounting_list) || ((type == CLUSTER_REPORT_UW) && !wckey->user)) { list_delete_item(itr); continue; } if (xstrcmp(cluster_name, wckey->cluster)) continue; if (type == CLUSTER_REPORT_UW) _process_uw(slurmdb_report_cluster->user_list, wckey); else if (type == CLUSTER_REPORT_WU) _process_wu(slurmdb_report_cluster->assoc_list, wckey); list_delete_item(itr); } }
/* * InventoryRemoveItem: Remove the object with the given id from the * inventory display. */ void InventoryRemoveItem(ID id) { InvItem *item; WindowBeginUpdate(hwndInv); item = (InvItem *) list_find_item(items, (void *) id, InventoryCompareIdItem); if (item == NULL) { debug(("Tried to remove nonexistent object %ld from inventory list", id)); return; } items = list_delete_item(items, (void *) id, InventoryCompareIdItem); // Object itself freed elsewhere SafeFree(item); num_items--; InventoryScrollRange(); /* See if we should remove scroll bar */ if (num_items == rows * cols) { InventoryDisplayScrollbar(); top_row = 0; } WindowEndUpdate(hwndInv); InventoryRedraw(); }
void main(int argc, char* argv[]) { list * l; list_iter it; intptr_t i; char* sv[] = { "fff", "zzz", "rrr", "bbb", "ggg", "hhh", "lll", "ttt" }; //list test l = list_new(); for (i=0; i<10; ++i) { (i%2 ? list_append(l, (void*)i): list_prepend(l, (void*)i)); } list_insert_at(l, (void*)20,9); list_append(l, (void*)22); list_delete_item(l, (void*)22); list_delete_at(l, 10); list_dump(l, "%d\n"); list_free(l); //string list test l = list_new_full(free); for(i=0; i<8; ++i) list_append(l, strdup(sv[i])); list_prepend(l, strdup("nine")); list_delete_item_comp(l, strdup("seven"), (list_comparator)strcmp); list_delete_item_comp(l, "eee", (list_comparator)strcmp); list_dump(l, "%s\n"); list_free(l); l = list_new(); for(i=0; i<8; ++i) list_insert_sorted_comp(l, sv[i], (list_comparator)strcmp); list_dump(l, "%s\n"); list_free(l); }
/* * ProjectilesMove; called for every frame. * dt is number of milliseconds since last time animation timer went off. * Return True iff some projectile moved. */ Bool ProjectilesMove(int dt) { list_type l, next; if (current_room.projectiles == NULL) return False; // Have to be careful here, since deleting items from list as we go down it l = current_room.projectiles; while (l != NULL) { Projectile *p = (Projectile *) (l->data); next = l->next; if (MoveSingle(&p->motion, dt)) { current_room.projectiles = list_delete_item(current_room.projectiles, p, CompareProjectiles); SafeFree(p); } else if (p->flags & PROJ_FLAG_FOLLOWGROUND) { p->motion.z = GetPointFloor(p->motion.x, p->motion.y); } l = next; } return True; }
/* Checkpoint processing pthread * Never returns, but is cancelled on plugin termiantion */ static void *_ckpt_agent_thr(void *arg) { ListIterator iter; struct ckpt_timeout_info *rec; time_t now; while (1) { _my_sleep(1); if (ckpt_agent_stop) break; if (!ckpt_timeout_list) continue; now = time(NULL); iter = list_iterator_create(ckpt_timeout_list); slurm_mutex_lock(&ckpt_agent_mutex); /* look for and process any timeouts */ while ((rec = list_next(iter))) { if (rec->end_time > now) continue; info("checkpoint timeout for %u.%u", rec->job_id, rec->step_id); _ckpt_signal_step(rec); list_delete_item(iter); } slurm_mutex_unlock(&ckpt_agent_mutex); list_iterator_destroy(iter); } return NULL; }
/* * merge_delta_qos_list - apply delta_qos_list to qos_list * * IN/OUT qos_list: list of QOS'es * IN delta_qos_list: list of delta QOS'es */ extern void merge_delta_qos_list(List qos_list, List delta_qos_list) { ListIterator curr_itr = list_iterator_create(qos_list); ListIterator new_itr = list_iterator_create(delta_qos_list); char *new_qos = NULL, *curr_qos = NULL; while((new_qos = list_next(new_itr))) { if (new_qos[0] == '-') { while((curr_qos = list_next(curr_itr))) { if (!xstrcmp(curr_qos, new_qos+1)) { list_delete_item(curr_itr); break; } } list_iterator_reset(curr_itr); } else if (new_qos[0] == '+') { while((curr_qos = list_next(curr_itr))) { if (!xstrcmp(curr_qos, new_qos+1)) { break; } } if (!curr_qos) { list_append(qos_list, xstrdup(new_qos+1)); } list_iterator_reset(curr_itr); } } list_iterator_destroy(new_itr); list_iterator_destroy(curr_itr); }
/* remove a BG block from the given list */ static int _excise_block(List block_list, char *bg_block_id, char *nodes) { int rc = SLURM_SUCCESS; ListIterator iter; bg_record_t *bg_record = NULL; if (block_list) { iter = list_iterator_create(block_list); xassert(iter); while ((bg_record = list_next(iter))) { rc = SLURM_ERROR; if (strcmp(bg_record->bg_block_id, bg_block_id)) continue; if (strcmp(bg_record->mp_str, nodes)) { /* changed bgblock */ error("bg_block_id:%s old_nodes:%s " "new_nodes:%s", bg_block_id, nodes, bg_record->mp_str); break; } /* exact match of name and node list */ debug("synced Block %s", bg_block_id); list_delete_item(iter); rc = SLURM_SUCCESS; break; } list_iterator_destroy(iter); } else { error("_excise_block: No block_list"); rc = SLURM_ERROR; } return rc; }
/* Prepare cluster_list to be federation centric that will be passed to * verify_clsuters_exists in federation_functions.c. */ static int _verify_fed_clusters(List cluster_list, const char *fed_name, bool *existing_fed) { int rc = SLURM_SUCCESS; char *tmp_name = NULL; List tmp_list = list_create(slurmdb_destroy_cluster_rec); ListIterator itr = list_iterator_create(cluster_list); while ((tmp_name = list_next(itr))) { slurmdb_cluster_rec_t *rec = xmalloc(sizeof(slurmdb_cluster_rec_t)); slurmdb_init_cluster_rec(rec, 0); rec->name = xstrdup(tmp_name); list_append(tmp_list, rec); } if ((rc = verify_fed_clusters(tmp_list, fed_name, existing_fed))) goto end_it; /* have to reconcile lists now, clusters may have been removed from * tmp_list */ list_iterator_reset(itr); while ((tmp_name = list_next(itr))) { if (!list_find_first(tmp_list, _find_cluster_rec_in_list, tmp_name)) list_delete_item(itr); } end_it: FREE_NULL_LIST(tmp_list); list_iterator_destroy(itr); return rc; }
void pmixp_dmdx_timeout_cleanup(void) { ListIterator it = list_iterator_create(_dmdx_requests); dmdx_req_info_t *req = NULL; time_t ts = time(NULL); /* run through all requests and discard stale one's */ while (NULL != (req = list_next(it))) { if ((ts - req->ts) > pmixp_info_timeout()) { #ifndef NDEBUG /* respond with the timeout to libpmix */ char *host = pmixp_nspace_resolve(req->nspace, req->rank); xassert(NULL != host); PMIXP_ERROR("timeout: ns=%s, rank=%d," " host=%s, ts=%lu", req->nspace, req->rank, (NULL != host) ? host : "unknown", ts); if (NULL != host) { free(host); } #endif req->cbfunc(PMIX_ERR_TIMEOUT, NULL, 0, req->cbdata, NULL, NULL); /* release tracker & list iterator */ list_delete_item(it); } } list_iterator_destroy(it); }
void UnuseObject(ID obj_id) { if (list_find_item(use_list, (void *) obj_id, CompareId) == NULL) return; /* Not an error, since we always try to unuse what we drop */ use_list = list_delete_item(use_list, (void *) obj_id, CompareId); ModuleEvent(EVENT_INVENTORY, INVENTORY_UNUSE, obj_id); }
int boxpath_removefile(boxpath * bpath) { if(!boxpath_getfile(bpath)) return FALSE; return list_delete_item( bpath->is_dir ? bpath->dir->folders : bpath->dir->files, bpath->file); }
/* * KeyRemoveTable: Remove the given key table. */ void KeyRemoveTable(int game_state, KeyTable table) { KeyTableListEntry entry; entry.state = game_state; entry.table = table; key_tables = list_delete_item(key_tables, table, CompareKeyTableListEntries); }
void client_remove_user( int id ) { ClientUser *entry = 0; if ( ( entry = client_find_user( id ) ) ) { if ( entry == client_user ) client_user = 0; list_delete_item( client_users, entry ); } }
/* * Convert all GPU records to a new entries in a list where each File is a * unique device (i.e. convert a record with "File=nvidia[0-3]" into 4 separate * records). */ static List _build_gpu_list(List gres_list) { ListIterator itr; gres_slurmd_conf_t *gres_record, *gpu_record; List gpu_list; hostlist_t hl; char *f_name; bool log_fname = true; if (gres_list == NULL) return NULL; gpu_list = list_create(_delete_gres_list); itr = list_iterator_create(gres_list); while ((gres_record = list_next(itr))) { if (xstrcmp(gres_record->name, "gpu")) continue; if (!gres_record->file) { if (log_fname) { error("%s: GPU configuration lacks \"File\" specification", plugin_name); log_fname = false; } continue; } hl = hostlist_create(gres_record->file); while ((f_name = hostlist_shift(hl))) { gpu_record = xmalloc(sizeof(gres_slurmd_conf_t)); gpu_record->config_flags = gres_record->config_flags; if (gres_record->type_name) { gpu_record->config_flags |= GRES_CONF_HAS_TYPE; } gpu_record->count = 1; gpu_record->cpu_cnt = gres_record->cpu_cnt; gpu_record->cpus = xstrdup(gres_record->cpus); if (gres_record->cpus_bitmap) { gpu_record->cpus_bitmap = bit_copy(gres_record->cpus_bitmap); } gpu_record->file = xstrdup(f_name); gpu_record->links = xstrdup(gres_record->links); gpu_record->name = xstrdup(gres_record->name); gpu_record->plugin_id = gres_record->plugin_id; gpu_record->type_name = xstrdup(gres_record->type_name); list_append(gpu_list, gpu_record); free(f_name); } hostlist_destroy(hl); (void) list_delete_item(itr); } list_iterator_destroy(itr); return gpu_list; }
void test_pop_delete(void) { List list = list_random(MAX_LIST_SIZE, ELEMENT_MAX_VALUE); list_sort_by_item(&list); list_unique(&list); printf("Original List ::: "); list_print(&list); List duplicate = list_duplicate(&list); list_pop(&duplicate); printf("%sList 1 without last item ::: ", cyan); list_print(&duplicate); list_destroy(&duplicate); duplicate = list_duplicate(&list); uint random_value = rand() % duplicate.size; list_pop_multi(&duplicate, random_value); printf("%sList without last %d items ::: ", brown, random_value); list_print(&duplicate); list_destroy(&duplicate); duplicate = list_duplicate(&list); uint random_end = rand() % duplicate.size; list_pop_until(&duplicate, random_end); printf("%sList until %d ::: ", magenta, random_end); list_print(&duplicate); list_destroy(&duplicate); duplicate = list_duplicate(&list); uint random_position = rand() % (duplicate.size); list_delete_position(&duplicate, random_position); printf("%sList wihout %d-d item ::: ", green, random_position); list_print(&duplicate); printf("%s", none); list_destroy(&duplicate); duplicate = list_duplicate(&list); Item random_item; random_position = rand() % (duplicate.size); random_item = duplicate.data[random_position]; list_delete_item(&duplicate, random_item); printf("%sList without %d ::: ", red, random_item.item); list_print(&duplicate); printf("%s", none); list_destroy(&duplicate); duplicate = list_duplicate(&list); uint low = rand() % duplicate.size; uint high = (rand() % (duplicate.size - low)) + low; list_delete_range(&duplicate, low, high); printf("%sList without range %d - %d ::: ", blue, low, high); list_print(&duplicate); printf("%s", none); }
static void _dmdx_resp(Buf buf, char *sender_host, uint32_t seq_num) { dmdx_req_info_t *req; int rank, rc = SLURM_SUCCESS; int status; char *ns = NULL, *sender_ns = NULL; char *data = NULL; uint32_t size = 0; /* find the request tracker */ ListIterator it = list_iterator_create(_dmdx_requests); req = (dmdx_req_info_t *)list_find(it, _dmdx_req_cmp, &seq_num); if (NULL == req) { /* We haven't sent this request! */ PMIXP_ERROR("Received DMDX response with bad " "seq_num=%d from %s!", seq_num, sender_host); list_iterator_destroy(it); rc = SLURM_ERROR; goto exit; } /* get the service data */ rc = _read_info(buf, &ns, &rank, &sender_ns, &status); if (SLURM_SUCCESS != rc) { /* notify libpmix about an error */ req->cbfunc(PMIX_ERROR, NULL, 0, req->cbdata, NULL, NULL); goto exit; } /* get the modex blob */ if (SLURM_SUCCESS != (rc = unpackmem_ptr(&data, &size, buf))) { /* notify libpmix about an error */ req->cbfunc(PMIX_ERROR, NULL, 0, req->cbdata, NULL, NULL); goto exit; } /* call back to libpmix-server */ req->cbfunc(status, data, size, req->cbdata, pmixp_free_Buf, (void *)buf); /* release tracker & list iterator */ req = NULL; list_delete_item(it); list_iterator_destroy(it); exit: if (SLURM_SUCCESS != rc) { /* we are not expect libpmix to call the callback * to cleanup this buffer */ free_buf(buf); } /* no sense to return errors, engine can't do anything * anyway. We've notified libpmix, that's enough */ }
void do_undefine(char* name) { list*r=NULL; if((r=list_find(name,conf->defsyms))){ free(((symba*)r->data)->value); free((symba*)r->data); r->data=NULL; conf->defsyms=list_delete_item(r); } }
/* ==================================================================== Transfer an entry from one list to another list by removing from 'source' and adding to 'dest' thus if source does not contain the item this is equvalent to list_add( dest, item ). ==================================================================== */ void list_transfer( List *source, List *dest, void *item ) { int old_auto_flag; /* add to destination */ list_add( dest, item ); /* as the pointer is added to dest without changes only the empty entry must be deleted in source */ old_auto_flag = source->auto_delete; source->auto_delete = LIST_NO_AUTO_DELETE; list_delete_item( source, item ); source->auto_delete = old_auto_flag; }
static int _check_status() { ListIterator itr = list_iterator_create(block_list); int i=0; block_info_msg_t *block_ptr = NULL; char *block_name = NULL; while (list_count(block_list)) { info("waiting for %d bgblocks to free...", list_count(block_list)); if (_get_new_info_block(&block_ptr) == SLURM_SUCCESS) { while ((block_name = list_next(itr))) { for (i=0; i<block_ptr->record_count; i++) { if (!xstrcmp(block_name, block_ptr-> block_array[i]. bg_block_id)) { if (block_ptr-> block_array[i]. state == BG_BLOCK_FREE) list_delete_item(itr); break; } } /* Here if we didn't find the record it is gone so we just will delete it. */ if (i >= block_ptr->record_count) list_delete_item(itr); } list_iterator_reset(itr); } sleep(1); } list_iterator_destroy(itr); return SLURM_SUCCESS; }
void entity_delete_node(entity_t* entity, void* node) { ListIterator i; void* result; i = list_iterator_create(entity->nodes); result = list_find(i, _entity_node_find, node); do { if (result == NULL) break; list_delete_item(i); xfree(result); } while(0); list_iterator_destroy(i); }
void RemoveSpell(ID id) { spell *old_spell = (spell *) list_find_item(spells, (void *) id, CompareIdObject); if (old_spell == NULL) { debug(("Tried to remove nonexistent spell #%ld\n", id)); return; } MenuRemoveSpell(old_spell); spells = list_delete_item(spells, (void *) id, CompareIdObject); SafeFree(old_spell); }
static int _verify_federations(List name_list, bool report_existing) { int rc = SLURM_SUCCESS; char *name = NULL; List temp_list = NULL; ListIterator itr = NULL; ListIterator itr_c = NULL; slurmdb_federation_cond_t fed_cond; slurmdb_init_federation_cond(&fed_cond, 0); fed_cond.federation_list = name_list; temp_list = acct_storage_g_get_federations(db_conn, my_uid, &fed_cond); if (!temp_list) { fprintf(stderr, " Problem getting federations from database. " "Contact your admin.\n"); return SLURM_ERROR; } itr_c = list_iterator_create(name_list); itr = list_iterator_create(temp_list); while((name = list_next(itr_c))) { slurmdb_federation_rec_t *fed_rec = NULL; list_iterator_reset(itr); while((fed_rec = list_next(itr))) { if (!strcasecmp(fed_rec->name, name)) break; } if (fed_rec && report_existing) { printf(" This federation %s already exists. " "Not adding.\n", name); list_delete_item(itr_c); } else if (!fed_rec && !report_existing) { printf(" The federation %s doesn't exist.\n", name); rc = SLURM_ERROR; } } list_iterator_destroy(itr); list_iterator_destroy(itr_c); FREE_NULL_LIST(temp_list); if (!list_count(name_list) || rc != SLURM_SUCCESS) { return SLURM_ERROR; } return SLURM_SUCCESS; }
/* * Count of gres/mps records is zero, remove them from GRES list sent to * slurmctld daemon. */ static void _remove_mps_recs(List gres_list) { ListIterator itr; gres_slurmd_conf_t *gres_record; if (gres_list == NULL) return; itr = list_iterator_create(gres_list); while ((gres_record = list_next(itr))) { if (!xstrcmp(gres_record->name, "mps")) { (void) list_delete_item(itr); } } list_iterator_destroy(itr); }
bool eio_remove_obj(eio_obj_t *obj, List objs) { ListIterator i; eio_obj_t *obj1; bool ret = false; xassert(obj != NULL); i = list_iterator_create(objs); while ((obj1 = list_next(i))) { if (obj1 == obj) { list_delete_item(i); ret = true; break; } } list_iterator_destroy(i); return ret; }
static void _connection_fini_callback(void *arg) { slurmdbd_conn_t *conn = (slurmdbd_conn_t *) arg; if (conn->conn->rem_port) { if (!shutdown_time) { slurmdb_cluster_rec_t cluster_rec; ListIterator itr; slurmdbd_conn_t *slurmdbd_conn; memset(&cluster_rec, 0, sizeof(slurmdb_cluster_rec_t)); cluster_rec.name = conn->conn->cluster_name; cluster_rec.control_host = conn->conn->rem_host; cluster_rec.control_port = conn->conn->rem_port; cluster_rec.rpc_version = conn->conn->version; cluster_rec.tres_str = conn->tres_str; debug("cluster %s has disconnected", conn->conn->cluster_name); clusteracct_storage_g_fini_ctld( conn->db_conn, &cluster_rec); slurm_mutex_lock(®istered_lock); itr = list_iterator_create(registered_clusters); while ((slurmdbd_conn = list_next(itr))) { if (conn == slurmdbd_conn) { list_delete_item(itr); break; } } list_iterator_destroy(itr); slurm_mutex_unlock(®istered_lock); } /* needs to be the last thing done */ acct_storage_g_commit(conn->db_conn, 1); } acct_storage_g_close_connection(&conn->db_conn); /* handled directly in the internal persist_conn code */ //slurm_persist_conn_members_destroy(&conn->conn); xfree(conn->tres_str); xfree(conn); }
static int _remove_allocation(char *com, List allocated_blocks) { ListIterator results_i; allocated_block_t *allocated_block = NULL; int i=1, found=0; int len = strlen(com); char letter; while (com[i-1]!=' ' && i<len) { i++; } if (i>(len-1)) { memset(error_string, 0, 255); sprintf(error_string, "You need to specify which letter to delete."); return 0; } else { letter = com[i]; results_i = list_iterator_create(allocated_blocks); while ((allocated_block = list_next(results_i)) != NULL) { if (found) { allocated_block->letter = letters[color_count%62]; allocated_block->color = colors[color_count%6]; allocated_block->color_count = color_count++; _set_nodes(allocated_block->nodes, allocated_block->color, allocated_block->letter); } else if (allocated_block->letter == letter) { found = 1; color_count = allocated_block->color_count; list_delete_item(results_i); } } list_iterator_destroy(results_i); } return 1; }
/* De-queue a checkpoint timeout request. The operation completed */ static void _ckpt_dequeue_timeout(uint32_t job_id, uint32_t step_id, time_t start_time) { ListIterator iter; struct ckpt_timeout_info *rec; slurm_mutex_lock(&ckpt_agent_mutex); if (!ckpt_timeout_list) goto fini; iter = list_iterator_create(ckpt_timeout_list); while ((rec = list_next(iter))) { if ((rec->job_id != job_id) || (rec->step_id != step_id) || (start_time && (rec->start_time != start_time))) continue; /* debug("dequeue %u.%u", job_id, step_id); */ list_delete_item(iter); break; } list_iterator_destroy(iter); fini: slurm_mutex_unlock(&ckpt_agent_mutex); }
extern void *_process_jobs(void *x) { ListIterator iter; struct job_node *jnode = NULL; time_t now; while (!thread_shutdown) { int success_cnt = 0, fail_cnt = 0, wait_retry_cnt = 0; sleep(1); iter = list_iterator_create(jobslist); while ((jnode = (struct job_node *)list_next(iter)) && !thread_shutdown) { now = time(NULL); if ((jnode->last_index_retry == 0) || (difftime(now, jnode->last_index_retry) >= INDEX_RETRY_INTERVAL)) { if ((_index_job(jnode->serialized_job) == SLURM_SUCCESS)) { list_delete_item(iter); success_cnt++; } else { jnode->last_index_retry = now; fail_cnt++; } } else wait_retry_cnt++; } list_iterator_destroy(iter); if ((success_cnt || fail_cnt) && (slurm_get_debug_flags() & DEBUG_FLAG_ESEARCH)) { info("%s: index success:%d fail:%d wait_retry:%d", plugin_type, success_cnt, fail_cnt, wait_retry_cnt); } } return NULL; }