void *queue_route( void *vp) { pbs_queue *pque; job *pjob = NULL; char *queue_name; char log_buf[LOCAL_LOG_BUF_SIZE]; int iter = -1; time_t time_now = time(NULL); queue_name = (char *)vp; if (queue_name == NULL) { sprintf(log_buf, "NULL queue name"); log_err(-1, __func__, log_buf); return(NULL); } if (LOGLEVEL >= 7) { snprintf(log_buf, sizeof(log_buf), "queue name: %s", queue_name); log_event(PBSEVENT_SYSTEM, PBS_EVENTCLASS_QUEUE, __func__, log_buf); } pthread_mutex_lock(reroute_job_mutex); pque = find_queuebyname(queue_name); if (pque == NULL) { sprintf(log_buf, "Could not find queue %s", queue_name); log_err(-1, __func__, log_buf); free(queue_name); pthread_mutex_unlock(reroute_job_mutex); return(NULL); } while ((pjob = next_job(pque->qu_jobs,&iter)) != NULL) { /* the second condition says we only want to try if routing * has been tried once - this is to let req_commit have the * first crack at routing always */ unlock_queue(pque, __func__, (char *)NULL, 0); if ((pjob->ji_qs.ji_un.ji_routet.ji_rteretry <= time_now - ROUTE_RETRY_TIME) && (pjob->ji_qs.ji_un.ji_routet.ji_rteretry != 0)) { reroute_job(pjob, pque); unlock_ji_mutex(pjob, __func__, (char *)"1", LOGLEVEL); } else unlock_ji_mutex(pjob, __func__, (char *)"1", LOGLEVEL); } free(queue_name); unlock_queue(pque, __func__, (char *)NULL, 0); pthread_mutex_unlock(reroute_job_mutex); return(NULL); } /* END queue_route() */
void *queue_route( void *vp) { pbs_queue *pque; job *pjob = NULL; char *queue_name; char log_buf[LOCAL_LOG_BUF_SIZE]; all_jobs_iterator *iter = NULL; queue_name = (char *)vp; if (queue_name == NULL) { sprintf(log_buf, "NULL queue name"); log_err(-1, __func__, log_buf); return(NULL); } while (1) { pthread_mutex_lock(reroute_job_mutex); /* Before we attempt to service this queue, make sure we can find it. */ pque = find_queuebyname(queue_name); if (pque == NULL) { sprintf(log_buf, "Could not find queue %s", queue_name); log_err(-1, __func__, log_buf); free(queue_name); return(NULL); } mutex_mgr que_mutex(pque->qu_mutex, true); pque->qu_jobs->lock(); iter = pque->qu_jobs->get_iterator(); pque->qu_jobs->unlock(); if (LOGLEVEL >= 7) { snprintf(log_buf, sizeof(log_buf), "routing any ready jobs in queue: %s", queue_name); log_event(PBSEVENT_SYSTEM, PBS_EVENTCLASS_QUEUE, __func__, log_buf); } while ((pjob = next_job(pque->qu_jobs,iter)) != NULL) { /* We only want to try if routing has been tried at least once - this is to let * req_commit have the first crack at routing always. */ if (pjob->ji_commit_done == 0) /* when req_commit is done it will set ji_commit_done to 1 */ { unlock_ji_mutex(pjob, __func__, "1", LOGLEVEL); continue; } /* queue must be unlocked when calling reroute_job */ que_mutex.unlock(); reroute_job(pjob); unlock_ji_mutex(pjob, __func__, "2", LOGLEVEL); /* need to relock queue when we go to call next_job */ pque = find_queuebyname(queue_name); if (pque == NULL) { sprintf(log_buf, "Could not find queue %s", queue_name); log_err(-1, __func__, log_buf); free(queue_name); delete iter; return(NULL); } que_mutex.mark_as_locked(); } /* we come out of the while loop with the queue locked. We don't want it locked while we sleep */ que_mutex.unlock(); pthread_mutex_unlock(reroute_job_mutex); delete iter; sleep(route_retry_interval); } free(queue_name); return(NULL); } /* END queue_route() */