示例#1
0
void myperiodic() {
    int i;
    for (i = 0; i < 4; i++) {
        printf("Periodic task, %d\n", i);
        cp++;
        ptask_activate(aperiodic_id);
        ptask_wait_for_period();
    }
}
示例#2
0
文件: pcp.c 项目: JoKeRGreGre/PJI
void	gen()
{
    int	i, j; 

    for (i=1; i<nt; i++) {
	j = ptask_create(task, period[i], prio[i], DEFERRED);
	if (j < 0) ptask_syserror("gen()", "error in creating task");
    }

    for (i=1; i<nt; i++) {
	ptask_activate(i);
    }
}
示例#3
0
void activ_aper_task()
{
    int task_to_activate = *((int*) ptask_get_argument());
    int i = 0;
    while(1) {
        if (i%3 == 0) work_for(15, MILLI);
        else work_for(5, MILLI);
        
        if (i%2 == 0) ptask_activate(task_to_activate);
        
        i++;
        ptask_wait_for_period();
    }
}
示例#4
0
int	main(void)
{
	  int 	unit = MILLI;
	  int	i, id, k;
	  int	c;						/* character from keyboard	*/
	  int   ntasks 	= 0;        	/* total number of activated tasks*/
	  int 	ret		= 0;
	  int 	tipo_prio = PRIO_EQUAL;
	  int 	sched 	= SCHED_RR;
	  int 	part	= GLOBAL;
	  int 	prot 	= NO_PROTOCOL;
	  int 	test 	= TASK_FUN;
	  int 	modeACT = MOD_NOW;		/* {MOD_NOW=0, MOD_DEF_OFFSET=1, MOD_DEF_NO_OFFS = 2} */
	  int   act_flag = NOW;

	  init(TASK_FUN);

	  int 	num_tasks = NUM_T_TEST;
	  int 	priority[num_tasks];
	  ptime v_offset[num_tasks];	/* time offset vector */

	  for(i = 0; i < num_tasks; i++) v_offset[i] = 0;

	  modeACT = select_act (v_offset, num_tasks); // {MOD_NOW=0, MOD_DEF_OFFSET=1, MOD_DEF_NO_OFFS = 2}
	  if ( modeACT == -1 ) {
		  allegro_exit();
	   	  return 0;
	   }

	   ptask_init(sched, part, prot);

	   /* Time reference for timeoffset */
	   time_t0 = ptask_gettime(MILLI);
	   ptime time_tmp;

	   if(modeACT == 0) {	// {MOD_NOW=0, MOD_DEF_OFFSET=1, MOD_DEF_NO_OFFS = 2}
		   act_flag = NOW;
	   }
	   else {
		   act_flag = DEFERRED;
	   }

	   init_vettore_prio(tipo_prio, priority, num_tasks);

	   draw_system_info(sched, part, prot, modeACT, tipo_prio, test, false);

	   draw_Timetask_info(modeACT);

	   pthread_mutex_lock(&mxa);
	   textprintf_ex(screen, font, 2, 25 + 15, FGC, BGC, " Time reference t0 = %ld (time creation/visualization of this screen)", time_t0);
	   pthread_mutex_unlock(&mxa);
	   const char* str_offset = "Time offset(ms) inseriti = ";

	   /* Creation of aperiodic task */
	   for ( i = 0; i < num_tasks; i++) {

	    	if (modeACT != MOD_DEF_OFFSET) {

	    		/* MODE WITHOUT OFFSET */
	    		time_tmp = ptask_gettime(MILLI);
	    		if(act_flag == NOW) {
	    			pthread_mutex_lock(&mxa);
	    			textprintf_ex(screen, font, X_LINE_VERT0 + 5, Y_TIMES + i * ALT_RIGA, FGC, BGC, "%ld            ", time_tmp);
	    			pthread_mutex_unlock(&mxa);
	    		}
	    		id = ptask_create(periodicLine_testSystemTask, PER, priority[i], act_flag);
	    	}
	    	else {
	    			/* MODE WITH OFFSET */
	    			time_tmp = ptask_gettime(MILLI);
	    			pthread_mutex_lock(&mxa);
	    			textprintf_ex(screen, font, (X_LINE_VERT0 + X_LINE_VERT1)/2, Y_TIMES + i * ALT_RIGA, FGC, BGC, "-");
	    			pthread_mutex_unlock(&mxa);
	    			id = ptask_create(periodicLine_testSystemTaskOFFSET, PER, priority[i], act_flag);
	    			printf("act_flag = %d, id = %d, v_offset[%d] = %ld\n", act_flag, id+1, id, v_offset[id]);
	    			ret = ptask_activate_at(id, v_offset[i]);

	    			if (ret != -1) {
	    				draw_activation (ntasks, i, priority[i], false);
	    				ntasks++;
	    				if (i == 0) {
	    					pthread_mutex_lock(&mxa);
	    					textout_ex(screen, font, str_offset, XMIN, BASE1 + 2 * ALT_RIGA, FGC, 0);
	    					pthread_mutex_unlock(&mxa);
	    				}
	    				pthread_mutex_lock(&mxa);
	    				textprintf_ex(screen, font, XMIN + (strlen(str_offset)+i*(NUM_CIF_OFFSET))*PIXEL_CHAR, BASE1 + 2 * ALT_RIGA,FGC, BGC, "%ld", v_offset[i]);
	    				pthread_mutex_unlock(&mxa);
	    			}
	    			else fprintf(stderr, "Task %d non può essere attivato o già avviato!!!\n", i+1);

	    	}
	       	if (id != -1) {
	       		char* temp = " e attivato!\n";
	       		if(act_flag == DEFERRED) {
	       			temp = "!\n";
	       		}
	       		printf("Task %d creato%s", id+1, temp);
	       	}
	       	else {
	       	    allegro_exit();
	       	    printf("Errore nella creazione(o anche attivazione NOW) del task!\n");
	       	    exit(-1);
	       	}
	   }

	   do {

		   	k = 0;
	   	   	if (keypressed()) {
	   	   		c = readkey();
	   	   		k = c >> 8;
	   	   	}

		   if ((k >= KEY_1) && (k <= KEY_0 + num_tasks) && (modeACT != MOD_DEF_OFFSET)) {

			   id = k - KEY_0 - 1;
			   time_tmp = ptask_gettime(unit);
			   ret = ptask_activate(id);

			   if (ret != -1) {
				   printf("Task %d attivato\n", id);
				   pthread_mutex_lock(&mxa);
				   textprintf_ex(screen, font, X_LINE_VERT0 + 5, Y_TIMES + (id) * ALT_RIGA,
						   FGC, BGC, "%ld            ", time_tmp);
				   pthread_mutex_unlock(&mxa);
				   draw_activation (ntasks, id, priority[id], false);
				   ntasks++;
			   }
			   else{

				   printf("Task %d non può essere attivato o già avviato!!!\n", id);
				   pthread_mutex_lock(&mxa);
				   textprintf_ex(screen, font, X_LINE_VERT0 + 5, Y_TIMES + id * ALT_RIGA,FGC, BGC, "T%d: Gia' attivo!   ", id);
				   pthread_mutex_unlock(&mxa);
			   }
		   }

	   } while (k != KEY_ESC);
	   allegro_exit();
	   return 0;
}