コード例 #1
0
/*******************************************
 Name  : uninitVolume
 Descr.: maybe a better name would be unmountVolume
         free resources allocated by initVolume
 Input : volume  - volume to unmount
 Output: -
********************************************/
void uninitVolume(struct AFSBase *afsbase, struct Volume *volume) {

	osMediumFree(afsbase, volume, TRUE);
	if (volume->blockcache != NULL)
		freeCache(afsbase, volume->blockcache);
	closeBlockDevice(afsbase, &volume->ioh);
	FreeMem(volume,sizeof(struct Volume));
}
コード例 #2
0
ファイル: csim.c プロジェクト: mandyssst/MyCode
/*
 * main - Main routine 
 */
int main(int argc, char* argv[])
{
    char c;

    while( (c=getopt(argc,argv,"s:E:b:t:vh")) != -1){
        switch(c){
        case 's':
            s = atoi(optarg);
            break;
        case 'E':
            E = atoi(optarg);
            break;
        case 'b':
            b = atoi(optarg);
            break;
        case 't':
            trace_file = optarg;
            break;
        case 'v':
            verbosity = 1;
            break;
        case 'h':
            printUsage(argv);
            exit(0);
        default:
            printUsage(argv);
            exit(1);
        }
    }

    /* Make sure that all required command line args were specified */
    if (s == 0 || E == 0 || b == 0 || trace_file == NULL) {
        printf("%s: Missing required command line argument\n", argv[0]);
        printUsage(argv);
        exit(1);
    }

    /* Compute S, E and B from command line args */
     S=pow(2,s);
     B=pow(2,b);
    /* Initialize cache */
    initCache();

#ifdef DEBUG_ON
    printf("DEBUG: S:%u E:%u B:%u trace:%s\n", S, E, B, trace_file);
#endif
 
    /* Read the trace and access the cache */
    replayTrace(trace_file);

    /* Free allocated memory */
    freeCache();

    /* Output the hit and miss statistics for the autograder */
    printSummary(hit_count, miss_count, eviction_count);
    return 0;
}
コード例 #3
0
void Font::InitModel() {
    if (! ( program = ProgramManagerObj->Program( ( char * )"font" ) ) )
    {
        program = ProgramManagerObj->ProgramInit( ( char * )"font" );
        ProgramManagerObj->AddProgram( program );
        program->VertexShader	= ShaderManager::ShaderInit( VERTEX_SHADER_PRG,	GL_VERTEX_SHADER	);
        program->FragmentShader	= ShaderManager::ShaderInit( FRAGMENT_SHADER_PRG, GL_FRAGMENT_SHADER	);
        
        //////////////////////////////////////////////////////
        ///////////// Vertex shader //////////////////////////
        //////////////////////////////////////////////////////
        CACHE *m = reserveCache(VERTEX_SHADER_PRG, true);
        if (m) {
            if (!ShaderManager::ShaderCompile(program->VertexShader, (char *) m->buffer, 1))
                exit(1);
            freeCache(m);
        }
        
        //////////////////////////////////////////////////////
        ///////////// Fragment shader ////////////////////////
        //////////////////////////////////////////////////////
        m = reserveCache(FRAGMENT_SHADER_PRG, true);
        if (m) {
            if (!ShaderManager::ShaderCompile(program->FragmentShader,(char *) m->buffer, 1))
                exit(2);
            freeCache(m);
        }
        
        if (!ProgramManagerObj->ProgramLink(program, 1))
            exit(3);
    }
    else{
    }
    
    
    // Get the uniform location cache for optimization purpose
    MVP         = ProgramManagerObj->ProgramGetUniformLocation( program, (char*)"ModelViewProjectMatrix" );
    TEX         = ProgramManagerObj->ProgramGetUniformLocation( program, (char *) "Tex1" );
    FRAG_COLOR  = ProgramManagerObj->ProgramGetUniformLocation( program, (char*)"TextColor" );
}
コード例 #4
0
ファイル: csim.c プロジェクト: laosiaudi/CMU-15513-Labs
void simulate(FILE* fp, int setIndex, int lines, int blockBits) {
    //simulate cache memory
    struct cache_line** cache = build_cache(setIndex, lines);
    char blank;
    char Op;
    int addressVal;
    int offset;

    char buf[1000];
    int hit = 0, miss = 0, eviction = 0;
    int setNumber;
    int tag;
    int tempHit, tempMiss, tempEvict;
    while (fgets(buf, sizeof(buf), fp) != NULL) {
        tempHit = tempMiss = tempEvict = 0;
        sscanf(buf, "%c %c %x,%d",&blank, &Op, &addressVal, &offset);
        if (blank == 'I')
            continue;

        setNumber = getSetIndex(addressVal, setIndex, blockBits);
        tag = addressVal >> (setIndex + blockBits);

        if (findCache(cache, setNumber, lines, tag)) {
            hit ++;
            tempHit ++;
            updateCache(setNumber, tag);
        } else {
            miss ++;
            tempMiss ++;
            tempEvict += replaceCache(cache, setNumber, lines, tag);
        }
        if (Op == 'M') {
            //if the operation is M, need to find cache again
            if (findCache(cache, setNumber, lines, tag)) {
                hit ++;
                tempHit ++;
                updateCache(setNumber, tag);
            } else {
                miss ++;
                tempMiss ++;
                tempEvict += replaceCache(cache, setNumber, lines, tag);
            }
        }
        eviction += tempEvict;
        if (verbose)
            printVerboseInfo(buf, tempHit, tempMiss, tempEvict);
    }
    //printf("%d %d %d\n", hit, miss, eviction);
    freeCache(cache);
    freeQueue();
    printSummary(hit, miss, eviction);
}
コード例 #5
0
ファイル: tuxtxtapp.cpp プロジェクト: henrye/enigma2pc
void eTuxtxtApp::setEnableTtCachingOnOff( int onoff )
{
    if (onoff && !enableTtCaching)		// Switch caching on
    {
        enableTtCaching = true;
        if (pid)
        {
            initCache();
            startCaching(pid, demux);
        }
    }
    else if (!onoff && enableTtCaching)	// Switch caching off
    {
        enableTtCaching = false;
        int savePid = pid;
        freeCache();
        pid = savePid;
    }
}
コード例 #6
0
HttpWorker::~HttpWorker()
{
	TRACE(1, "destroying");

	clearCustomData();

#if !defined(X0_WORKER_POST_LIBEV)
	pthread_mutex_destroy(&postLock_);
#endif

	pthread_cond_destroy(&resumeCondition_);
	pthread_mutex_destroy(&resumeLock_);

	evLoopCheck_.stop();
	evNewConnection_.stop();
	evWakeup_.stop();

	freeCache();
}
コード例 #7
0
ファイル: inotify_dtree.c プロジェクト: Cergoo/junk
static int
reinitialize(int oldInotifyFd)
{
    int inotifyFd;
    static int reinitCnt;
    int cnt, j;

    if (oldInotifyFd >= 0) {
        close(oldInotifyFd);

        reinitCnt++;
        logMessage(0, "Reinitializing cache and inotify FD (reinitCnt = %d)\n",
                reinitCnt);

    } else {
        logMessage(0, "Initializing cache\n");
        reinitCnt = 0;
    }

    inotifyFd = inotify_init();
    if (inotifyFd == -1)
        errExit("inotify_init");

    logMessage(VB_BASIC, "    new inotifyFd = %d\n", inotifyFd);

    freeCache();

    for (j = 0; j < numRootDirs; j++)
        if (rootDirPaths[j] != NULL)
            watchSubtree(inotifyFd, rootDirPaths[j]);

    cnt = 0;
    for (j = 0; j < cacheSize; j++)
        if (wlCache[j].wd >= 0)
            cnt++;

    if (oldInotifyFd >= 0)
        logMessage(0, "Rebuilt cache with %d entries\n", cnt);

    return inotifyFd;
}
コード例 #8
0
/*******************************************
 Name  : initVolume
 Descr.: maybe a better name would be mountVolume
         allocate resources for a new mounted device
 Input : device      - device pointer
         blockdevice - name of blockdevice
         unit        - unit number of blockdevice
         devicedef   - medium geometry data
         error       - return error code
 Output: 0 on error (error set dos dos error);
         pointer to struct Volume on success
********************************************/
struct Volume *initVolume
	(
		struct AFSBase *afsbase,
		struct Device *device,
		CONST_STRPTR blockdevice,
		ULONG unit,
		struct DosEnvec *devicedef,
		ULONG *error
	)
{
struct Volume *volume;

	volume = AllocMem(sizeof(struct Volume),MEMF_PUBLIC | MEMF_CLEAR);
	if (volume != NULL)
	{
		volume->device = device;
		volume->ioh.blockdevice = blockdevice;
		volume->ioh.unit = unit;
		volume->ioh.flags = 0;
		volume->SizeBlock=devicedef->de_SizeBlock;
		if (devicedef->de_TableSize>=20)
			volume->bootblocks=devicedef->de_BootBlocks;
		else
			volume->bootblocks=devicedef->de_Reserved;
		volume->blockcache=initCache(afsbase, volume, devicedef->de_NumBuffers);
		if (volume->blockcache != NULL)
		{
			if (openBlockDevice(afsbase, &volume->ioh)!= NULL)
			{
				volume->countblocks =
					(
						(
							devicedef->de_HighCyl-devicedef->de_LowCyl+1
						)*devicedef->de_Surfaces*devicedef->de_BlocksPerTrack
					);
				volume->rootblock =(volume->countblocks-1+devicedef->de_Reserved)/2;
				volume->startblock=
						devicedef->de_LowCyl*
						devicedef->de_Surfaces*
						devicedef->de_BlocksPerTrack;
				volume->lastblock=
						(
							(devicedef->de_HighCyl+1)
							*devicedef->de_Surfaces
							*devicedef->de_BlocksPerTrack
						)-1;
				check64BitSupport(afsbase, volume);
				volume->ah.volume=volume;
				if (mediumPresent(&volume->ioh))
				{
					*error = newMedium(afsbase, volume);
				}
				else
					*error = 0;
				if ((*error == 0) || (*error == ERROR_NOT_A_DOS_DISK))
				{
					D(bug("[afs] initVolume: BootBlocks=%d\n",volume->bootblocks));
					D(bug("[afs] initVolume: RootBlock=%ld\n",volume->rootblock));
					volume->ah.header_block = volume->rootblock;
					return volume;
				}
			}
			else
			{
				*error=ERROR_NO_FREE_STORE;
			}
			freeCache(afsbase, volume->blockcache);
		}
		else
		{
			*error=ERROR_NO_FREE_STORE;
		}
		FreeMem(volume,sizeof(struct Volume));
	}
	else
		*error=ERROR_NO_FREE_STORE;
	return NULL;
}
コード例 #9
0
/*!
	Initialize the scene, reserve shaders, compile and cache program

	\param[in] None.
	\return None

*/
void Cube::InitModel()
{
	if (! ( program = ProgramManagerObj->Program( (char *)"Cube" ))){
		program = ProgramManagerObj->ProgramInit( (char *)"Cube" );
		ProgramManagerObj->AddProgram( program );
	}

    //Initialize Vertex and Fragment shader
	program->VertexShader	= ShaderManager::ShaderInit( VERTEX_SHADER_PRG,	GL_VERTEX_SHADER	);
	program->FragmentShader	= ShaderManager::ShaderInit( FRAGMENT_SHADER_PRG, GL_FRAGMENT_SHADER	);

    // Compile Vertex shader
	CACHE *m = reserveCache( VERTEX_SHADER_PRG, true );
	if( m ) {
		if( !ShaderManager::ShaderCompile( program->VertexShader, ( char * )m->buffer, 1 ) ) exit( 1 );
        freeCache( m );
	}

    // Compile Fragment shader
	m = reserveCache( FRAGMENT_SHADER_PRG, true );
	if( m ) {
		if( !ShaderManager::ShaderCompile( program->FragmentShader, ( char * )m->buffer, 1 ) ) exit( 2 );
        freeCache( m );
	}

    // Link program
    if( !ProgramManagerObj->ProgramLink( program, 1 ) ) exit( 3 );

    glUseProgram( program->ProgramID );


    // Create VBO
 	size = 24*sizeof(float);
    glGenBuffers(1, &vId);
	glBindBuffer( GL_ARRAY_BUFFER, vId );
	glBufferData( GL_ARRAY_BUFFER, size + size, 0, GL_STATIC_DRAW );
	glBufferSubData( GL_ARRAY_BUFFER, 0,			size,	cubeVerts );
	glBufferSubData( GL_ARRAY_BUFFER, size,			size,	cubeColors );


    // Create VBO for transformation matrix
    glGenBuffers(1, &matrixId);
	glBindBuffer( GL_ARRAY_BUFFER, matrixId );


    glm::mat4 transformMatrix[dimension][dimension][dimension];
    glBufferData(GL_ARRAY_BUFFER, sizeof(transformMatrix) , 0, GL_DYNAMIC_DRAW);

    // Create IBO
	unsigned short indexSize = sizeof( unsigned short )*36;
    glGenBuffers(1, &iId);
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, iId );
	glBufferData( GL_ELEMENT_ARRAY_BUFFER, indexSize, 0, GL_STATIC_DRAW );
	glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, 0, indexSize,	cubeIndices );

    glGenVertexArrays(1, &Vertex_VAO_Id);
    glBindVertexArray(Vertex_VAO_Id);

    // Create VBO  and set attribute parameters
	glBindBuffer( GL_ARRAY_BUFFER, vId );
    glEnableVertexAttribArray(VERTEX_LOCATION);
    glEnableVertexAttribArray(COLOR_LOCATION);
    glVertexAttribPointer(VERTEX_LOCATION, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
    glVertexAttribPointer(COLOR_LOCATION, 3, GL_FLOAT, GL_FALSE, 0, (void*)size);

    // Create VBO for transformation matrix and set attribute parameters
	glBindBuffer( GL_ARRAY_BUFFER, matrixId );
    glEnableVertexAttribArray(MATRIX1_LOCATION);
    glEnableVertexAttribArray(MATRIX2_LOCATION);
    glEnableVertexAttribArray(MATRIX3_LOCATION);
    glEnableVertexAttribArray(MATRIX4_LOCATION);

    glVertexAttribPointer(MATRIX1_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(float) * 0));
    glVertexAttribPointer(MATRIX2_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(float) * 4));
    glVertexAttribPointer(MATRIX3_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(float) * 8));
    glVertexAttribPointer(MATRIX4_LOCATION, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(float) * 12));

    glVertexAttribDivisor(MATRIX1_LOCATION, 1);
    glVertexAttribDivisor(MATRIX2_LOCATION, 1);
    glVertexAttribDivisor(MATRIX3_LOCATION, 1);
    glVertexAttribDivisor(MATRIX4_LOCATION, 1);

    // Bind IBO
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, iId );


    // Make sure the VAO is not changed from outside code
    glBindVertexArray(0);

    return;
}