int insert_job_first( struct all_jobs *aj, job *pjob) { int rc; pthread_mutex_lock(aj->alljobs_mutex); if ((rc = insert_thing_after(aj->ra,pjob,ALWAYS_EMPTY_INDEX)) == -1) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE"); } else { add_hash(aj->ht,rc,pjob->ji_qs.ji_jobid); rc = PBSE_NONE; } pthread_mutex_unlock(aj->alljobs_mutex); return(rc); } /* END insert_job_first () */
/* * insert a new job into the array after a previous one * * @param already_in - the job this job should follow * @param pjob - the job to be inserted * @return PBSE_NONE if the job is inserted correctly */ int insert_job_after( struct all_jobs *aj, job *already_in, job *pjob) { int rc; int i; pthread_mutex_lock(aj->alljobs_mutex); i = get_value_hash(aj->ht,already_in->ji_qs.ji_jobid); if (i < 0) rc = THING_NOT_FOUND; else { if ((rc = insert_thing_after(aj->ra,pjob,i)) == -1) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE"); } else { add_hash(aj->ht,rc,pjob->ji_qs.ji_jobid); rc = PBSE_NONE; } } pthread_mutex_unlock(aj->alljobs_mutex); return(rc); } /* END insert_job_after() */
int insert_job_after_index( struct all_jobs *aj, int index, job *pjob) { int rc = -1; if (aj == NULL) { rc = PBSE_BAD_PARAMETER; log_err(rc, __func__, "null job array input"); return(rc); } if (pjob == NULL) { rc = PBSE_BAD_PARAMETER; log_err(rc, __func__, "null job input"); return(rc); } pthread_mutex_lock(aj->alljobs_mutex); rc = insert_thing_after(aj->ra, pjob, index); if (rc == -1) { rc = ENOMEM; log_err(rc, __func__, "No memory to resize the array...SYSTEM FAILURE"); } else { add_hash(aj->ht, rc, pjob->ji_qs.ji_jobid); rc = PBSE_NONE; } pthread_mutex_unlock(aj->alljobs_mutex); return(rc); } /* END insert_job_after_index() */
int insert_task_first( all_tasks *at, work_task *wt) { int rc; pthread_mutex_lock(at->alltasks_mutex); if ((rc = insert_thing_after(at->ra,wt,ALWAYS_EMPTY_INDEX)) == -1) { rc = ENOMEM; log_err(rc, __func__, "Cannot allocate space to resize the array"); } wt->wt_tasklist = at; pthread_mutex_unlock(at->alltasks_mutex); return(rc); } /* END insert_task_first() */