int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb callback, void *data, int variable) { /* * Schedule callback(data) to happen when ms into the future */ struct sched *tmp; int res = -1; DEBUG(ast_log(LOG_DEBUG, "ast_sched_add()\n")); if (!when) { ast_log(LOG_NOTICE, "Scheduled event in 0 ms?\n"); return -1; } ast_mutex_lock(&con->lock); if ((tmp = sched_alloc(con))) { tmp->id = con->eventcnt++; tmp->callback = callback; tmp->data = data; tmp->resched = when; tmp->variable = variable; tmp->when = ast_tv(0, 0); if (sched_settime(&tmp->when, when)) { sched_release(con, tmp); } else { schedule(con, tmp); res = tmp->id; } } #ifdef DUMP_SCHEDULER /* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */ ast_sched_dump(con); #endif ast_mutex_unlock(&con->lock); return res; }
int cw_sched_add_variable(struct sched_context *con, int when, cw_sched_cb callback, void *data, int variable) { /* * Schedule callback(data) to happen when ms into the future */ struct sched *tmp; int res = -1; #ifdef DEBUG_SCHED DEBUG_LOG(cw_log(LOG_DEBUG, "cw_sched_add_variable()\n")); #endif cw_mutex_lock(&con->lock); if ((tmp = sched_alloc(con))) { if ((tmp->id = con->eventcnt++) < 0) tmp->id = con->eventcnt = 0; tmp->callback = callback; tmp->data = data; tmp->resched = when; tmp->variable = variable; tmp->when = cw_tvadd(cw_tvnow(), cw_samp2tv(when, 1000)); schedule(con, tmp); res = tmp->id; } #ifdef DUMP_SCHEDULER /* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */ cw_sched_dump(con); #endif cw_mutex_unlock(&con->lock); return res; }
pbs_sched * sched_recov_db(char *sname) { pbs_sched *ps; pbs_db_sched_info_t dbsched; pbs_db_obj_info_t obj; pbs_db_conn_t *conn = (pbs_db_conn_t *) svr_db_conn; obj.pbs_db_obj_type = PBS_DB_SCHED; obj.pbs_db_un.pbs_db_sched = &dbsched; ps = sched_alloc(sname); /* allocate & init sched structure space */ if (ps == NULL) { log_err(-1, "sched_recov", "sched_alloc failed"); return NULL; } /* load sched */ dbsched.sched_name[sizeof(dbsched.sched_name) - 1] = '\0'; strncpy(dbsched.sched_name, sname, sizeof(dbsched.sched_name)); /* read in job fixed sub-structure */ if (pbs_db_load_obj(conn, &obj) != 0) goto db_err; if (db_to_svr_sched(ps, &dbsched) != 0) goto db_err; pbs_db_reset_obj(&obj); /* all done recovering the sched */ return (ps); db_err: log_err(-1, "sched_recov", "read of scheddb failed"); if (ps) free(ps); return NULL; }