int MPIDI_nem_ckpt_init(void)
{
    int mpi_errno = MPI_SUCCESS;
    cr_callback_id_t cb_id;
    cr_client_id_t client_id;
    int ret;
    MPIDI_STATE_DECL(MPID_STATE_MPIDI_NEM_CKPT_INIT);

    MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_NEM_CKPT_INIT);

    if (!MPIR_CVAR_NEMESIS_ENABLE_CKPOINT)
        goto fn_exit;
    
    client_id = cr_init();
    MPIU_ERR_CHKANDJUMP(client_id < 0 && errno == ENOSYS, mpi_errno, MPI_ERR_OTHER, "**blcr_mod");

    cb_id = cr_register_callback(ckpt_cb, NULL, CR_THREAD_CONTEXT);
    MPIU_ERR_CHKANDJUMP1(cb_id == -1, mpi_errno, MPI_ERR_OTHER, "**intern", "**intern %s", MPIU_Strerror(errno));
    
    checkpointing = FALSE;
    current_wave = 0;

    ret = sem_init(&ckpt_sem, 0, 0);
    MPIU_ERR_CHKANDJUMP1(ret, mpi_errno, MPI_ERR_OTHER, "**sem_init", "**sem_init %s", MPIU_Strerror(errno));
    ret = sem_init(&cont_sem, 0, 0);
    MPIU_ERR_CHKANDJUMP1(ret, mpi_errno, MPI_ERR_OTHER, "**sem_init", "**sem_init %s", MPIU_Strerror(errno));

 fn_exit:
    MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_NEM_CKPT_INIT);
    return mpi_errno;
 fn_fail:
    goto fn_exit;
}
int opal_crs_blcr_module_init(void)
{
    void *crs_blcr_thread_callback_arg = NULL;
    void *crs_blcr_signal_callback_arg = NULL;

    opal_output_verbose(10, mca_crs_blcr_component.super.output_handle,
                        "crs:blcr: module_init()");

    my_pid = getpid();

    if( !opal_cr_is_tool ) {
        /*
         * Initialize BLCR
         */
        client_id = cr_init();
        if (0 > client_id) {
            opal_output(mca_crs_blcr_component.super.output_handle,
                        "Error: crs:blcr: module_init: cr_init failed (%d)\n", client_id);
            return OPAL_ERROR;
        }
    }

    blcr_restart_cmd    = strdup("cr_restart");
    blcr_checkpoint_cmd = strdup("cr_checkpoint");
    
    if( !opal_cr_is_tool ) {
        /* We need to make the lock and condition variable before
         * starting the thread, since the thread uses these vars.
         */
        OBJ_CONSTRUCT(&blcr_lock, opal_mutex_t);
        OBJ_CONSTRUCT(&blcr_cond, opal_condition_t);
        
        /*
         * Register the thread handler
         */
        cr_thread_callback_id = cr_register_callback(opal_crs_blcr_thread_callback,
                                                     crs_blcr_thread_callback_arg,
                                                     CR_THREAD_CONTEXT);
        /*
         * Register the signal handler
         *  - even though we do not use it
         */
        cr_signal_callback_id = cr_register_callback(opal_crs_blcr_signal_callback,
                                                     crs_blcr_signal_callback_arg,
                                                     CR_SIGNAL_CONTEXT);
    }

    /*
     * Now that we are done with init, set the state to running
     */
    blcr_current_state = OPAL_CRS_RUNNING;

    opal_output_verbose(10, mca_crs_blcr_component.super.output_handle,
                        "crs:blcr: module_init() --> Finished [%d]",
                        opal_cr_is_tool);
    
    return OPAL_SUCCESS;
}
int opal_crs_blcr_reg_thread(void)
{
    cr_client_id_t loc_client_id;

    /*
     * Initialize BLCR
     */
    loc_client_id = cr_init();
    if (0 > loc_client_id) {
        opal_output(mca_crs_blcr_component.super.output_handle,
                    "Error: crs:blcr: reg_thread: cr_init failed (%d)\n", loc_client_id);
        return OPAL_ERROR;
    }

    return OPAL_SUCCESS;
}
Exemple #4
0
// In CR_initialize(), put only code that must be called once
// because CR_initialize() won't be called at restart
// Code that needs to be run after each restart should go in CR_thread_start() or CR_Loop()
int CR_initialize()
{
    time_t tm;
    struct tm *stm;

    int rv = pthread_mutex_init( &cr_state_mutex, NULL );
    if ( rv != 0 ) {
        PRINT_ERROR_ERRNO( "pthread_mutex_init() failed", errno );
        return -1;
    }

    CR_state_transition( CR_INIT );

    cr_client_id_t cr_id = cr_init();
    if (cr_id < 0) {
        PRINT_ERROR("BLCR call cr_init() failed\n");
        return -2;
    }

    if (cr_register_callback(CR_Callback, (void *) NULL, CR_THREAD_CONTEXT) == -1) {
        PRINT_ERROR("BLCR call cr_register_callback() failed with error %d: %s\n", errno, cr_strerror(errno));
        return -3;
    }

    strncpy(ckpt_filename, DEFAULT_CHECKPOINT_FILENAME, CR_MAX_FILENAME);

    tm = time(NULL);
    if ((time_t) tm == -1) {
        PRINT_ERROR("time() failed\n");
        return -4;
    }

    stm = localtime(&tm);
    if (!stm) {
        PRINT_ERROR("localtime() failed\n");
        return -5;
    }

    snprintf(sessionid, CR_SESSION_MAX, "%d%d%d%d%d", stm->tm_yday, stm->tm_hour, stm->tm_min, stm->tm_sec, getpid());
    sessionid[CR_SESSION_MAX - 1] = '\0';

    return 0;
}
Exemple #5
0
int main()
{
	char string[256] = {0};

	fgets(string,256,stdin);

	cr_init("derpderpderpderp","AAAAAAAAAAAAAAAA");

	printf("Plaintext before: %s\n",string);

	cr_encrypt(string);	
	cr_decrypt(string);

	printf("Plaintext after : %s\n",string);


	cr_close();

	return 0;
}
void setup(void) {
	int rc;
	rc = cr_init("../../../config/xml/core_config.xml");
	fail_if(rc == 0, "config reader could not be initialized");
	
	rc = logger_init();
	fail_if(rc == 0, "logger could not be initialized");
	
	//init thread management
	rc = tm_init();
	if (rc == 0) {
		// ERROR
		LOG_ERROR(TEST_SIPSTACK_PREFIX "Thread management could not be initialized.\n");
	}else {
		LOG_DEBUG(TEST_SIPSTACK_PREFIX "Thread management  initialized.\n");
	}

	//init event queue
	event_queue = queue_create_queue(30);
	LOG_DEBUG(TEST_SIPSTACK_PREFIX "Event queue created.");
}
Exemple #7
0
Fichier : Mcr.c Projet : huahbo/src
int main(int argc, char* argv[])
{
    int nr, nc, nx, niter;
    float *x, tol;
    sf_file row_in, col_in, row_out, col_out;

    sf_init(argc,argv);
    row_in = sf_input("in");
    col_in = sf_input("col_in");

    row_out = sf_output("out");
    col_out = sf_output("col_out");

    if (!sf_histint(row_in,"n1",&nr)) sf_error("No n1= in input");
    if (!sf_histint(col_in,"n1",&nc)) sf_error("No n1= in input");

    nx = nr+nc;
    x = sf_floatalloc(nx);

    /* read input - B'd */
    sf_floatread(x,nr,row_in);
    sf_floatread(x+nr,nc,col_in);

    if (!sf_getint("niter",&niter)) niter=10; /* number of iterations */
    if (!sf_getfloat("tol",&tol)) tol=0.0f;   /* CG tolerance */

    /* Run PCG */
    cr_init(nr,nc);
    conjgrad(cr_apply,nx,x,x,x,niter,tol);
    
    /* write output */
    sf_floatwrite(x,nr,row_out);
    sf_floatwrite(x+nr,nc,col_out);

    exit(0);
}
Exemple #8
0
HYD_status HYDT_ckpoint_blcr_init(void)
{
    HYD_status status = HYD_SUCCESS;
    int rc;
    cr_client_id_t client_id;
    cr_callback_id_t callback_id;

    HYDU_FUNC_ENTER();

    client_id = (int) cr_init();
    if (client_id < 0)
        goto fn_fail;

    callback_id = cr_register_callback(my_callback, &rc, CR_SIGNAL_CONTEXT);
    if (callback_id < 0)
        goto fn_fail;

  fn_exit:
    HYDU_FUNC_EXIT();
    return status;

  fn_fail:
    goto fn_exit;
}
Exemple #9
0
int
main(int argc, char **argv)
{
	int debug_level, sig, srun_fd;
	struct sigaction sa;
	log_options_t logopt = LOG_OPTS_STDERR_ONLY;
	struct sockaddr_un ca;
	unsigned int ca_len = sizeof(ca);

	atexit(remove_listen_socket);

	/* copied from srun */
	debug_level = _slurm_debug_env_val();
	logopt.stderr_level += debug_level;
	log_init(xbasename(argv[0]), logopt, 0, NULL);

	if (init_srun_argv(argc, argv)) {
		fatal("failed to initialize arguments for running srun");
	}

	if ((cr_id = cr_init()) < 0) {
		fatal("failed to initialize libcr: %s", cr_strerror(errno));
	}
	(void)cr_register_callback(cr_callback, NULL, CR_THREAD_CONTEXT);

	/* forward signals. copied from cr_restart */
	sa.sa_sigaction = signal_child;
	sa.sa_flags = SA_RESTART | SA_NODEFER | SA_SIGINFO;
	sigemptyset(&sa.sa_mask);
	for (sig = 0;  sig < _NSIG; sig ++) {
		if (sig == SIGSTOP ||
		    sig == SIGKILL ||
		    sig == SIGCHLD)
			continue;
		sigaction(sig, &sa, NULL);
	}
	sa.sa_sigaction = on_child_exit;
	sa.sa_flags = SA_RESTART | SA_SIGINFO | SA_NOCLDSTOP;
	sigaction(SIGCHLD, &sa, NULL);

	cr_enter_cs(cr_id); /* BEGIN CS: avoid race condition of whether srun is forked */
	if ( fork_exec_srun() ) {
		fatal("failed fork/exec/wait srun");
	}
	cr_leave_cs(cr_id); /* END CS */

	while (1) {
		pthread_mutex_lock(&step_launch_mutex);
		while (step_launched) {
			/* just avoid busy waiting */
			pthread_cond_wait(&step_launch_cond,
					  &step_launch_mutex);
		}
		pthread_mutex_unlock(&step_launch_mutex);

		if (_wait_for_srun_connect() < 0)
			continue;

		cr_enter_cs(cr_id); /* BEGIN CS: checkpoint(callback) will be delayed */

		srun_fd = accept(listen_fd, (struct sockaddr*)&ca, &ca_len);
		if (srun_fd < 0) {
			/* restarted before enter CS. socket will not be restored */
			if (errno == EBADF) {
				cr_leave_cs(cr_id);
				continue;
			} else {
				fatal("failed to accept socket: %m");
			}
		}

		_read_info_from_srun(srun_fd);
		close(srun_fd);

		step_launched = 1;
		debug2("step launched");

		cr_leave_cs(cr_id); /* END CS */
	}

	return 0;
}
int init(int ac, char **av)
{
    int i;
    int openlog_failed = 0, openlog_errno = 0;
    int started_from_term = isatty(0) && isatty(1) && isatty(2);

    /* Imported from main.c */
    extern void sighandler(int signum);


    /* Set file creation mask and group ID. */
#if defined(DEFUMASK) && HAVE_UMASK
    umask(DEFUMASK);
#endif
    if (set_group() < 0)
	return -1;
    
    /* Parse command line for -dir option. */
    parse_dir_options(ac, av);

    /* Chdir to Services data directory. */
    if (chdir(services_dir) < 0) {
	fprintf(stderr, "chdir(%s): %s\n", services_dir, strerror(errno));
	return -1;
    }

    /* Open logfile, and complain if we didn't. */
    if (open_log() < 0) {
	openlog_errno = errno;
	if (started_from_term) {
	    fprintf(stderr, "ATENCION: No puedo abrir el archivo de log %s: %s\n",
			log_filename, strerror(errno));
	} else {
	    openlog_failed = 1;
	}
    }

    /* Read configuration file; exit if there are problems. */
    if (!read_config())
	return -1;

    /* Parse all remaining command-line options. */
    parse_options(ac, av);

    /* Detach ourselves if requested. */
    if (!nofork) {
	if ((i = fork()) < 0) {
	    perror("fork()");
	    return -1;
	} else if (i != 0) {
	    exit(0);
	}
	if (started_from_term) {
	    close(0);
	    close(1);
	    close(2);
	}
	if (setpgid(0, 0) < 0) {
	    perror("setpgid()");
	    return -1;
	}
    }

    /* Write our PID to the PID file. */
    write_pidfile();

    /* Announce ourselves to the logfile. */
    if (debug || readonly || skeleton) {
	log("euskalirc-services-bdd %s (compilados para %s) iniciados (opciones:%s%s%s)",
		version_number, version_protocol,
		debug ? " debug" : "", readonly ? " readonly" : "",
		skeleton ? " skeleton" : "");
    } else {
	log("euskalirc-services-bdd %s (compilados para %s) iniciados.",
		version_number, version_protocol);
    }
    start_time = time(NULL);

    /* If in read-only mode, close the logfile again. */
    if (readonly)
	close_log();

    /* Set signal handlers.  Catch certain signals to let us do things or
     * panic as necessary, and ignore all others.
     */
#ifdef NSIG
    for (i = 1; i <= NSIG; i++)
#else
    for (i = 1; i <= 32; i++)
#endif
	signal(i, SIG_IGN);

    signal(SIGINT, sighandler);
    signal(SIGTERM, sighandler);
    signal(SIGQUIT, sighandler);
    signal(SIGSEGV, sighandler);
    signal(SIGBUS, sighandler);
    signal(SIGQUIT, sighandler);
    signal(SIGHUP, sighandler);
    signal(SIGILL, sighandler);
    signal(SIGTRAP, sighandler);
#ifdef SIGIOT
    signal(SIGIOT, sighandler);
#endif
    signal(SIGFPE, sighandler);

    signal(SIGUSR1, sighandler);  /* This is our "out-of-memory" panic switch */

    /* Initialize multi-language support */
    lang_init();
    if (debug)
	log("debug: Cargando lenguajes");

    /* Initialiize subservices */
    ns_init();
    cs_init();
#ifdef CREGSERV
    cr_init();
#endif    
    ms_init();
    os_init();
    load_spam();
    load_ipv();   /*leyendo datos de frases*/
    /* Load up databases */
    if (!skeleton) {
	load_ns_dbase();
	if (debug)
	    log("debug: Cargando la DB de %s (1/7)", s_NickServ);
	load_cs_dbase();
	if (debug)
	    log("debug: Cargando la DB de %s (2/7)", s_ChanServ);
	    load_cr_dbase();
	if (debug)
	    log("debug: Cargando la DB de %s (3/7)", s_CregServ);
    }
	
    load_os_dbase();
    if (debug)
	log("debug: Cargando la DB de %s (4/7)", s_OperServ);
    load_akill();
    if (debug)
	log("debug: Cargando la DB de GLINES (5/7)");
    load_news();
    if (debug)
	log("debug: Cargando la DB de NOTICIAS (6/7)");
   
    if (debug)
	log("debug: Cargando la DB de SPAM (7/7)");
    load_cr_dbase();
    load_ipv();
    log("Cargadas las bases de datos");

    /* Connect to the remote server */
    servsock = conn(RemoteServer, RemotePort, LocalHost, LocalPort);
    if (servsock < 0)
	fatal_perror("No puedo conectar al servidor");
    send_cmd(NULL, "PASS :%s", RemotePassword);
#ifdef IRC_UNDERNET_P09
    send_cmd(NULL, "SERVER %s 1 %lu %lu P09 :%s",
             ServerName, start_time, start_time, ServerDesc);
#else /* IRC_UNDERNET_P10 */
    send_cmd(NULL, "SERVER %s %d 0 %ld J10 %cD] :%s",
             ServerName, 2, start_time, convert2y[ServerNumerico], ServerDesc); 
#endif
    sgets2(inbuf, sizeof(inbuf), servsock);
    if (strnicmp(inbuf, "ERROR", 5) == 0) {
	/* Close server socket first to stop wallops, since the other
	 * server doesn't want to listen to us anyway */
	disconn(servsock);
	servsock = -1;
	fatal("El servidor ha devuelto: %s", inbuf);
    }


    /* Announce a logfile error if there was one */
    if (openlog_failed) {
	canalopers(NULL, "4ATENCION: No puedo abrir el fichero de log: 12%s",
		strerror(openlog_errno));
    }

    /* Bring in our pseudo-clients */
    introduce_user(NULL);

    send_cmd(ServerName, "SETTIME %lu", time(NULL));
#if HAVE_ALLWILD_NOTICE
    send_cmd(s_OperServ, "NOTICE $*.%s :Establecidos los servicios de la RED.", NETWORK_DOMAIN);
    
#else
# ifdef NETWORK_DOMAIN
    send_cmd(s_OperServ, "NOTICE $*.%s :Establecidos los servicios de la RED.", NETWORK_DOMAIN);
# else
     Go through all common top-level domains.  If you have others,
     * add them here.
     
    send_cmd(s_OperServ, "NOTICE $*.es :Establecidos los servicios de la RED.");
    send_cmd(s_OperServ, "NOTICE $*.com :Establecidos los servicios de la RED.");
    send_cmd(s_OperServ, "NOTICE $*.net :Establecidos los servicios de la RED.");
    send_cmd(s_OperServ, "NOTICE $*.org :Establecidos los servicios de la RED.");    
    send_cmd(s_OperServ, "NOTICE $*.edu :Establecidos los servicios de la RED.");
    send_cmd(s_OperServ, "NOTICE $*.tk :Establecidos los servicios de la RED.");
# endif
#endif
        
    join_chanserv();
      

    /* Success! */
    return 0;
}
Exemple #11
0
int main(int argc, char* argv[])
{
	uint32_t tmp = 0;
	uint32_t volatile timing_barrier = 0;

	// we explicitly create the array of CR_CONTEXT structures
	CR_CONTEXT context_array[CONTEXT_ARRAY_CNT];

	// register a cleanup function
	atexit(cleanup);

	// some signal handlers
	if (signal(SIGFPE, signal_handler) == SIG_ERR) {
		perror("An error occured while setting the SIGFPE signal handler.\n");
	} else if (signal( SIGILL, signal_handler) == SIG_ERR) {
		perror("An error occured while setting the SIGILL signal handler.\n");
	} else if (signal( SIGINT, signal_handler) == SIG_ERR) {
		perror("An error occured while setting the SIGINT signal handler.\n");
	} else if (signal( SIGSEGV, signal_handler) == SIG_ERR) {
		perror("An error occured while setting the SIGSEGV signal handler.\n");
	}

	// 1. init the cr library
	assert(((sizeof(context_array) / sizeof(CR_CONTEXT)) == CONTEXT_ARRAY_CNT)
			&& "context_array size mismatch!\n");

	cr_init(context_array, CONTEXT_ARRAY_CNT);

	// 2. register the threads
	cr_register_thread(Thread_A);
	cr_register_thread(Thread_B);
	cr_register_thread(Thread_C);
	cr_register_thread(Thread_D);

	//--------------------------------------------------------------------------
	//-------------------- Simulated ISR Thread Setup --------------------------
	pthread_attr_init(&isr_thread_attr);

	pthread_attr_setschedpolicy(&isr_thread_attr, SCHED_RR);

	pthread_attr_setstacksize(&isr_thread_attr, PTHREAD_STACK_MIN);

// XXX: the scheduling priority could be set here

	pthread_attr_setschedparam(&isr_thread_attr, &isr_thread_sched);

	isr_thread_run = true;

	tmp = pthread_create(&isr_thread_id, &isr_thread_attr, isr_thread, 0);

	assert((tmp == 0) && "pthread_create failed!");

	timing_barrier = 1000;

	// Code block to stop the compiler from messing with the code
	{
		while(timing_barrier--)
			/* no code */ ;
	}
	//--------------------------------------------------------------------------

	// 3. bootstrap the system
	CR_START(cr_idle);

	return EXIT_SUCCESS;
}
Exemple #12
0
int main(

    int   argc,
    char *argv[])

{
    struct timeval timeout;
    int i;
    int maxfd;
    int main_sock_out = 3;
    int main_sock_err = 4;
    int n;
    int newsock;
    pid_t parent;
    fd_set selset;

    struct routem *routem;

#ifdef ENABLE_BLCR
    if (cr_init() < 0)
    {
        perror("Failed to initialize BLCR.");
        exit(5);
    }

    (void)cr_register_callback(demux_callback, NULL, CR_THREAD_CONTEXT);
#endif /* ENABLE_BLCR */

    parent = getppid();

    /* disable cookie search - PW - mpiexec patch */

    /*
    cookie = getenv("PBS_JOBCOOKIE");

    if (cookie == 0)
      {
      fprintf(stderr, "%s: no PBS_JOBCOOKIE found in the env\n",
        argv[0]);

      exit(3);
      }

    #ifdef DEBUG
    printf("Cookie found in environment: %s\n",
      cookie);
    #endif
    */

    if((maxfd = sysconf(_SC_OPEN_MAX)) < 0)
    {
        perror("unexpected return from sysconf.");

        exit(5);
    }

    routem = (struct routem *)calloc(maxfd, sizeof(struct routem));

    if (routem == NULL)
    {
        perror("cannot alloc memory");

        exit(5);
    }

    for (i = 0; i < maxfd; ++i)
    {
        routem[i].r_where = invalid;
        routem[i].r_nl    = 1;
    }

    routem[main_sock_out].r_where = new_out;
    routem[main_sock_err].r_where = new_err;

    FD_ZERO(&readset);
    FD_SET(main_sock_out, &readset);
    FD_SET(main_sock_err, &readset);

    if (listen(main_sock_out, TORQUE_LISTENQUEUE) < 0)
    {
        perror("listen on out");

        exit(5);
    }

    if (listen(main_sock_err, TORQUE_LISTENQUEUE) < 0)
    {
        perror("listen on err");

        exit(5);
    }

    while (1)
    {
        selset = readset;
        timeout.tv_usec = 0;
        timeout.tv_sec  = 10;

        n = select(FD_SETSIZE, &selset, (fd_set *)0, (fd_set *)0, &timeout);

        if (n == -1)
        {
            if (errno == EINTR)
            {
                n = 0;
            }
            else
            {
                fprintf(stderr, "%s: select failed\n",
                        argv[0]);

                exit(1);
            }
        }
        else if (n == 0)
        {
            /* NOTE:  on TRU64, init process does not have pid==1 */

            if (getppid() != parent)
            {
#ifdef DEBUG
                fprintf(stderr, "%s: Parent has gone, and so will I\n",
                        argv[0]);
#endif /* DEBUG */

                break;
            }
        }    /* END else if (n == 0) */

        for (i = 0; (n != 0) && (i < maxfd); ++i)
        {
            if (FD_ISSET(i, &selset))
            {
                /* this socket has data */
                n--;

                switch ((routem + i)->r_where)
                {

                case new_out:

                case new_err:

                    newsock = accept(i, 0, 0);

                    (routem + newsock)->r_where = (routem + i)->r_where == new_out ?
                                                  old_out :
                                                  old_err;

                    FD_SET(newsock, &readset);

                    break;

                case old_out:

                case old_err:

                    readit(i, routem + i);

                    break;

                default:

                    fprintf(stderr, "%s: internal error\n",
                            argv[0]);

                    exit(2);

                    /*NOTREACHED*/

                    break;
                }
            }
        }
    }    /* END while(1) */

    return(0);
}  /* END main() */
int fase3_init() {
	// Guarda qual texto do file queremos utilizar;
	int text_pos, resultado_desafio;
	// Aloca os desafios desta fase.
	int v[15];

	// Cor para limpar a tela
	ALLEGRO_COLOR clean_color;

	// Imagem de quem está falando com o jogador;
	ALLEGRO_BITMAP *speaker;

	// Struct que controla o desafio
	challenger_rule cr;	
	// Inicializa a struct dos desafios
	cr_init(&cr);
	
	// Define a cor para limpar a tela (preto), limpa e adiciona o background.
 	clean_color = al_map_rgb(0, 0, 0);
    al_clear_to_color(clean_color);
    al_draw_bitmap(im_bg, 0, 0, 0);

    // Define as cartas a serem desenhadas.
    cr.prog = 3;
    cr.cond = 3;
    cr.act = 3;

    draw_prog_cards(cr);    
    draw_conditional_cards(cr);
    draw_action_cards(cr);
    al_flip_display();

	text_pos = 0;
    speaker = im_tutor;
    draw_text(text, text_pos, speaker);

    cr.prog = 3;
    cr.cond = 4;
    cr.act = 3;

    draw_prog_cards(cr);    
    draw_conditional_cards(cr);
    draw_action_cards(cr);
    al_flip_display();

	text_pos = 1;
    draw_text(text, text_pos, speaker);

	text_pos = 2;
    draw_text(text, text_pos, speaker);

    cr.prog = 3;
    cr.cond = 4;
    cr.act = 5;

    draw_prog_cards(cr);    
    draw_conditional_cards(cr);
    draw_action_cards(cr);
    al_flip_display();

	text_pos = 3;
    draw_text(text, text_pos, speaker);

	text_pos = 4;
    draw_text(text, text_pos, speaker);

	text_pos = 5;
    draw_text(text, text_pos, speaker);

    // Desafio da gosminha 1.
	text_pos = 6;
    speaker = im_mon_set[4];
    draw_text(text, text_pos, speaker);

    desafio_gosma1(v);
    transferir_desafio(&cr, v);
    resultado_desafio = create_desafio(cr);

    if (resultado_desafio <= 0) {
        resultado_desafio = show_try_again_dialog("Desafio da Gosma");
        if (resultado_desafio == 1) {
            return 0;
        } else {
            return resultado_desafio;
        }
    }

	text_pos = 7;
    speaker = im_tutor;
    draw_text(text, text_pos, speaker);

    // Desafio da gosminha 2.
	text_pos = 8;
    speaker = im_mon_set[4];
    draw_text(text, text_pos, speaker);

    desafio_gosma2(v);
    transferir_desafio(&cr, v);
    resultado_desafio = create_desafio(cr);

    if (resultado_desafio <= 0) {
        resultado_desafio = show_try_again_dialog("Desafio das Gosmas");
        if (resultado_desafio == 1) {
            return 0;
        } else {
            return resultado_desafio;
        }
    }

	text_pos = 9;
    speaker = im_tutor;
    draw_text(text, text_pos, speaker);

	text_pos = 10;
    draw_text(text, text_pos, speaker);

	text_pos = 11;
    draw_text(text, text_pos, speaker);

    // Desafio do fantasma
	text_pos = 12;
    speaker = im_boss;
    draw_text(text, text_pos, speaker);

    desafio_fantasma(v);
    transferir_desafio(&cr, v);
    resultado_desafio = create_desafio(cr);

    if (resultado_desafio <= 0) {
        resultado_desafio = show_try_again_dialog("Desafio do Fantasma");
        if (resultado_desafio == 1) {
            return 0;
        } else {
            return resultado_desafio;
        }
    }

	text_pos = 13;
    speaker = im_tutor;
    draw_text(text, text_pos, speaker);

	return 1;
}
Exemple #14
0
int opal_crs_blcr_module_init(void)
{
    void *crs_blcr_thread_callback_arg = NULL;
    void *crs_blcr_signal_callback_arg = NULL;

    opal_output_verbose(10, mca_crs_blcr_component.super.output_handle,
                        "crs:blcr: module_init()");

    blcr_restart_cmd    = strdup("cr_restart");
    blcr_checkpoint_cmd = strdup("cr_checkpoint");

    my_pid = getpid();

    if( !opal_cr_is_tool ) {
        /* We need to make the lock and condition variable before
         * starting the thread, since the thread uses these vars.
         */
        OBJ_CONSTRUCT(&blcr_lock, opal_mutex_t);
        OBJ_CONSTRUCT(&blcr_cond, opal_condition_t);

        /*
         * Initialize BLCR
         */
        client_id = cr_init();
        if (0 > client_id) {
            opal_output(mca_crs_blcr_component.super.output_handle,
                        "Error: crs:blcr: module_init: cr_init failed (%d)\n", client_id);
            return OPAL_ERROR;
        }
    }

#if OPAL_ENABLE_CRDEBUG == 1
    blcr_crdebug_refreshed_env = false;
#endif

    blcr_restart_cmd    = strdup("cr_restart");
    blcr_checkpoint_cmd = strdup("cr_checkpoint");

    if( !opal_cr_is_tool ) {
        /*
         * Register the thread handler
         */
        cr_thread_callback_id = cr_register_callback(opal_crs_blcr_thread_callback,
                                                     crs_blcr_thread_callback_arg,
                                                     CR_THREAD_CONTEXT);
        /*
         * Register the signal handler
         *  - even though we do not use it
         */
        cr_signal_callback_id = cr_register_callback(opal_crs_blcr_signal_callback,
                                                     crs_blcr_signal_callback_arg,
                                                     CR_SIGNAL_CONTEXT);

#if OPAL_ENABLE_CRDEBUG == 1
        /*
         * Checkpoint/restart enabled debugging hooks
         *  "NO_CALLBACKS"   -> non-MPI threads
         *  "SIGNAL_CONTEXT" -> MPI threads
         *  "THREAD_CONTEXT" -> BLCR threads
         */
        cr_register_hook(CR_HOOK_CONT_NO_CALLBACKS,   MPIR_checkpoint_debugger_crs_hook);
        cr_register_hook(CR_HOOK_CONT_SIGNAL_CONTEXT, MPIR_checkpoint_debugger_crs_hook);

        cr_register_hook(CR_HOOK_RSTRT_NO_CALLBACKS,   MPIR_checkpoint_debugger_crs_hook);
        cr_register_hook(CR_HOOK_RSTRT_SIGNAL_CONTEXT, MPIR_checkpoint_debugger_crs_hook);
#endif
    }

    /*
     * Now that we are done with init, set the state to running
     */
    blcr_current_state = OPAL_CRS_RUNNING;

    opal_output_verbose(10, mca_crs_blcr_component.super.output_handle,
                        "crs:blcr: module_init() --> Finished [%d]",
                        opal_cr_is_tool);

    return OPAL_SUCCESS;
}