int StaticFileCache::getCacheElement( const char * pPath, int pathLen, const struct stat& fileStat, int fd, StaticFileCacheData* &pData, FileCacheDataEx * &pECache ) { if ( !pData ) { HttpCache::iterator iter = find( pPath ); if ( iter ) { pData = (StaticFileCacheData* )(iter.second()); } } if ( pData ) { if ( pData->isDirty( fileStat ) ) { if ( dirty( pData ) ) return SC_500; pData = NULL; pECache = NULL; } else return 0; } int ret = newCache( pPath, pathLen, fileStat, fd, pData ); if ( ret ) return ret; add( pData ); return 0; }
static PRBool EnsurePreflightCache() { if (sPreflightCache) return PR_TRUE; nsAutoPtr<nsPreflightCache> newCache(new nsPreflightCache()); if (newCache->Initialize()) { sPreflightCache = newCache.forget(); return PR_TRUE; } return PR_FALSE; }
void MusicLibraryModel::convertCache(const QString &compressedName) { QString prev=compressedName; prev.replace(constLibraryCompressedExt, constLibraryExt); if (QFile::exists(prev) && !QFile::exists(compressedName)) { QFile old(prev); if (old.open(QIODevice::ReadOnly)) { QByteArray a=old.readAll(); old.close(); QFile newCache(compressedName); QtIOCompressor compressor(&newCache); compressor.setStreamFormat(QtIOCompressor::GzipFormat); if (compressor.open(QIODevice::WriteOnly)) { compressor.write(a); compressor.close(); QFile::remove(prev); } } } }
void insertInOrder(sortedPacketCache **head, Packet* pkt, int seq){ sortedPacketCache* cache = newCache(pkt, seq); sortedPacketCache* cur = *head; if(cur == NULL){ cache->next = cur; *head = cache; return; } while(cur != NULL){ if(cur->next == NULL){ cur->next = cache; break; } if(seq < cur->next->seq){ cache->next = cur->next; cur->next = cache; break; } cur = cur->next; } }
/* * Return a GC associated with the given id, allocating if needed. */ GC getCgsGC(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId) { CgsCache *me; GC result = 0; int j, k; unsigned used = 0; if ((me = myCache(xw, cgsWin, cgsId)) != 0) { TRACE2(("getCgsGC(%s, %s)\n", traceVTwin(xw, cgsWin), traceCgsEnum(cgsId))); if (me->mask != 0) { /* fill in the unchanged fields */ if (!(me->mask & GC_CSet)) NEXT(cset) = 0; /* OPT_DEC_CHRSET */ if (!(me->mask & GCFont)) NEXT(font) = THIS(font); if (!(me->mask & GCForeground)) NEXT(fg) = THIS(fg); if (!(me->mask & GCBackground)) NEXT(bg) = THIS(bg); if (NEXT(font) == 0) { setCgsFont(xw, cgsWin, cgsId, 0); } TRACE2(("...Cgs new data fg=%s, bg=%s, font=%s cset %s\n", tracePixel(xw, NEXT(fg)), tracePixel(xw, NEXT(bg)), traceFont(NEXT(font)), traceCSet(NEXT(cset)))); /* try to find the given data in an already-created GC */ for (j = 0; j < DEPTH; ++j) { if (LIST(j).gc != 0 && SameFont(LIST(j).font, NEXT(font)) && SameCSet(LIST(j).cset, NEXT(cset)) && SameColor(LIST(j).fg, NEXT(fg)) && SameColor(LIST(j).bg, NEXT(bg))) { LINK(j); result = THIS(gc); TRACE2(("getCgsGC existing %p(%d)\n", result, ITEM())); break; } } if (result == 0) { /* try to find an empty slot, to create a new GC */ used = 0; for (j = 0; j < DEPTH; ++j) { if (LIST(j).gc == 0) { LINK(j); result = newCache(xw, cgsWin, cgsId, me); break; } if (used < LIST(j).used) used = LIST(j).used; } } if (result == 0) { /* if none were empty, pick the least-used slot, to modify */ for (j = 0, k = -1; j < DEPTH; ++j) { if (used >= LIST(j).used) { used = LIST(j).used; k = j; } } LINK(k); TRACE2(("...getCgsGC least-used(%d) was %d\n", k, THIS(used))); result = chgCache(xw, cgsId, me, True); } me->next = *(me->data); } else { result = THIS(gc); } me->mask = 0; THIS(used) += 1; TRACE2(("...getCgsGC(%s, %s) gc %p(%d), used %d\n", traceVTwin(xw, cgsWin), traceCgsEnum(cgsId), result, ITEM(), THIS(used))); } return result; }
int main(int argc, char *argv[]){ cache_params_t params; /* file handling stuff */ FILE *tracefile; char instruction_ptr[50]; char instruction; char mem_addr[50]; int count; char *traceData; Cache_t cache; int tagSize, setSize, offsetSize; if(argc == 2 && strcmp(argv[1], "-h") == 0){ printf("help menu\n"); return 1; } if(argc < 2 || argc > 6){ printf("ERROR: incorrect number of arguments\n"); return 1; } /* * TODO: * Check cachesize = numsets x setsize x blocksize */ /* Check if cachesize here and correct*/ /* should check that these are numbers as well */ if(isPowerOfTwo(atoi(argv[1]))){ params.cachesize = atoi(argv[1]); }else{ printf("ERROR: cachesize must be a power of 2\n"); return 1; } /* check if blocksize is here and correct */ if(isPowerOfTwo(atoi(argv[3]))){ params.blocksize = atoi(argv[3]); }else{ printf("ERROR: blocksize must be a power of 2\n"); return 1; } params.setsize = 1; /* check for associativit y */ if(strcmp("direct", argv[2]) == 0){ params.associativity = "direct"; }else if( strcmp("assoc", argv[2]) == 0){ params.associativity = "assoc"; }else{ int i = 0, digit = 0; char* str = argv[2]; char* test; while(str[i] != '\0'){ if(isdigit(str[i])){ digit = i; break; } i++; } /* * setsize = 1 for d-m caches */ params.setsize = 1; test = malloc(strlen(argv[2])); strncpy(test, argv[2], digit); if(strcmp("assoc:", test) == 0){ params.associativity = "n-way"; if(isPowerOfTwo( argv[2][digit] - '0')){ params.setsize = argv[2][digit] - '0'; }else{ printf("ERROR: n must be power of 2\n"); return 1; } }else{ printf("ERROR: invalid associativity format\n"); return 1; } } /* check for writepolicy*/ if(strcmp("wt", argv[4]) == 0){ params.writepolicy = "wt"; }else if(strcmp("wb", argv[4]) == 0){ params.writepolicy = "wb"; }else{ printf("ERROR: invalid writepolicy format\n"); return 1; } /* check for tracefile */ if(!(tracefile = fopen(argv[5], "r"))){ printf("ERROR: could not find tracefile: %s\n", argv[5]); return 1; }else{ traceData = readFile(argv[5]); } /* <<<<<<< HEAD * create the new cache, do initialization stuff ======= * create the new cache, do initializatino stuff >>>>>>> 59f4c294c92c026c0d9d15ccfd2984234f2a3158 */ cache = *newCache(params.cachesize, params.blocksize, params.setsize, params.associativity, params.writepolicy); /* * read each line of the tracefile * * DIRECT MAP ONLY RIGHT NOW */ count = 0; while(fscanf(tracefile, "%s %c %s", instruction_ptr, &instruction, mem_addr) == 3) { int tag_size; int lines; int offset_size; int set_size; int set_lines; unsigned int addr_int; char *addr_bin; char *formatted_bin; char *tag; char *setid; char *offset; formatted_bin = (char*) malloc(sizeof(char) * 35); addr_bin = (char*) malloc(sizeof(char) * 33); lines = (int)(params.cachesize / params.blocksize); set_lines = (int)(params.cachesize / (params.blocksize * params.setsize)); if(strcmp(params.associativity,"n-way") == 0){ set_size = (int) ceil((log10(set_lines)/log10(2.0))); }else{ set_size = (int) ceil((log10(lines)/log10(2.0))); } offset_size = ceil((log10(params.blocksize)/log10(2.0))); tag_size = (32 - (offset_size+set_size)); /* * just for output */ tagSize = tag_size; setSize = set_size; offsetSize = offset_size; tag = (char*) malloc(sizeof(char)*tag_size+1); setid = (char*) malloc(sizeof(char)*set_size+1); offset = (char*) malloc(sizeof(char)*offset_size+1); addr_int = htoi(mem_addr); addr_bin = itob(addr_int); memcpy(tag, &addr_bin[0], tag_size); tag[tag_size+1] = '\0'; memcpy(setid, &addr_bin[tag_size], set_size); setid[set_size+1] = '\0'; memcpy(offset, &addr_bin[(tag_size+set_size)], offset_size); offset[offset_size+1] = '\0'; if(DEBUG) { printf("------\n%s\n",mem_addr); printf("%s %s %s \n", tag, setid, offset); printf("tag: %i, set: %i, offset: %i\n", tagSize, setSize, offsetSize); } /* * Write to the cache */ if('W' == instruction){ if(DEBUG){ printf("Write instruction\n Cache State:\n"); printCache(&cache); if( isInCache(&cache, addr_bin, tag, setid, offset)){ printf("\ncache already contains %s\n",mem_addr); }else{ printf("\ncache does not contain %s\n",mem_addr); } if( isInCache(&cache, addr_bin, tag, setid, offset)){ printf("\ncache contains %s\n",mem_addr); } printf("\nCache State:\n"); printCache(&cache); } writeToCache(&cache, addr_bin, tag, setid, offset, lines); /* * Read from the cache */ }else if('R' == instruction ){ if(DEBUG) { printf("Read instruction\n Cache State:\n"); printCache(&cache); if( isInCache(&cache, addr_bin, tag, setid, offset)){ printf("\ncache already contains %s\n",mem_addr); }else{ printf("\ncache does not contain %s\n",mem_addr); } if( isInCache(&cache, addr_bin, tag, setid, offset)){ printf("\ncache contains %s\n",mem_addr); } printf("\nCache State:\n"); printCache(&cache); } readFromCache(&cache, addr_bin, tag, setid, offset, lines); } count++; } printCache(&cache); return 1; }
UnzipCache::UnzipCache(const char *filename, const char *password) : m_uf(0), m_root(0), m_filename(filename), m_password(password ? password : "") { newCache(); }