// // Copyright 2006 Perforce Software. All rights reserved. // // This file is part of Perforce - the FAST SCM System. // #include <p4wp4.h> #include <string.h> #include <ctype.h> #include "thumbcache.h" # ifdef OS_NT // thumbnail cache data StrBuf cache; unsigned cacheSize = 0; char * pCache = 0; char * pCacheEnd = 0; // performance statistics unsigned cachein = 0; unsigned cacheout = 0; unsigned cachefail = 0; typedef struct _thumb { void * prev; void * next; char * path; int rev; int chg; char * thumbnail; int thumblgth; int done; } thumb; thumb * head = 0; #endif // only one of rev or chgnbr need be passed, the other should be NULL int addToCache(char *depotpath, char * rev, char *chgnbr, char *thumbnail, int thumblgth) { # ifdef OS_NT extern CRITICAL_SECTION CriticalSection; if (thumblgth <= 0) return 0; EnterCriticalSection(&CriticalSection); thumb * oldhead = head; // save for putting in 'prev' ptr if (!pCache) // initialize { pCache = cache.Alloc(cacheSize = 60 * 1024 * 500); pCacheEnd = pCache + cacheSize; head = (thumb *)pCache; memset(pCache, '\0', sizeof(thumb)); } thumb *next = (thumb *)head->next; // save the current 'next' ptr if (head->path) // (is NULL only for initial call) { head = (thumb *)((char *)head + sizeof(thumb) + strlen(head->path)+1 + head->thumblgth+1); memset(head, '\0', sizeof(thumb)); } // check for room in buffer int lgth = sizeof(thumb) + strlen(depotpath)+1 + thumblgth+1; char *p = (char *)head + lgth; if (p >= pCacheEnd) // if we've run out of room at the end of the buffer { head = (thumb *)pCache; next = (thumb *)head->next; } // If we've wrapped, then the 'next' ptr will be non-zero. // // Figure out how many images to overwrite with this new one // and set the new head's next to point to the next live image. // // Note that if t becomes == pCache, we know (from above) // that the cache has enough room, so we can stop looking // and set head->next to pCache (i.e. wrap after this image). if (next) { p = (char *)head + lgth; thumb *t = next; while (((char *)t <= p) && (t != (thumb *)pCache)) t = (thumb *)t->next; head->next = (thumb *)t; t->prev = NULL; } // We've now found enough room in cache buffer for // the thumb struct, the path and the image. if (oldhead) // If there is a prev, oldhead->next = head; // make it point its 'next' to here. head->prev = (void *)oldhead; head->path = (char *)head + sizeof(thumb); strcpy(head->path, depotpath); head->rev = rev ? atoi(rev) : -1; head->chg = chgnbr ? atoi(chgnbr) : -1; head->thumbnail = head->path + strlen(head->path) + 1; memmove(head->thumbnail, thumbnail, thumblgth); head->thumblgth = thumblgth; head->done = 0; cachein++; LeaveCriticalSection(&CriticalSection); return thumblgth; #else return 0; // caching only on NT #endif } // only one of rev or chgnbr should be passed, the other should be NULL // // Note: you must call EnterCriticalSection(&CriticalSection); // before calling getFromCache() and you must call // LeaveCriticalSection(&CriticalSection); // AFTER you have finished copying/writing the date returned in 'thumbnail' // and AFTER getFromCache() returns 0 (as well) // int getFromCache(char *depotpath, char * rev, char *chgnbr, char **pthumbnail) { # ifdef OS_NT if (!head) return 0; thumb *t = head; // start at the current head do // loop backwards thru the cache using the 'prev' ptrs { if (!strcmp(depotpath, t->path)) { if ((rev && (atoi(rev) == t->rev)) || (chgnbr && (atoi(chgnbr) == t->chg))) { cacheout++; t->done = 1; *pthumbnail = t->thumbnail; return t->thumblgth; } } t = (thumb *)t->prev; } while (t); cachefail++; #endif return 0; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12234 | Matt Attaway |
Rejigger P4Web project in preparation for official sunsetting The bin directory contains the last official builds of P4Web from the Perforce download site. P4Web is soon to be completely sunsetted; these builds are here for folks who don't want to build their own. To better handle the archived builds the source code has been moved into a separate src directory. |
||
//guest/perforce_software/p4web/Main/thumbcache.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |