void palla() { int i, col, dcol = 0; /* indice del task */ int x, y; /* coordinate grafiche pallina */ int ox, oy; /* vecchia posizione pallina */ int x0; /* posizione iniziale X pallina */ float vx, vy; /* velocità della pallina */ float t, tx; /* variabile temporale */ // float z, z0; /* posizione della pallina */ float dt; /* incremento temporale */ double a; /* variabile di appoggio */ // long j, k; i = ptask_get_index(); col = 2 + i % 14; y = oy = (TOP - L); x = ox = x0 = XMIN; a = 2. * G * (float)(TOP - L); vy = sqrt(a); vx = VELX; tx = 0.0; t = vy / G; dt = ptask_get_period(i, MILLI) / 100.; // removed, unless a specific activation from the main is done // wait_for_activation(); while (1) { x = x0 + vx * tx; y = BASE + vy * t - .5 * G * t * t; if (y < BASE) { t = 0.0; pthread_mutex_lock(&mxv); v0[i] = .9 * v0[i]; vy = v0[i]; pthread_mutex_unlock(&mxv); y = BASE + vy * t - .5 * G * t * t; } if (x > XMAX) { tx = 0.0; x0 = XMAX; vx = -vx; x = x0 + vx * tx; } if (x < XMIN) { tx = 0.0; x0 = XMIN; vx = -vx; x = x0 + vx * tx; } pthread_mutex_lock(&mxa); draw_ball(ox, YWIN - oy, BGC); draw_ball(x, YWIN - y, col); pthread_mutex_unlock(&mxa); oy = y; ox = x; t += dt; tx += dt; /* check for deadline miss */ if (ptask_deadline_miss()) { dcol = dcol % 15 + 1; pthread_mutex_lock(&mxa); rectfill(screen, 400, 50, 450, 70, dcol); pthread_mutex_unlock(&mxa); } ptask_wait_for_period(); } }
void task() { int x; long t; int i, k; int lev1, lev2, col; int at = 0; i = ptask_get_index(); lev1 = LEV0 + DLEV*i - 2; lev2 = LEV0 + DLEV*i - 2 - DEX; col = 1 + i%15; //wait_for_activation(); while (x < 640L) { //dl = at + ptask_get_deadline(i, MILLI); for (k=0; k<prtime[i]; k++) { t = ptask_gettime(MILLI); x = OFFSET + t/scale; pthread_mutex_lock(&mxa); line(screen, x, lev1, x, lev2, col); pthread_mutex_unlock(&mxa); while (ptask_gettime(MILLI) == t); } /*----------------------------------------------*/ /* Critical section guarded by muxA */ /*----------------------------------------------*/ if ((i != 2) && (i != 4)) { pthread_mutex_lock(&muxA); for (k=0; k<csa[i]; k++) { t = ptask_gettime(MILLI); x = OFFSET + t/scale; pthread_mutex_lock(&mxa); line(screen, x, lev1-1, x, lev2+1, CSCOLA); pthread_mutex_unlock(&mxa); while (ptask_gettime(MILLI) == t); } pthread_mutex_unlock(&muxA); } /*----------------------------------------------*/ if (i != 4) { for (k=0; k<prtime[i]; k++) { t = ptask_gettime(MILLI); x = OFFSET + t/scale; pthread_mutex_lock(&mxa); line(screen, x, lev1, x, lev2, col); pthread_mutex_unlock(&mxa); while (ptask_gettime(MILLI) == t); } } /*----------------------------------------------*/ /* Critical section guarded by muxB */ /*----------------------------------------------*/ if (i != 2) { pthread_mutex_lock(&muxB); for (k=0; k<csb[i]; k++) { t = ptask_gettime(MILLI); x = OFFSET + t/scale; pthread_mutex_lock(&mxa); line(screen, x, lev1-1, x, lev2+1, CSCOLB); pthread_mutex_unlock(&mxa); while (ptask_gettime(MILLI) == t); } pthread_mutex_unlock(&muxB); } /*----------------------------------------------*/ if (ptask_deadline_miss()) { // TO BE DONE //sprintf(s, "%d", task_dmiss(i)); //textout_ex(screen, font, s, OFFSET+dl/scale-4, lev1+8, 7, 0); } ptask_wait_for_period(); at = at + ptask_get_period(i,MILLI); } }