int remove_array( job_array *pa) { char log_buf[LOCAL_LOG_BUF_SIZE]; int rc; if (pthread_mutex_trylock(allarrays.allarrays_mutex)) { unlock_ai_mutex(pa, __func__, "1", LOGLEVEL); pthread_mutex_lock(allarrays.allarrays_mutex); if(LOGLEVEL >= 7) { sprintf(log_buf, "%s: unlocked allarrays_mutex", __func__); log_event(PBSEVENT_JOB, PBS_EVENTCLASS_JOB, __func__, log_buf); } lock_ai_mutex(pa, __func__, NULL, LOGLEVEL); } rc = remove_thing(allarrays.ra,pa); pthread_mutex_unlock(allarrays.allarrays_mutex); return(rc); } /* END remove_array() */
int main() { static rtp_packet *pp; static pktbuf_t *pb; int32_t i, j, n,ts; if (pktbuf_create(&pb, PKTBUF_SIZE) == 0) { printf("Failed to create buffer\n"); exit(-1); } xmemchk(); for(i = 0; i < 100000; i++) { n = lrand48() % 16; for(j = 0; j <= n; j++) { pp = (rtp_packet*)xmalloc(sizeof(rtp_packet)); pp->ts = ts ++; add_thing(pb, pp); } n = lrand48() % 16; for(j = 0; j < n; j++) { remove_thing(pb); } } pktbuf_destroy(&pb); xmemdmp(); printf("Okay\n"); return 0; }
resizable_array *sort_exec_hosts( resizable_array *exec_hosts, const char *mppnodes) { if(mppnodes == NULL) { return exec_hosts; } char *tmp = strdup(mppnodes); char *tmp_str = tmp; resizable_array *tmp_host_list = initialize_resizable_array(100); char *tok; int iter; host_req *pHr; while((tok = threadsafe_tokenizer(&tmp_str,",")) != NULL) { iter = -1; while((pHr = (host_req *)next_thing_from_back(exec_hosts,&iter)) != NULL) { if(strcmp(pHr->hostname,tok) == 0) { insert_thing(tmp_host_list,pHr); remove_thing(exec_hosts,pHr); break; } } } iter = -1; while((pHr = (host_req *)next_thing_from_back(exec_hosts,&iter)) != NULL) { insert_thing(tmp_host_list,pHr); } free_resizable_array(exec_hosts); free(tmp); return tmp_host_list; }
/* * removes a specific tasks from this array */ int remove_task( all_tasks *at, work_task *wt) { int rc = PBSE_NONE; if (pthread_mutex_trylock(at->alltasks_mutex)) { pthread_mutex_unlock(wt->wt_mutex); pthread_mutex_lock(at->alltasks_mutex); pthread_mutex_lock(wt->wt_mutex); } if (wt->wt_being_recycled == FALSE) { rc = remove_thing(at->ra,wt); } pthread_mutex_unlock(at->alltasks_mutex); return(rc); } /* END remove_task() */