//add_job function takes in a_job struct as an argument and passes it to the job //class's add function and returns an int indicating success int table::add_job(a_job & to_add, node * & root) { char * temp_name = NULL; // for holding the company name char * temp_position = NULL; // for holding the company position if (!root) //adding at the root, or a leave recurssivly { root = new node; root->the_job = new job; root->the_job->create_job(to_add); root->left = NULL; root->right = NULL; return 1; } root->the_job->get_name(temp_name); if (strcmp(temp_name, to_add.company_name) > 0) //new nade is less { return add_job(to_add, root->left); } else if (strcmp(temp_name, to_add.company_name) < 0) //new node is more { return add_job(to_add, root->right); } else //nodes are equal { root->the_job->get_position(temp_position); if(strcmp(temp_position, to_add.position) > 0) //new position is less { return add_job(to_add, root->left); } else //new position is more { return add_job(to_add, root->right); } } }
/* * Parse as if 'o' was a command line */ void add_job_opts(const char **o) { struct thread_data *td, *td_parent; int i, in_global = 1; char jobname[32]; i = 0; td_parent = td = NULL; while (o[i]) { if (!strncmp(o[i], "name", 4)) { in_global = 0; if (td) add_job(td, jobname, 0); td = NULL; sprintf(jobname, "%s", o[i] + 5); } if (in_global && !td_parent) td_parent = get_new_job(1, &def_thread, 0); else if (!in_global && !td) { if (!td_parent) td_parent = &def_thread; td = get_new_job(0, td_parent, 0); } if (in_global) fio_options_parse(td_parent, (char **) &o[i], 1); else fio_options_parse(td, (char **) &o[i], 1); i++; } if (td) add_job(td, jobname, 0); }
void client_check_status(struct s_client *cl) { if (!cl || cl->kill || !cl->init_done) return; switch (cl->typ) { case 'm': case 'c': // Check clients for exceeding cmaxidle by checking cl->last if (!(cl->ncd_keepalive && (get_module(cl)->listenertype & LIS_NEWCAMD)) && cl->last && cfg.cmaxidle && (time(NULL) - cl->last) > (time_t)cfg.cmaxidle) { add_job(cl, ACTION_CLIENT_IDLE, NULL, 0); } break; case 'r': cardreader_checkhealth(cl, cl->reader); break; case 'p': { struct s_reader *rdr = cl->reader; if (!rdr || !rdr->enable || !rdr->active) //reader is disabled or restarting at this moment break; // execute reader do idle on proxy reader after a certain time (rdr->tcp_ito = inactivitytimeout) // disconnect when no keepalive available if ((rdr->tcp_ito && is_cascading_reader(rdr)) || rdr->typ == R_CCCAM) { time_t now = time(NULL); int32_t time_diff = abs(now - rdr->last_check); if (time_diff > 60 || (time_diff > 30 && rdr->typ == R_CCCAM)) { //check 1x per minute or every 30s for cccam add_job(rdr->client, ACTION_READER_IDLE, NULL, 0); rdr->last_check = now; } } break; } } }
void client_check_status(struct s_client *cl) { if(!cl || cl->kill || !cl->init_done) { return; } switch(cl->typ) { case 'm': case 'c': if((get_module(cl)->listenertype & LIS_CCCAM) && cl->last && (time(NULL) - cl->last) > (time_t)12) { add_job(cl, ACTION_CLIENT_IDLE, NULL, 0); } //Check umaxidle to avoid client is killed for inactivity, it has priority than cmaxidle if(!cl->account->umaxidle) break; // Check user for exceeding umaxidle by checking cl->last if(!(cl->ncd_keepalive && (get_module(cl)->listenertype & LIS_NEWCAMD)) && cl->account->umaxidle>0 && cl->last && (time(NULL) - cl->last) > (time_t)cl->account->umaxidle) { add_job(cl, ACTION_CLIENT_IDLE, NULL, 0); } // Check clients for exceeding cmaxidle by checking cl->last if(!(cl->ncd_keepalive && (get_module(cl)->listenertype & LIS_NEWCAMD)) && cl->last && cl->account->umaxidle==-1 && cfg.cmaxidle && (time(NULL) - cl->last) > (time_t)cfg.cmaxidle) { add_job(cl, ACTION_CLIENT_IDLE, NULL, 0); } break; case 'r': cardreader_checkhealth(cl, cl->reader); break; case 'p': { struct s_reader *rdr = cl->reader; if(!rdr || !rdr->enable || !rdr->active) //reader is disabled or restarting at this moment { break; } // execute reader do idle on proxy reader after a certain time (rdr->tcp_ito = inactivitytimeout) // disconnect when no keepalive available if((rdr->tcp_ito && is_cascading_reader(rdr)) || (rdr->typ == R_CCCAM) || (rdr->typ == R_CAMD35) || (rdr->typ == R_CS378X) || (rdr->typ == R_SCAM) || (rdr->tcp_ito != 0 && rdr->typ == R_RADEGAST)) { time_t now = time(NULL); int32_t time_diff = llabs(now - rdr->last_check); if(time_diff > 60 || (time_diff > 12 && (rdr->typ == R_CCCAM || rdr->typ == R_CAMD35 || rdr->typ == R_CS378X)) || ((time_diff > (rdr->tcp_rto?rdr->tcp_rto:60)) && rdr->typ == R_RADEGAST)) //check 1x per minute or every 10s for cccam/camd35 or reconnecttimeout radegast if 0 defaut 60s { add_job(rdr->client, ACTION_READER_IDLE, NULL, 0); rdr->last_check = now; } } break; } } }
int main(void) { queue_init(&queue); printf("queue successfully initialized.\n"); add_job(&queue, 0); add_job(&queue, 1); add_job(&queue, 2); add_job(&queue, 3); printf("jobs successfully added.\n"); printf("%i dequeued.\n", poll_job(&queue)); printf("%i dequeued.\n", poll_job(&queue)); printf("%i dequeued.\n", poll_job(&queue)); printf("%i dequeued.\n", poll_job(&queue)); }
static void * card_poll(void) { struct s_client *cl; struct s_reader *rdr; pthread_mutex_t card_poll_sleep_cond_mutex; SAFE_MUTEX_INIT(&card_poll_sleep_cond_mutex, NULL); SAFE_COND_INIT(&card_poll_sleep_cond, NULL); set_thread_name(__func__); while (!exit_oscam) { cs_readlock(__func__, &readerlist_lock); for (rdr=first_active_reader; rdr; rdr=rdr->next) { if (rdr->enable && rdr->card_status == CARD_INSERTED) { cl = rdr->client; if (cl && !cl->kill) { add_job(cl, ACTION_READER_POLL_STATUS, 0, 0); } } } cs_readunlock(__func__, &readerlist_lock); struct timespec ts; struct timeval tv; gettimeofday(&tv, NULL); ts.tv_sec = tv.tv_sec; ts.tv_nsec = tv.tv_usec * 1000; ts.tv_sec += 1; SAFE_MUTEX_LOCK(&card_poll_sleep_cond_mutex); SAFE_COND_TIMEDWAIT(&card_poll_sleep_cond, &card_poll_sleep_cond_mutex, &ts); // sleep on card_poll_sleep_cond SAFE_MUTEX_UNLOCK(&card_poll_sleep_cond_mutex); } return NULL; }
void cacheex_timeout(ECM_REQUEST *er) { if(er->cacheex_wait_time_expired) return; er->cacheex_wait_time_expired = 1; if(er->rc >= E_UNHANDLED) { cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex timeout! ", (check_client(er->client) ? er->client->account->usr : "******"), er->caid, er->prid, er->srvid); // if check_cw mode=0, first try to get cw from cache without check counter! CWCHECK check_cw = get_cwcheck(er); if(!check_cw.mode) { struct ecm_request_t *ecm = NULL; ecm = check_cache(er, er->client); if(ecm) // found in cache { struct s_write_from_cache *wfc = NULL; if(!cs_malloc(&wfc, sizeof(struct s_write_from_cache))) { NULLFREE(ecm); return; } wfc->er_new = er; wfc->er_cache = ecm; if(!add_job(er->client, ACTION_ECM_ANSWER_CACHE, wfc, sizeof(struct s_write_from_cache))) // write_ecm_answer_fromcache { NULLFREE(ecm); } return; } } // check if "normal" readers selected, if not send NOT FOUND! // cacheex1-client (having always no "normal" reader), // or not-cacheex-1 client with no normal readers available (or filtered by LB) if((er->reader_count + er->fallback_reader_count - er->cacheex_reader_count) <= 0) { if(!cfg.wait_until_ctimeout) { er->rc = E_NOTFOUND; er->selected_reader = NULL; er->rcEx = 0; cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex timeout: NO \"normal\" readers... not_found! ", (check_client(er->client) ? er->client->account->usr : "******"), er->caid, er->prid, er->srvid); send_dcw(er->client, er); return; } } else { if(er->stage < 2) { debug_ecm(D_TRACE, "request for %s %s", username(er->client), buf); request_cw_from_readers(er, 0); } } } }
void tsp_partiel (int hops, int len, Path_t path, int *cuts) { int i ; int me, dist ; if (len >= minimum) { (*cuts)++ ; return; } if (hops == MINNBHOPS) { #ifdef DEBUG PrintPath("Add job : ", hops, path); #endif add_job (&listeTaches, path, hops, len); } else { me = path [hops-1] ; for (i=0; i < NbCities; i++) { if (!present (i, hops, path)) { path [hops] = i ; dist = distance[me][i] ; tsp_partiel (hops+1, len+dist, path, cuts) ; } } } }
// Attach to AFU static void _attach(struct psl *psl, struct client *client) { uint64_t wed; uint8_t ack; uint8_t buffer[MAX_LINE_CHARS]; size_t size; // FIXME: This only works for dedicate mode // Get wed value from application ack = PSLSE_DETACH; size = sizeof(uint64_t); if (get_bytes_silent(client->fd, size, buffer, psl->timeout, &(client->abort)) < 0) { warn_msg("Failed to get WED value from client"); client_drop(client, PSL_IDLE_CYCLES, CLIENT_NONE); goto attach_done; } memcpy((char *)&wed, (char *)buffer, sizeof(uint64_t)); wed = ntohll(wed); // Send start to AFU if (add_job(psl->job, PSL_JOB_START, wed) != NULL) { psl->idle_cycles = PSL_IDLE_CYCLES; ack = PSLSE_ATTACH; } attach_done: if (put_bytes(client->fd, 1, &ack, psl->dbg_fp, psl->dbg_id, client->context) < 0) { client_drop(client, PSL_IDLE_CYCLES, CLIENT_NONE); } }
int32_t reader_checkhealth(struct s_reader * reader) { struct s_client *cl = reader->client; if (reader_card_inserted(reader)) { if (reader->card_status == NO_CARD || reader->card_status == UNKNOWN) { rdr_log(reader, "card detected"); led_status_card_detected(); reader->card_status = CARD_NEED_INIT; //reader_reset(reader); add_job(cl, ACTION_READER_RESET, NULL, 0); } } else { if (reader->card_status == CARD_INSERTED || reader->card_status == CARD_NEED_INIT) { rdr_log(reader, "card ejected"); reader_nullcard(reader); if (cl) { cl->lastemm = 0; cl->lastecm = 0; } led_status_card_ejected(); } reader->card_status = NO_CARD; } return reader->card_status == CARD_INSERTED; }
int gw_em_mad_recover( int jid, char *job_contact, char *info ) { int rc; int *i; if (!mad.initialized) { strcpy(info, "MAD not initialized"); return 1; } i = (int *) malloc( sizeof(int)); *i = jid; rc = globus_gram_client_register_job_callback_registration(job_contact, GLOBUS_GRAM_PROTOCOL_JOB_STATE_ALL, mad.callback_contact, GLOBUS_GRAM_CLIENT_NO_ATTR, gw_em_mad_recover_callback, i); if (rc != GLOBUS_SUCCESS) { sprintf(info, "GRAM client job callback register failed: %s (error %d)", globus_gram_client_error_string(rc), rc); return 1; } add_job(jid, job_contact); return 0; }
void tsp_partiel (int hops, int len, Path_t path, int *cuts) { int i ; int me, dist ; if (len >= minimum) { cuts[hops]++ ; return; } if (hops == NUM) { add_job (&q, path, hops, len); } else { me = path [hops-1] ; for (i=0; i < NrTowns; i++) { if (!present (i, hops, path)) { path [hops] = i ; dist = distance[me][i] ; tsp_partiel (hops+1, len+dist, path, cuts) ; } } } }
int32_t cardreader_do_checkhealth(struct s_reader * reader) { struct s_client *cl = reader->client; if (reader_card_inserted(reader)) { if (reader->card_status == NO_CARD || reader->card_status == UNKNOWN) { rdr_log(reader, "card detected"); led_status_card_detected(); reader->card_status = CARD_NEED_INIT; add_job(cl, ACTION_READER_RESET, NULL, 0); } } else { rdr_debug_mask(reader, D_READER, "%s: !reader_card_inserted", __func__); if (reader->card_status == CARD_INSERTED || reader->card_status == CARD_NEED_INIT) { rdr_log(reader, "card ejected"); reader_nullcard(reader); NULLFREE(reader->csystem_data); if (cl) { cl->lastemm = 0; cl->lastecm = 0; } led_status_card_ejected(); } reader->card_status = NO_CARD; } rdr_debug_mask(reader, D_READER, "%s: reader->card_status = %d, ret = %d", __func__, reader->card_status, reader->card_status == CARD_INSERTED); return reader->card_status == CARD_INSERTED; }
void move_to_background(pid_t pgid, int state, char *command, int len) { int jid = find_job(pgid); if (jid < 0) add_job(pgid, state, command, len); else update_job(pgid, state); }
/* Allows to kill another thread specified through the client cl with locking. If the own thread has to be cancelled, cs_exit or cs_disconnect_client has to be used. */ void kill_thread(struct s_client *cl) { if (!cl || cl->kill) return; if (cl == cur_client()) { cs_log("Trying to kill myself, exiting."); cs_exit(0); } add_job(cl, ACTION_CLIENT_KILL, NULL, 0); //add kill job, ... cl->kill=1; //then set kill flag! }
Trick::DataRecordGroup::DataRecordGroup( std::string in_name ) : record(true) , inited(false) , group_name(in_name) , freq(DR_Always), start(0.0) , cycle(0.1) , time_value_attr() , num_variable_names(0), variable_names(NULL), variable_alias(NULL), num_change_variable_names(0), change_variable_names(NULL), change_variable_alias(NULL), max_num(100000), buffer_num(0), writer_num(0), max_file_size(1<<30), // 1 GB total_bytes_written(0), writer_buff(NULL), single_prec_only(false), buffer_type(DR_Buffer), job_class("data_record"), curr_time(0.0) { union { long l; char c[sizeof(long)]; } byte_order_union; byte_order_union.l = 1; if (byte_order_union.c[sizeof(long) - 1] != 1) { byte_order = "little_endian" ; } else { byte_order = "big_endian" ; } // sim object name name = std::string("trick_data_record_group_") + in_name ; // add_jobs_to_queue will fill in job_id later // make the init job run after all other initialization jobs but before the post init checkpoint // job so users can allocate memory in initialization jobs and checkpointing data rec groups will work add_job(0, 1, (char *)"initialization", NULL, cycle, (char *)"init", (char *)"TRK", 65534) ; add_job(0, 2, (char *)"end_of_frame", NULL, 1.0, (char *)"write_data", (char *)"TRK") ; add_job(0, 3, (char *)"checkpoint", NULL, 1.0, (char *)"checkpoint", (char *)"TRK") ; add_job(0, 4, (char *)"post_checkpoint", NULL, 1.0, (char *)"clear_checkpoint_vars", (char *)"TRK") ; // run the restart job in phase 60001 add_job(0, 5, (char *)"restart", NULL, 1.0, (char *)"restart", (char *)"TRK", 60001) ; add_job(0, 6, (char *)"shutdown", NULL, 1.0, (char *)"shutdown", (char *)"TRK") ; // (Alex 1/15/14) The dmtcp_restart job is called by the DataRecordDispatcher... is the // dispatcher necessary anymore? write_job = add_job(0, 99, (char *)job_class.c_str(), NULL, cycle, (char *)"data_record" , (char *)"TRK") ; add_time_variable() ; }
int start_steadystaterwp_generator (omg_global_param omg_param_list) { static int n_id = 0; int id; double cur_time = 0.0, pause_p; node_struct *node = NULL; mobility_struct *mobility = NULL; pair_struct *pair = NULL; pause_p = pause_probability (omg_param_list); srand (omg_param_list.seed + RWP); LOG_I (OMG, "STEADY_RWP mobility model for %d %d nodes\n", omg_param_list.nodes, omg_param_list.nodes_type); for (id = n_id; id < (omg_param_list.nodes + n_id); id++) { node = create_node (); mobility = create_mobility (); node->id = id; node->type = omg_param_list.nodes_type; node->mob = mobility; node->generator = STEADY_RWP; node->event_num = 0; place_rwp_node (node); //initial positions pair = (pair_struct *) malloc (sizeof (struct pair_struct)); pair->b = node; //pause probability...some of the nodes start at pause & the other on move if (randomgen (0, 1) < pause_p) sleep_steadystaterwp_node (pair, cur_time); //sleep else move_steadystaterwp_node (pair, cur_time); job_vector_end[STEADY_RWP] = add_job (pair, job_vector_end[STEADY_RWP]); if (job_vector[STEADY_RWP] == NULL) job_vector[STEADY_RWP] = job_vector_end[STEADY_RWP]; job_vector_len[STEADY_RWP]++; } n_id += omg_param_list.nodes; if (job_vector[STEADY_RWP] == NULL) LOG_E (OMG, "[STEADY_RWP] Job Vector is NULL\n"); return (0); }
void IntegLoopSimObject::add_jobs(double in_cycle, unsigned int child) { Trick::JobData * job ; exec_register_scheduler(&integ_sched) ; job = add_job(0, 0, "default_data", NULL, 1, "integ_sched.rebuild_jobs", "", 65534) ; job->add_tag("TRK") ; job = add_job(0, 1, "initialization", NULL, 1, "integ_sched.get_first_step_deriv_from_integrator", "", 65535) ; job->add_tag("TRK") ; job = add_job(0, 2, "initialization", NULL, 1, "integ_sched.call_deriv_jobs", "", 65535) ; job->add_tag("TRK") ; job = add_job(child, 3, "integ_loop", NULL, in_cycle, "integ_sched.integrate", "", 60000) ; job->add_tag("TRK") ; job = add_job(0, 4, "checkpoint", NULL, 1, "checkpoint_stl", "", 60000) ; job = add_job(0, 5, "post_checkpoint", NULL, 1, "delete_stl", "", 60000) ; job = add_job(0, 6, "restart", NULL, 1, "restore_stl", "", 60000) ; job = add_job(0, 7, "preload_checkpoint", NULL, 1, "integ_sched.restart_checkpoint", "", 0) ; job->add_tag("TRK") ; job = add_job(0, 8, "restart", NULL, 1, "integ_sched.rebuild_jobs", "", 60000) ; job->add_tag("TRK") ; job = add_job(0, 9, "restart", NULL, 1, "integ_sched.get_first_step_deriv_from_integrator", "", 65535) ; job->add_tag("TRK") ; }
static void *work(void *args) { int i; int work_num; int failed = 0; DENTER(TOP_LAYER, "work"); work_num = *((int *)args); WARNING((SGE_EVENT, "work %d starting %d loops", work_num, loops)); for (i = 0; i < loops; i++) { #if SGE_LOCKING /* SGE_LOCK(LOCK_GLOBAL, LOCK_WRITE); */ pthread_mutex_lock(&mtx); #endif if (!add_job(work_num * loops + i)) { failed++; } #if SGE_LOCKING /* SGE_UNLOCK(LOCK_GLOBAL, LOCK_WRITE); */ pthread_mutex_unlock(&mtx); #endif } WARNING((SGE_EVENT, "work %d finished adding %d jobs, %d failed", work_num, loops, failed)); failed = 0; for (i = 0; i < loops; i++) { #if SGE_LOCKING /* SGE_LOCK(LOCK_GLOBAL, LOCK_WRITE); */ pthread_mutex_lock(&mtx); #endif if(!del_job(work_num * loops + i)) { failed++; } #if SGE_LOCKING /* SGE_UNLOCK(LOCK_GLOBAL, LOCK_WRITE); */ pthread_mutex_unlock(&mtx); #endif } WARNING((SGE_EVENT, "work %d finished deleting %d jobs, %d failed", work_num, loops, failed)); DEXIT; return (void *)NULL; }
static int32_t bulcrypt_do_emm(struct s_reader *reader, EMM_PACKET *ep) { char tmp[512]; uchar emm_cmd[1024]; def_resp // DE 04 xx yy B0 // xx == EMM type (emm[0]) // yy == EMM type2 (emm[5]) // B0 == EMM len (176) memcpy(emm_cmd, cmd_emm1, sizeof(cmd_emm1)); memcpy(emm_cmd + sizeof(cmd_emm1), ep->emm + 7, 176); switch (ep->emm[0]) { case BULCRYPT_EMM_UNIQUE_82: emm_cmd[2] = ep->emm[0]; // 0x82 break; case BULCRYPT_EMM_UNIQUE_8a: // Polaris equivallent of 0x82 emm_cmd[2] = 0x82; emm_cmd[3] = 0x0b; break; case BULCRYPT_EMM_SHARED_84: emm_cmd[2] = ep->emm[0]; // 0x84 emm_cmd[3] = ep->emm[5]; // 0x0b break; case BULCRYPT_EMM_UNIQUE_85: case BULCRYPT_EMM_UNIQUE_8b: // Polaris 0x85 equivallent of 0x85 memcpy(emm_cmd, cmd_emm2, sizeof(cmd_emm2)); emm_cmd[2] = ep->emm[5]; // 0xXX (Last bytes of the serial) emm_cmd[3] = ep->emm[6]; // 0x0b break; } // Write emm write_cmd(emm_cmd, emm_cmd + 5); if (cta_lr != 2 || cta_res[0] != 0x90 || (cta_res[1] != 0x00 && cta_res[1] != 0x0a)) { rdr_log(reader, "(emm_cmd) Unexpected card answer: %s", cs_hexdump(1, cta_res, cta_lr, tmp, sizeof(tmp))); return ERROR; } if (ep->emm[0] == BULCRYPT_EMM_UNIQUE_82 && cta_res[0] == 0x90 && cta_res[1] == 0x0a) { rdr_log(reader, "Your subscription data was updated."); add_job(reader->client, ACTION_READER_CARDINFO, NULL, 0); } return OK; }
static void find_full_tree(void) { const char * extract_subdir[] = { bmake_path, "show-subdir-var", "VARNAME=SUBDIR", NULL }; char *cat_path; char *buf, *buf_orig, *cat, *cat_orig; size_t buf_len, cat_len; buf = read_from_child(pkgsrc_tree, bmake_path, extract_subdir); if (buf == NULL) err(1, "Cannot extract categories"); cat = cat_orig = buf; for (;;) { cat += strspn(cat, " \t\n"); cat_len = strcspn(cat, " \t\n"); if (cat_len == 0) break; cat_path = xasprintf("%s/%.*s", pkgsrc_tree, (int)cat_len, cat); buf_orig = buf = read_from_child(cat_path, bmake_path, extract_subdir); free(cat_path); if (buf == NULL) { warnx("Cannot extract subdirectories for %.*s", (int)cat_len, cat); cat += cat_len; continue; } for (;;) { buf += strspn(buf, " \t\n"); buf_len = strcspn(buf, " \t\n"); if (buf_len == 0) break; add_job(cat, cat_len, buf, buf_len); buf += buf_len; } free(buf_orig); cat += cat_len; } free(cat_orig); }
/* * Check the spool directory for pending jobs on start-up. * * LOCKING: none. */ void build_qonstart(void) { int fd, err, nr; int32_t jobid; DIR *dirp; struct dirent *entp; struct printreq req; char dname[FILENMSZ], fname[FILENMSZ]; sprintf(dname, "%s/%s", SPOOLDIR, REQDIR); if ((dirp = opendir(dname)) == NULL) return; while ((entp = readdir(dirp)) != NULL) { /* * Skip "." and ".." */ if (strcmp(entp->d_name, ".") == 0 || strcmp(entp->d_name, "..") == 0) continue; /* * Read the request structure. */ sprintf(fname, "%s/%s/%s", SPOOLDIR, REQDIR, entp->d_name); if ((fd = open(fname, O_RDONLY)) < 0) continue; nr = read(fd, &req, sizeof(struct printreq)); if (nr != sizeof(struct printreq)) { if (nr < 0) err = errno; else err = EIO; close(fd); log_msg("build_qonstart: can't read %s: %s", fname, strerror(err)); unlink(fname); sprintf(fname, "%s/%s/%s", SPOOLDIR, DATADIR, entp->d_name); unlink(fname); continue; } jobid = atol(entp->d_name); log_msg("adding job %d to queue", jobid); add_job(&req, jobid); } closedir(dirp); }
int start_rwp_generator (omg_global_param omg_param_list) { static int n_id = 0; int id; double cur_time = 0.0; node_struct *node = NULL; mobility_struct *mobility = NULL; pair_struct *pair = NULL; srand (omg_param_list.seed + RWP); LOG_I (OMG, "# RWP mobility model for %d type %d nodes\n", omg_param_list.nodes, omg_param_list.nodes_type); for (id = n_id; id < (omg_param_list.nodes + n_id); id++) { node = create_node (); mobility = create_mobility (); node->id = id; node->type = omg_param_list.nodes_type; node->mob = mobility; node->generator = RWP; node->event_num = 0; place_rwp_node (node); //initial positions pair = (pair_struct *) malloc (sizeof (struct pair_struct)); pair->b = node; sleep_rwp_node (pair, cur_time); //sleep job_vector_end[RWP] = add_job (pair, job_vector_end[RWP]); if (job_vector[RWP] == NULL) job_vector[RWP] = job_vector_end[RWP]; job_vector_len[RWP]++; } n_id += omg_param_list.nodes; if (job_vector[RWP] == NULL) LOG_E (OMG, "[RWP] Job Vector is NULL\n"); return (0); }
int start_rwalk_generator(omg_global_param omg_param_list) { int n_id=0; //omg_omg_param_list.seed= time(NULL); srand(omg_param_list.seed + RWALK); double cur_time = 0.0; NodePtr node = NULL; MobilityPtr mobility = NULL; if (omg_param_list.nodes <= 0){ LOG_W(OMG, "Number of nodes has not been set\n"); return(-1); } if (omg_param_list.nodes_type == eNB) { LOG_I(OMG, "Node type has been set to eNB\n"); } else if (omg_param_list.nodes_type == UE) { LOG_I(OMG, "Node type has been set to UE\n"); } LOG_I(OMG, "Number of random walk nodes has been set to %d\n", omg_param_list.nodes); for (n_id = 0; n_id< omg_param_list.nodes; n_id++) { node = (NodePtr) create_node(); mobility = (MobilityPtr) create_mobility(); node->mobile = 0; // static for the moment node->ID = n_id; node->type = omg_param_list.nodes_type; node->generator = omg_param_list.mobility_type; node->mob = mobility; place_rwalk_node(node); //initial positions Pair pair = malloc (sizeof(Pair)); pair = (Pair) sleep_rwalk_node(node, cur_time); //sleep Job_Vector = add_job(pair, Job_Vector); Job_Vector_len ++; if (Job_Vector == NULL) LOG_E(OMG, "Job Vector is NULL\n"); } return(0); }
int main(int argc, char *argv[]) { guint n_threads = 10; guint n; struct configuration conf= { NULL, NULL, NULL, 0 }; GThread **threads = g_new(GThread*, n_threads); struct thread_data* td = g_new(struct thread_data, n_threads); conf.queue = g_async_queue_new(); conf.ready = g_async_queue_new(); for (n = 0; n < n_threads; n++) { td[n].thread_id = n + 1; td[n].conf = &conf; threads[n] = g_thread_create((GThreadFunc)process_queue, &td[n], TRUE, NULL); g_async_queue_pop(conf.ready); } g_async_queue_unref(conf.ready); g_message("%d threads created", n_threads); add_job(&conf,"TEST1","10", 3305); add_job(&conf,"TEST2","11", 3306); add_job(&conf,"TEST3","12", 3307); add_job(&conf,"TEST4","13", 3308); add_job(&conf,"TEST5","14", 3309); add_job(&conf,"TEST6","14", 3309); add_job(&conf,"TEST7","14", 3309); for (n = 0; n < n_threads; n++) { struct job * jb = g_new0(struct job, 1); jb->type = JOB_SHUTDOWN; g_async_queue_push(conf.queue, jb); } for (n = 0; n < n_threads; n++) g_thread_join(threads[n]); g_async_queue_unref(conf.queue); g_free(td); g_free(threads); return 0; }
static void generate_tsp_jobs (struct tsp_queue *q, int hops, int len, tsp_path_t path, long long int *cuts, tsp_path_t sol, int *sol_len, int depth) { if (len >= minimum) { (*cuts)++ ; return; } if (hops == depth) { /* On enregistre du travail à faire plus tard... */ add_job (q, path, hops, len); } else { int me = path [hops - 1]; for (int i = 0; i < nb_towns; i++) { if (!present (i, hops, path)) { path[hops] = i; int dist = distance[me][i]; generate_tsp_jobs (q, hops + 1, len + dist, path, cuts, sol, sol_len, depth); } } } }
int main(int argc, char *argv[]){ if(argc!=2){ printf("usage: prog joblibst\n"); printf("Run jobs with definite num. of seconds since run useless\n"); return EARG; } FILE *f; openf(f,argv[1],"r"); int sec; char * comm = NULL; size_t len = 0; while(fscanf(f,"%d ",&sec)==1){ getline(&comm, &len, f); add_job(comm,sec); } fclose(f); qsort(jobs,cnt,sizeof(joblist),cmp); print_job(); exec_job(); return SUCC; }
/* * Creates a new job object for the worker_thread appending it to the end of job's queue. */ static thread_job_list *add_job(thread_job_list *h, int type, int (*f)(void)) { if (h) { h->next = add_job(h->next, type, f); } else { if (!(h = malloc(sizeof(struct thread_list)))) { quit = MEM_ERR_QUIT; ERROR("could not malloc. Leaving."); return NULL; } num_of_jobs++; h->selected_files = NULL; h->next = NULL; h->f = f; strncpy(h->full_path, ps[active].my_cwd, PATH_MAX); h->num_selected = num_selected; h->type = type; h->num = num_of_jobs; current_th = h; } return h; }
void add_jobs(Puzzle *puz, Solution *sol, int except, Cell *cell, int depth, bit_type *old) { dir_t k; line_t i, j; int lwork, rwork; /* While probing, we OR all bits set into our scratchpad. These values * should not be probed on later during this sequence. */ if (probing) fbit_or(propad(cell),cell->bit); if (!maylinesolve) return; for (k= 0; k < puz->nset; k++) if (k != except) { i= cell->line[k]; j= cell->index[k]; /* We only add the job only if either the saved left or right * solution for the line has been invalidated. */ if (VL || WL(puz->clue[k][i])) printf ("L: CHECK OLD SOLN FOR %s %d CELL %d\n", CLUENAME(puz->type,k),i,j); lwork= left_check(&puz->clue[k][i], j, cell->bit); rwork= right_check(&puz->clue[k][i], j, cell->bit); if (lwork || rwork) { add_job(puz, k, i, depth, newedge(puz, sol->line[k][i], j, old, cell->bit) ); if (!VJ && WL(puz->clue[k][i])) dump_jobs(stdout,puz); } } }
void gw_em_mad_submit_callback(void *arg, globus_gram_protocol_error_t failure_code, const char * job_contact, globus_gram_protocol_job_state_t job_state, globus_gram_protocol_error_t error_code) { int *jid; jid = (int *) arg; if ( failure_code == GLOBUS_SUCCESS) { add_job(*jid, job_contact); printf("SUBMIT %d SUCCESS %s\n", *jid, job_contact); } else { printf("SUBMIT %d FAILURE %s (%i)\n", *jid, globus_gram_client_error_string(failure_code), error_code); } free(jid); }