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); } }
/** * Run an application according to 'app_dsc' * @param app_dsc pointer to an application descriptor * @param conf pointer to a lv_app_example_conf_t structure with configuration data or NULL if unused * @return pointer to the opened application or NULL if any error occurred */ static void my_app_run(lv_app_inst_t * app, void * conf) { /*Initialize the application*/ my_app_data_t * app_data = app->app_data; app_data->file_cnt = 0; app_data->path[0] = '\0'; app_data->fn[0] = '\0'; app_data->send_fn = 0; app_data->send_size = 0; app_data->send_crc = 0; app_data->chunk_size = LV_APP_FILES_CHUNK_DEF_SIZE; app_data->chunk_delay = LV_APP_FILES_CHUNK_DEF_TIME; app_data->send_in_prog = 0; app_data->send_task = ptask_create(send_task, LV_APP_FILES_CHUNK_DEF_TIME, PTASK_PRIO_OFF, app); }
int main(void) { int ret = 0, nc; int c; int key = 0; int part = PARTITIONED; // PARTITIONED, GLOBAL int sched = SCHED_FIFO; get_data(); init(); ret = select_prot(); if ( ret == -1 ) { allegro_exit(); return 0; } print_grid(ret); ptask_init(sched, part, ret); t_start = ptask_gettime(MILLI); set_sem_sezC(ret); nc = ptask_getnumcores(); textprintf_ex(screen, font, 480, 10, 7, BGC, "(NumCores = %d)", nc); int gen_id = ptask_create(gen, 100, 30, NOW); if (gen_id < 0) { printf("Could not create task gen\n"); exit(-1); } while (key != KEY_ESC) { if (keypressed()) { c = readkey(); key = c >> 8; } } pmux_destroy(&mx_sezNorm); pmux_destroy(&mx_sezA); pmux_destroy(&mx_sezB); allegro_exit(); return 0; }
int main(void) { int lev1, lev2; int c, key = 0; long x = 0; long t; get_data(); init(SCHED_FIFO, PCP); lev1 = LEV0 - 2; lev2 = LEV0 - 2 - DEX; int gen_id = ptask_create(gen, 100, 30, NOW); if (gen_id < 0) { printf("Could not create task gen\n"); exit(-1); } while (key != KEY_ESC) { if (keypressed()) { c = readkey(); key = c >> 8; } if (x < 640L) { t = ptask_gettime(MILLI); x = OFFSET + t/scale; pthread_mutex_lock(&mxa); line(screen, x, lev1, x, lev2, MAINCOL); pthread_mutex_unlock(&mxa); } } pmux_destroy(&mxa); pmux_destroy(&muxA); pmux_destroy(&muxB); allegro_exit(); return 0; }
VALUE rb_task_create(VALUE (*func)(VALUE *argv), int argc, ...) { va_list args; if (worker_thread_num > 0) { rb_task_t *task; VALUE *argv = xmalloc(sizeof(VALUE) * argc); VALUE obj; int i; obj = TypedData_Make_Struct(rb_cTask, rb_task_t, &task_data_type, task); /* setup argv */ va_init_list(args, argc); for (i=0; i<argc; i++) { argv[i] = va_arg(args, VALUE); } va_end(args); task->func = func; task->argc = argc; task->argv = argv; task->result = Qundef; task->ptask = ptask_create(task_dispatch_callback, task); ptask_dispatch(task->ptask); return obj; } else { /* Do it immediately */ int i; VALUE *argv = ALLOCA_N(VALUE, argc); va_init_list(args, argc); for (i=0; i<argc; i++) { argv[i] = va_arg(args, VALUE); } va_end(args); return (VALUE)func(argv); } }
/********************** * GLOBAL FUNCTIONS **********************/ void wifimng_init(void) { wifimng_state = WIFIMNG_STATE_IDLE; ptask_create(wifimng_task, 1000, PTASK_PRIO_LOW, NULL); }
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; }