예제 #1
0
double UtilObject::cpuUsage() {
	static double percent = 0.0;
	static quint64 ptime1 = processTime(), stime1 = systemTime();
	const quint64 ptime2 = processTime();
	static constexpr quint64 th = 10000;
	if (ptime2 > ptime1 + th) {
		const quint64 stime2 = systemTime();
		if (stime2 > stime1 + th) {
			percent = (double)(ptime2 - ptime1)/(double)(stime2 - stime1)*100.0;
			ptime1 = ptime2; stime1 = stime2;
		}
	}
	return percent;
}
bool WLEMMCommandProcessor::process( WLEMMCommand::SPtr cmdIn )
{
    bool succes;
    switch( cmdIn->getCommand() )
    {
        case WLEMMCommand::Command::COMPUTE:
            wlog::debug( CLASS ) << "Processing Command::COMPUTE";
            succes = processCompute( cmdIn->getEmm() );
            break;
        case WLEMMCommand::Command::INIT:
            wlog::debug( CLASS ) << "Processing Command::INIT";
            succes = processInit( cmdIn );
            break;
        case WLEMMCommand::Command::MISC:
            wlog::debug( CLASS ) << "Processing Command::MISC";
            succes = processMisc( cmdIn );
            break;
        case WLEMMCommand::Command::TIME_UPDATE:
            wlog::debug( CLASS ) << "Processing Command::TIME_UPDATE";
            succes = processTime( cmdIn );
            break;
        case WLEMMCommand::Command::RESET:
            wlog::debug( CLASS ) << "Processing Command::RESET";
            succes = processReset( cmdIn );
            break;
        default:
            wlog::error( CLASS ) << "Unknown Command::Enum!";
            succes = false;
    }
    if( !succes )
    {
        wlog::error( CLASS ) << "Error on processing command:\n" << *cmdIn;
    }
    return succes;
}
예제 #3
0
entry loadEntry() {
    entry e = { NULL, -1, 0 };
    uint32_t length, offset[4];

    /* reset error container */
    errors.level = 0;

    offset[0] = CURR_OFFSET;
    if (!loadType(&e)) {
        return e;
    }

    offset[1] = CURR_OFFSET;
    if (e.type == REDIS_SELECTDB) {
        if ((length = loadLength(NULL)) == REDIS_RDB_LENERR) {
            SHIFT_ERROR(offset[1], 
                "Error reading database number");
            return e;
        }
        if (length > 63) {
            SHIFT_ERROR(offset[1], 
                "Database number out of range (%d)", length);
            return e;
        }
    } else if (e.type == REDIS_EOF) {
        if (positions[level].offset < positions[level].size) {
            SHIFT_ERROR(offset[0], 
                "Unexpected EOF");
        } else {
            e.success = 1;
        }
        return e;
    } else {
        /* optionally consume expire */
        if (e.type == REDIS_EXPIRETIME) {
            if (!processTime()) return e;
            if (!loadType(&e)) return e;
            db_stats.total_expires++;
        }

        offset[1] = CURR_OFFSET;
        if (!loadPair(&e)) {
            SHIFT_ERROR(offset[1], "Error for type %s", types[e.type]);
            return e;
        }
    }

    /* all entries are followed by a valid type:
     * e.g. a new entry, SELECTDB, EXPIRE, EOF */
    offset[2] = CURR_OFFSET;
    if (peekType() == -1) {
        SHIFT_ERROR(offset[2], "Followed by invalid type");
        SHIFT_ERROR(offset[0], "Error for type %s", types[e.type]);
        e.success = 0;
    } else {
        e.success = 1;
    }

    return e;
}
예제 #4
0
	VML::Vector3 Vec3Linear::Interpolate(float t) const
	{
		assert(IsReady());

		processTime(t);
		size_t segm = findSegment(t); 

		const SKeyframeVec3& p0 = mKeyframes[segm];
		const SKeyframeVec3& p1 = mKeyframes[segm + 1];
		float u = (t - p0.time) / (p1.time - p0.time);
		return (p1.data - p0.data) * u + p0.data;
	}
예제 #5
0
	VML::Vector3 Vec3CubicSpline::Interpolate(float t) const
	{
		assert(IsReady());

		processTime(t);
		size_t segm = findSegment(t); 
		size_t n_ctrl = mKeyframes.size();

		const SKeyframeVec3& p0 = mKeyframes[segm];
		const SKeyframeVec3& p1 = mKeyframes[segm + 1];
		const VML::Vector3& t0 = mTangents[segm];
		const VML::Vector3& t1 = mTangents[segm+1];

		float u = (t - p0.time) / (p1.time - p0.time), u2 = u*u, u3 = u2*u;
		VML::Vector3 pos = p0.data*(2.0f*u3 - 3.0f*u2 + 1.0f) + p1.data*(-2.0f*u3 + 3.0f*u2) + t0*(u3 - 2.0f*u2 + u) + t1*(u3 - u2);

		return pos;
	}
예제 #6
0
	VML::Vector3 Vec3CatmullRom::Interpolate(float t) const
	{
		assert(IsReady());

		processTime(t);
		size_t segm = findSegment(t); 
		size_t n_ctrl = mKeyframes.size();

		const VML::Vector3& p0 = mKeyframes[segm].data;
		const VML::Vector3& p1 = mKeyframes[segm + 1].data;
		float time0 = mKeyframes[segm].time;
		float time1 = mKeyframes[segm + 1].time;

		VML::Vector3 t0(0);
		VML::Vector3 t1(0);

		if(segm > 0 && segm < n_ctrl - 2)
		{
			t0 = (p1 - mKeyframes[segm - 1].data) * 0.5f;
			t1 = (mKeyframes[segm + 2].data - p0) * 0.5f;
		}
		else if(segm == 0 && n_ctrl > 2)
		{
			t0 = (p1 + p1 - mKeyframes[segm + 2].data - p0) * 0.5f;
			t1 = (mKeyframes[segm + 2].data - p0) * 0.5f;
		}
		else if (segm == n_ctrl - 2 && n_ctrl > 2)
		{
			t0 = (p1 - mKeyframes[segm - 1].data) * 0.5f;
			t1 = - (p0 + p0 - mKeyframes[segm - 1].data - p1) * 0.5f;
		}

		float u = (t - time0) / (time1 - time0), u2 = u*u, u3 = u2*u;
		VML::Vector3 pos = p0*(2.0f*u3 - 3.0f*u2 + 1.0f) + p1*(-2.0f*u3 + 3.0f*u2) + t0*(u3 - 2.0f*u2 + u) + t1*(u3 - u2);
		return pos;
	}
int main(int argc, char** argv)
{
	struct sigaction quitAction;
	quitAction.sa_handler = finProgramme;
	quitAction.sa_flags = 0;
	sigaction(SIGINT, &quitAction, NULL);
	sigaction(SIGQUIT, &quitAction, NULL);
	// sigaction(, &quitAction, NULL);
	
	int pereFils[2];
	int filsPere[2];
	
	if(pipe(pereFils) == -1 || pipe(filsPere) == -1)
	{
		fprintf(stderr, "Erreur pipe() impossible...\nArret du programme...\n");
		finProgramme(1);
	}
	
	int pid = fork();
	if (pid == -1)
	{
		fprintf(stderr, "Erreur fork() impossible...\nArret du programme...\n");
		finProgramme(1);
	}
	else if(pid == 0) // fils traitement
	{
	
		
		close(filsPere[0]); // Fermeture de la lecture sur filsPere
		close(pereFils[1]); // Fermeture de l'ecriture sur pereFils
		
		fcntl(pereFils[0], F_SETFL, O_NONBLOCK); // Lecture non bloquante
		
		do
		{
			printf("Entrez la taille de la mémoire vive :\t");
			scanf("%d", &tailleMemoireVive);
		
			printf("Entrez la taille de la memoire virtuelle :\t");
			scanf("%d", &tailleMemoireVirtuelle);
			if (tailleMemoireVive > tailleMemoireVirtuelle)
			{
				fprintf(stderr, "La memoire vive ne peut pas avoir une plus grande taille que le memoire virtuelle!\n");
			}
		} while (tailleMemoireVive > tailleMemoireVirtuelle);
	
		do
		{
			printf("Entrez la taille des cadres de pages :\t");
			scanf("%d", &tailleCadresPages);
			if (tailleCadresPages > tailleMemoireVive || tailleCadresPages < 1)
				fprintf(stderr, "La taille du cadre des pages doit etre une valeur strictement positive, inferieure a la taille de la memoire vive!\n");
		} while (tailleCadresPages > tailleMemoireVive || tailleCadresPages < 1);
	
		do
		{
			printf("Entrez le quantum pour l'ordonnancement :\t");
			scanf("%d", &quantum);
			if (quantum < 1)
				fprintf(stderr, "Le quantum doit avoir une valeur strictement positive!\n");
		} while (quantum < 1);
		
		preparationMemoire();
		preparationOrdonnanceur();
		
		/*
		newProcessus(10, 10);
		newProcessus(10, 10);
		newProcessus(10, 10);
		*/
		
		kill(getppid(), SIGUSR1);
		
		while(0 == 0)
		{
			int numOrdonnancement = 0;
			while(numOrdonnancement < MAXORDONNANCEMENT)
			{
				processTime();
				//printf("Lecture de %s\n", a);
				analyseReponse(pereFils[0]);
				sleep(quantum);
			}
			reordonnancement();
		}
	}
	else // pere
	{
		close(filsPere[1]); // Fermeture de l'ecriture sur filsPere
		close(pereFils[0]); // Fermeture de la lecture sur pereFils
		struct sigaction reveilAct;
		reveilAct.sa_handler = reveil;
		reveilAct.sa_flags = 0;
		sigemptyset(&reveilAct.sa_mask);
		sigaction(SIGUSR1, &reveilAct, NULL);
		// Le pere entre en sommeil jusqu'a ce que le fils ait fini son initialisation
		sleep(60);
		
		printf("Initialisation terminée,\nvous pouvez maintenant utiliser le simulateur d'ordonnancement et de gestion de la mémoire.\n\n");
		
		int action, end;
		end = 0;
		
		while (end == 0)
		{
			printf("Entrez une action a effectuer parmis les suivantes en entrant le numero correspondant:\n");
			printf("0: Fin du simulateur.\n");
			printf("1: Ajout d'un nouveau processus.\n");
			printf("2: Affichage de la file d'attente des processus.\n");
			printf("3: Affichage de la memoire.\n");
		
			scanf("%d", &action);
			switch (action)
			{
				case 1:
					demandeAjoutProcessus(pereFils[1]);
					sleep(100);
					break;
				case 2:
					demandeFileAttenteProcessus(pereFils[1]);
					sleep(100);
					break;
				case 3:
					demandeMemoire(pereFils[1]);
					sleep(100);
					break;
				case 0:
					end = 1;
					break;
			}
		}
	}
	
	finProgramme(0);
	return 1;
}
예제 #8
0
STDMETHODIMP TffProcVideo::process(unsigned int framenum,uint64_t incsp,const unsigned char *src[4],stride_t srcStride[4],int ro,uint64_t outcsp,unsigned char *dst[4],stride_t dstStride[4])
{
    return processTime(framenum,REF_SECOND_MULT*fpsDen*framenum/fpsNum,REF_SECOND_MULT*fpsDen*(framenum+1)/fpsNum,incsp,src,srcStride,ro,outcsp,dst,dstStride);
}
예제 #9
0
AnimationTimer::AnimationTimer(QObject *parent) : QObject(parent)
{
    timer.setTimerType(Qt::PreciseTimer);
    connect(&timer, SIGNAL(timeout()), this, SLOT(processTime()));
}