void init_cfg(t_cfg *cfg, int argc, char **argv) { cfg->mlx = mlx_init(); cfg->win = mlx_new_window(cfg->mlx, WIDTH, HEIGHT, "Fractol"); cfg->img.img = mlx_new_image(cfg->mlx, WIDTH, HEIGHT); cfg->img.data = mlx_get_data_addr(cfg->img.img, &cfg->img.bpp, &cfg->img.sl, &cfg->img.endian); cfg->type = ftype(argc, argv); cfg->iter = 50; cfg->cr = -0.75; cfg->ci = 0.27015; cfg->zoom = 1.0; cfg->theme = 0; cfg->themev = 0; cfg->offset = (t_dvec2){.x = 0.0, .y = 0.0}; cfg->color = (t_color){.r = 0.0, .g = 0.0, .b = 0.0}; init_sval(cfg); } int main(int argc, char **argv) { t_cfg cfg; init_cfg(&cfg, argc, argv); mlx_put_image_to_window(cfg.mlx, cfg.win, cfg.img.img, 0, 0); mlx_hook(cfg.win, 2, 1, key_hook, &cfg); mlx_hook(cfg.win, 6, 64, &mouse, &cfg); mlx_expose_hook(cfg.win, expose_hook, &cfg); mlx_loop(cfg.mlx); return (0); }
void DEX_REGION::process_simply(OUT PRNO2UINT & prno2v, UINT param_num, UINT vregnum, DEX2IR & d2ir, UINT2PR * v2pr, IN PRNO2UINT * pr2v, TYIDR * tr) { LOG("\t\t Invoke DEX_REGION::process_simply '%s'", get_ru_name()); if (get_ir_list() == NULL) { return ; } OPT_CTX oc; OPTC_show_comp_time(oc) = g_show_comp_time; CHAR const* ru_name = get_ru_name(); construct_ir_bb_list(); IS_TRUE0(verify_ir_and_bb(get_bb_list(), get_dm())); RU_ana(this)->m_ir_list = NULL; //All IRs have been moved to each IR_BB. IR_CFG * cfg = init_cfg(oc); cfg->loop_analysis(oc); PASS_MGR * pm = new_pass_mgr(); OPTC_pass_mgr(oc) = pm; //record pass manager. if (g_do_ssa && OPTC_pass_mgr(oc) != NULL) { //Convert program to ssa form. IR_SSA_MGR * ssamgr = (IR_SSA_MGR*)OPTC_pass_mgr(oc)-> register_opt(OPT_SSA_MGR); IS_TRUE0(ssamgr); ssamgr->construction(oc, this); } init_aa(oc); init_du(oc); IR_SSA_MGR * ssamgr = (IR_SSA_MGR*)pm->query_opt(OPT_SSA_MGR); if (ssamgr != NULL && ssamgr->is_ssa_construct()) { //Destruct ssa form. ssamgr->destruction_in_bblist_order(); } delete pm; OPTC_pass_mgr(oc) = NULL; #if 1 //Do not allocate register. prno2v.clean(); prno2v.copy(*d2ir.get_pr2v_map()); return; #else //Allocate register. RA ra(this, tr, param_num, vregnum, v2pr, pr2v, &m_var2pr); LOG("\t\tdo DEX Register Allcation for '%s'", ru_name); ra.perform(oc); update_ra_res(ra, prno2v); #endif }
int refreshmenu() { CONF *tconf = conf; conf = NULL; if(!init_cfg()) { conf = tconf; return 0; } else { free(tconf); return 1; } }
extern "C" void init_il2cfg(SuifEnv *suif_env) { static bool init_done = false; if (init_done) return; init_done = true; ModuleSubSystem *mSubSystem = suif_env->get_module_subsystem(); mSubSystem->register_module(new Il2cfgSuifPass(suif_env)); // initialize the libraries required by this OPI pass init_suifpasses(suif_env); init_machine(suif_env); init_cfg(suif_env); }
bool DEX_REGION::high_process(OPT_CTX & oc) { CHAR const* ru_name = get_ru_name(); g_indent = 0; SIMP_CTX simp; SIMP_if(&simp) = 1; SIMP_do_loop(&simp) = 1; SIMP_do_while(&simp) = 1; SIMP_while_do(&simp) = 1; SIMP_switch(&simp) = 0; SIMP_break(&simp) = 1; SIMP_continue(&simp) = 1; RU_ana(this)->m_ir_list = simplify_stmt_list(get_ir_list(), &simp); IS_TRUE0(verify_simp(get_ir_list(), simp)); IS_TRUE0(verify_irs(get_ir_list(), NULL, get_dm())); construct_ir_bb_list(); IS_TRUE0(verify_ir_and_bb(get_bb_list(), get_dm())); RU_ana(this)->m_ir_list = NULL; //All IRs have been moved to each IR_BB. IS_TRUE0(g_do_cfg && g_do_aa && g_do_du_ana && g_do_cdg); IR_CFG * cfg = init_cfg(oc); cfg->loop_analysis(oc); if (g_do_ssa && OPTC_pass_mgr(oc) != NULL) { IR_SSA_MGR * ssamgr = (IR_SSA_MGR*)OPTC_pass_mgr(oc)-> register_opt(OPT_SSA_MGR); IS_TRUE0(ssamgr); ssamgr->construction(oc, this); } init_aa(oc); init_du(oc); if (g_opt_level == NO_OPT) { return false; } return true; }
TSCfgInfo * findcfg(Oid id) { /* last used cfg */ if (CList.last_cfg && CList.last_cfg->id == id) return CList.last_cfg; /* already used cfg */ if (CList.len != 0) { TSCfgInfo key; key.id = id; CList.last_cfg = bsearch(&key, CList.list, CList.len, sizeof(TSCfgInfo), comparecfg); if (CList.last_cfg != NULL) return CList.last_cfg; } /* last chance */ if (CList.len == CList.reallen) { TSCfgInfo *tmp; int reallen = (CList.reallen) ? 2 * CList.reallen : 16; tmp = (TSCfgInfo *) realloc(CList.list, sizeof(TSCfgInfo) * reallen); if (!tmp) ts_error(ERROR, "No memory"); CList.reallen = reallen; CList.list = tmp; } init_cfg(id, &(CList.list[CList.len]) ); CList.last_cfg = &(CList.list[CList.len]); CList.len++; qsort(CList.list, CList.len, sizeof(TSCfgInfo), comparecfg); return findcfg(id); /* qsort changed order!! */ ; }
int main(int argc, char **argv) #endif { int err = 0; pthread_t streamer_pthread; #if(DAEMON) struct opt_s *opt = (struct opt_s *)opti; D("Starting thread from daemon"); #else LOG("Running in non-daemon mode\n"); struct opt_s *opt = malloc(sizeof(struct opt_s)); CHECK_ERR_NONNULL(opt, "opt malloc"); LOG("STREAMER: Reading parameters\n"); clear_and_default(opt, 1); err = parse_options(argc, argv, opt); if (err != 0) STREAMER_ERROR_EXIT; err = init_branches(opt); CHECK_ERR("init branches"); err = init_recp(opt); CHECK_ERR("init recpoints"); #ifdef HAVE_LIBCONFIG_H err = init_cfg(opt); //TODO: cfg destruction if (err != 0) { E("Error in cfg init"); STREAMER_ERROR_EXIT; } #endif //HAVE_LIBCONFIG_H err = init_rbufs(opt); CHECK_ERR("init rbufs"); #endif //DAEMON /* Check and set cfgs at this point */ //return -1; /* If we're sending stuff, check all the diskbranch members for the files they have */ /* Also updates the fileholders list to point the owners of files to correct drives */ #ifdef HAVE_LIBCONFIG_H if (opt->optbits & READMODE) { oper_to_all(opt->diskbranch, BRANCHOP_CHECK_FILES, (void *)opt); LOG ("For recording %s: %lu files were found out of %lu total. file index shows %ld files\n", opt->filename, opt->cumul_found, opt->cumul, afi_get_n_files(opt->fi)); } #endif //HAVE_LIBCONFIG_H /* Handle hostname etc */ /* TODO: Whats the best way that accepts any format? */ err = prep_streamer(opt); if (err != 0) { STREAMER_ERROR_EXIT; } if (opt->optbits & READMODE) LOG("STREAMER: In main, starting sending thread \n"); else LOG("STREAMER: In main, starting receiver thread \n"); #ifdef HAVE_LRT /* TCP streams start counting from accept and others from here */ if (!(opt->optbits & (CAPTURE_W_TCPSPLICE | CAPTURE_W_TCPSTREAM))) GETTIME(opt->starting_time); set_status_for_opt(opt, STATUS_RUNNING); err = pthread_create(&streamer_pthread, NULL, opt->streamer_ent->start, (void *)opt->streamer_ent); if (err != 0) { printf("ERROR; return code from pthread_create() is %d\n", err); STREAMER_ERROR_EXIT; } /* Other thread spawned so we can minimize our priority */ minimize_priority(); #ifdef TUNE_AFFINITY /* Caused some weird ass bugs and crashes so not used anymore NEVER */ /* Put the capture on the first core */ CPU_SET(0, &(opt->cpuset)); err = pthread_setaffinity_np(streamer_pthread, sizeof(cpu_set_t), &cpuset); if (err != 0) { E("Error: setting affinity: %d", err); } CPU_ZERO(&cpuset); #endif #endif { /* READMODE shuts itself down so we just go to pthread_join */ /* Check also that last_packet is 0. Else the thread should shut itself */ /* down */ if (!(opt->optbits & READMODE) && opt->last_packet == 0 && !(opt-> optbits & (CAPTURE_W_TCPSPLICE | CAPTURE_W_TCPSTREAM | CAPTURE_W_MULTISTREAM))) { TIMERTYPE now; GETTIME(now); while ((GETSECONDS(now) <= (GETSECONDS(opt->starting_time) + (long)opt->time)) && get_status_from_opt(opt) == STATUS_RUNNING) { sleep(1); GETTIME(now); } shutdown_thread(opt); pthread_mutex_lock(&(opt->membranch->branchlock)); pthread_cond_broadcast(&(opt->membranch->busysignal)); pthread_mutex_unlock(&(opt->membranch->branchlock)); } } err = pthread_join(streamer_pthread, NULL); if (err < 0) { printf("ERROR; return code from pthread_join() is %d\n", err); } else D("Streamer thread exit OK"); LOG("STREAMER: Threads finished. Getting stats for %s\n", opt->filename); GETTIME(opt->endtime); LOG("Blocking until owned buffers are released\n"); block_until_free(opt->membranch, opt); #if(DAEMON) LOG("Buffers finished\n"); if (get_status_from_opt(opt) != STATUS_STOPPED) { E("Thread didnt finish nicely with STATUS_STOPPED"); set_status_for_opt(opt, STATUS_FINISHED); } else set_status_for_opt(opt, STATUS_FINISHED); #else close_streamer(opt); #endif #if(DAEMON) D("Streamer thread exiting for %s", opt->filename); pthread_exit(NULL); #else close_opts(opt); STREAMER_EXIT; #endif }
int main(int argc, char *argv[]) { if(!init_cfg()) { fprintf(stderr, "Unable to open config file or invalid content in config file.\n"); exit(1); } parseopts(argc, argv, conf); if(conf->msg) { if(!open_producer()) { printf("Unable to contact Bluemote server!\n"); exit(1); } if(ipc_write(conf->device, strlen(conf->device))<=0) { printf("Unable to send message to Bluemote server!\n"); close_producer(); exit(1); } close_producer(); exit(0); } else { if(!get_lock()) { printf("Another instance of Bluemote already running!\n"); exit(1); } if(!open_consumer()) { printf("Unable to listen for messages!\n"); exit(1); } } strcpy(logfile, getenv("HOME")); strcat(logfile, BLUEMOTEDIR); strcat(logfile, LOGFILE); printf("Setting up signal handlers.\n"); logger("INIT", "Setting up signal handlers"); if(!init_signals()) { perror("init_signals()"); exit(1); } if(conf->daemon) { printf("Entering daemon mode.\n"); logger("INIT", "Entering daemon mode.\n"); if(daemon(TRUE, FALSE)==-1) { printf("Unable to enter daemon mode. Exiting.\n"); logger("ERROR", "Unable to enter daemon mode. Exiting.\n"); exit(1); } } while(TRUE) { closeport(); printf("Connecting to phone...\n"); logger("INIT", "Connecting to phone..."); while(openport(conf->device) == -1) { sprintf(buf,"Unable to connect to phone. Will retry after %d secs.",conf->retrysecs); logger("INIT", buf); sleep(conf->retrysecs); logger("INIT", "Retrying..."); } printf("Connected to phone.\n"); logger("INIT", "Connected to phone."); printf("Initialising the connection.\n"); logger("INIT", "Initialising the connection.\n"); if(!initport()) exit(1); printf("Waiting for commands from phone\n"); logger("INIT", "Waiting for commands from phone\n"); /* Not looping to take care of timeout because timeout is very unlikely and * this function is called again inside remote(). In the worst case, the I/O * commands for Connect event won't have any effect. */ if(init_mainmenu()==-1) continue; exec_event("Connect"); if(!manual) { exec_event("MoveIn"); } manual = FALSE; remote(); if(!manual) { exec_event("MoveOut"); } exec_event("Disconnect"); } return(0); }
int mod_init (void) { /********** * o allocate shared mem and init * o init configuration data * o init DB **********/ pmod_data = (mod_data *) shm_malloc (sizeof (mod_data)); if (!pmod_data) { LM_ERR ("Unable to allocate shared memory"); return -1; } memset (pmod_data, 0, sizeof (mod_data)); if (!init_cfg ()) { goto initerr; } if (!init_db ()) { goto initerr; } /********** * o bind to SL/TM/RR modules * o bind to RTPPROXY functions **********/ if (sl_load_api (pmod_data->psl)) { LM_ERR ("Unable to load SL module\n"); goto initerr; } if (load_tm_api (pmod_data->ptm)) { LM_ERR ("Unable to load TM module\n"); goto initerr; } if (load_rr_api (pmod_data->prr)) { LM_ERR ("Unable to load RR module\n"); goto initerr; } pmod_data->fn_rtp_answer = find_export ("rtpproxy_answer", 0, 0); if (!pmod_data->fn_rtp_answer) { LM_ERR ("Unable to load rtpproxy_answer\n"); goto initerr; } pmod_data->fn_rtp_offer = find_export ("rtpproxy_offer", 0, 0); if (!pmod_data->fn_rtp_offer) { LM_ERR ("Unable to load rtpproxy_offer\n"); goto initerr; } pmod_data->fn_rtp_stream_c = find_export ("rtpproxy_stream2uac", 2, 0); if (!pmod_data->fn_rtp_stream_c) { LM_ERR ("Unable to load rtpproxy_stream2uac\n"); goto initerr; } pmod_data->fn_rtp_stream_s = find_export ("rtpproxy_stream2uas", 2, 0); if (!pmod_data->fn_rtp_stream_s) { LM_ERR ("Unable to load rtpproxy_stream2uas\n"); goto initerr; } pmod_data->fn_rtp_destroy = find_export ("rtpproxy_destroy", 0, 0); if (!pmod_data->fn_rtp_destroy) { LM_ERR ("Unable to load rtpproxy_destroy\n"); goto initerr; } /********** * init MOH and call queue locks **********/ if (!mohq_lock_init (pmod_data->pmohq_lock)) { goto initerr; } if (!mohq_lock_init (pmod_data->pcall_lock)) { goto initerr; } return 0; /********** * o release shared mem * o exit with error **********/ initerr: if (pmod_data->mohq_cnt) { shm_free (pmod_data->pmohq_lst); } if (pmod_data->pcall_lock->plock) { mohq_lock_destroy (pmod_data->pcall_lock); } shm_free (pmod_data); pmod_data = NULL; return -1; }