This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Data Structures | |
struct | Aname |
Functions | |
const char * | cache_get (Aname *nam, int *pLen) |
bool | cache_put (Aname *nam, const char *obj, size_t len) |
int | cache_init (const char *game_dir_file, const char *game_pag_file, int nCachePages) |
void | cache_close (void) |
void | cache_tick (void) |
bool | cache_sync (void) |
void | cache_del (Aname *nam) |
void cache_close | ( | void | ) |
Definition at line 115 of file attrcache.cpp.
References cache_initted, CHashFile::CloseAll(), and hfAttributeFile.
00116 { 00117 hfAttributeFile.CloseAll(); 00118 cache_initted = false; 00119 }
void cache_del | ( | Aname * | nam | ) |
Definition at line 432 of file attrcache.cpp.
References statedata::acache_htab, tagAttrRecord::attrKey, Aname::attrnum, statedata::bStandAlone, cache_initted, CacheSize, CHashFile::Copy(), CRC32_ProcessInteger2(), ENDLINE, CHashFile::FindFirstKey(), CHashFile::FindNextKey(), hashdeleteLEN(), hashfindLEN(), HF_FIND_END, hfAttributeFile, Log, MEMFREE, mudstate, Aname::object, CHashFile::Remove(), REMOVE_ENTRY(), TempRecord, CLogFile::tinyprintf(), and statedata::write_protect.
Referenced by atr_clr().
00433 { 00434 if ( !nam 00435 || !cache_initted) 00436 { 00437 return; 00438 } 00439 00440 #ifndef WIN32 00441 if (mudstate.write_protect) 00442 { 00443 Log.tinyprintf("cache_del((%d,%d)) while database is write-protected" ENDLINE, 00444 nam->object, nam->attrnum); 00445 return; 00446 } 00447 #endif 00448 00449 UINT32 nHash = CRC32_ProcessInteger2(nam->object, nam->attrnum); 00450 00451 HP_DIRINDEX iDir = hfAttributeFile.FindFirstKey(nHash); 00452 while (iDir != HF_FIND_END) 00453 { 00454 HP_HEAPLENGTH nRecord; 00455 hfAttributeFile.Copy(iDir, &nRecord, &TempRecord); 00456 00457 if ( TempRecord.attrKey.attrnum == nam->attrnum 00458 && TempRecord.attrKey.object == nam->object) 00459 { 00460 hfAttributeFile.Remove(iDir); 00461 } 00462 iDir = hfAttributeFile.FindNextKey(iDir, nHash); 00463 } 00464 00465 if (!mudstate.bStandAlone) 00466 { 00467 // Update cache. 00468 // 00469 PCENT_HDR pCacheEntry = (PCENT_HDR)hashfindLEN(nam, sizeof(Aname), 00470 &mudstate.acache_htab); 00471 if (pCacheEntry) 00472 { 00473 // It was in the cache, so delete it. 00474 // 00475 REMOVE_ENTRY(pCacheEntry); 00476 CacheSize -= pCacheEntry->nSize;; 00477 hashdeleteLEN((char *)nam, sizeof(Aname), &mudstate.acache_htab); 00478 MEMFREE(pCacheEntry); 00479 pCacheEntry = NULL; 00480 } 00481 } 00482 }
const char* cache_get | ( | Aname * | nam, | |
int * | pLen | |||
) |
Definition at line 221 of file attrcache.cpp.
References statedata::acache_htab, ADD_ENTRY(), tagCacheEntryHeader::attrKey, tagAttrRecord::attrKey, Aname::attrnum, tagAttrRecord::attrText, statedata::bStandAlone, cache_initted, CacheSize, CHashFile::Copy(), CRC32_ProcessInteger2(), CHashFile::FindFirstKey(), CHashFile::FindNextKey(), hashaddLEN(), hashfindLEN(), HF_FIND_END, hfAttributeFile, MEMALLOC, mudstate, tagCacheEntryHeader::nSize, Aname::object, REMOVE_ENTRY(), TempRecord, and TrimCache().
Referenced by atr_get_raw_LEN().
00222 { 00223 if ( nam == (Aname *) 0 00224 || !cache_initted) 00225 { 00226 *pLen = 0; 00227 return NULL; 00228 } 00229 00230 PCENT_HDR pCacheEntry = NULL; 00231 if (!mudstate.bStandAlone) 00232 { 00233 // Check the cache, first. 00234 // 00235 pCacheEntry = (PCENT_HDR)hashfindLEN(nam, sizeof(Aname), 00236 &mudstate.acache_htab); 00237 if (pCacheEntry) 00238 { 00239 // It was in the cache, so move this entry to the head of the queue. 00240 // and return a pointer to it. 00241 // 00242 REMOVE_ENTRY(pCacheEntry); 00243 ADD_ENTRY(pCacheEntry); 00244 if (sizeof(CENT_HDR) < pCacheEntry->nSize) 00245 { 00246 *pLen = pCacheEntry->nSize - sizeof(CENT_HDR); 00247 return (char *)(pCacheEntry+1); 00248 } 00249 else 00250 { 00251 *pLen = 0; 00252 return NULL; 00253 } 00254 } 00255 } 00256 00257 UINT32 nHash = CRC32_ProcessInteger2(nam->object, nam->attrnum); 00258 00259 HP_DIRINDEX iDir; 00260 iDir = hfAttributeFile.FindFirstKey(nHash); 00261 while (iDir != HF_FIND_END) 00262 { 00263 HP_HEAPLENGTH nRecord; 00264 hfAttributeFile.Copy(iDir, &nRecord, &TempRecord); 00265 00266 if ( TempRecord.attrKey.attrnum == nam->attrnum 00267 && TempRecord.attrKey.object == nam->object) 00268 { 00269 int nLength = nRecord - sizeof(Aname); 00270 *pLen = nLength; 00271 if (!mudstate.bStandAlone) 00272 { 00273 // Add this information to the cache. 00274 // 00275 pCacheEntry = (PCENT_HDR)MEMALLOC(sizeof(CENT_HDR)+nLength); 00276 if (pCacheEntry) 00277 { 00278 pCacheEntry->attrKey = *nam; 00279 pCacheEntry->nSize = nLength + sizeof(CENT_HDR); 00280 CacheSize += pCacheEntry->nSize; 00281 memcpy((char *)(pCacheEntry+1), TempRecord.attrText, nLength); 00282 ADD_ENTRY(pCacheEntry); 00283 hashaddLEN(nam, sizeof(Aname), pCacheEntry, 00284 &mudstate.acache_htab); 00285 00286 TrimCache(); 00287 } 00288 } 00289 return TempRecord.attrText; 00290 } 00291 iDir = hfAttributeFile.FindNextKey(iDir, nHash); 00292 } 00293 00294 // We didn't find that one. 00295 // 00296 if (!mudstate.bStandAlone) 00297 { 00298 // Add this information to the cache. 00299 // 00300 pCacheEntry = (PCENT_HDR)MEMALLOC(sizeof(CENT_HDR)); 00301 if (pCacheEntry) 00302 { 00303 pCacheEntry->attrKey = *nam; 00304 pCacheEntry->nSize = sizeof(CENT_HDR); 00305 CacheSize += pCacheEntry->nSize; 00306 ADD_ENTRY(pCacheEntry); 00307 hashaddLEN(nam, sizeof(Aname), pCacheEntry, 00308 &mudstate.acache_htab); 00309 00310 TrimCache(); 00311 } 00312 } 00313 00314 *pLen = 0; 00315 return NULL; 00316 }
int cache_init | ( | const char * | game_dir_file, | |
const char * | game_pag_file, | |||
int | nCachePages | |||
) |
Definition at line 45 of file attrcache.cpp.
References cache_initted, cs_ltime, CLinearTimeAbsolute::GetUTC(), HF_OPEN_STATUS_ERROR, hfAttributeFile, and CHashFile::Open().
Referenced by init_dbfile().
00047 { 00048 if (cache_initted) 00049 { 00050 return HF_OPEN_STATUS_ERROR; 00051 } 00052 00053 int cc = hfAttributeFile.Open(game_dir_file, game_pag_file, nCachePages); 00054 if (cc != HF_OPEN_STATUS_ERROR) 00055 { 00056 // Mark caching system live 00057 // 00058 cache_initted = true; 00059 cs_ltime.GetUTC(); 00060 } 00061 return cc; 00062 }
bool cache_put | ( | Aname * | nam, | |
const char * | obj, | |||
size_t | len | |||
) |
Definition at line 321 of file attrcache.cpp.
References statedata::acache_htab, ADD_ENTRY(), tagCacheEntryHeader::attrKey, tagAttrRecord::attrKey, Aname::attrnum, tagAttrRecord::attrText, statedata::bStandAlone, cache_initted, cache_redirected, CacheSize, CHashFile::Copy(), CRC32_ProcessInteger2(), ENDLINE, CHashFile::FindFirstKey(), CHashFile::FindNextKey(), hashaddLEN(), hashdeleteLEN(), hashfindLEN(), HF_FIND_END, hfAttributeFile, CHashFile::Insert(), Log, MEMALLOC, MEMFREE, mudstate, N_TEMP_FILES, tagCacheEntryHeader::nSize, Aname::object, CHashFile::Remove(), REMOVE_ENTRY(), TempFiles, TempRecord, CLogFile::tinyprintf(), TrimCache(), and statedata::write_protect.
Referenced by atr_add_raw_LEN(), and cache_pass2().
00322 { 00323 if ( !value 00324 || !nam 00325 || !cache_initted 00326 || len == 0) 00327 { 00328 return false; 00329 } 00330 #ifndef WIN32 00331 if (mudstate.write_protect) 00332 { 00333 Log.tinyprintf("cache_put((%d,%d), '%s', %u) while database is write-protected" ENDLINE, 00334 nam->object, nam->attrnum, value, len); 00335 return false; 00336 } 00337 #endif 00338 00339 if (len > sizeof(TempRecord.attrText)) 00340 { 00341 len = sizeof(TempRecord.attrText); 00342 } 00343 00344 // Removal from DB. 00345 // 00346 UINT32 nHash = CRC32_ProcessInteger2(nam->object, nam->attrnum); 00347 00348 if (cache_redirected) 00349 { 00350 TempRecord.attrKey = *nam; 00351 memcpy(TempRecord.attrText, value, len); 00352 TempRecord.attrText[len-1] = '\0'; 00353 00354 int iFile = (N_TEMP_FILES-1) & (nHash >> 29); 00355 size_t nSize = len+sizeof(Aname); 00356 fwrite(&nSize, 1, sizeof(nSize), TempFiles[iFile]); 00357 fwrite(&TempRecord, 1, nSize, TempFiles[iFile]); 00358 return true; 00359 } 00360 00361 HP_DIRINDEX iDir = hfAttributeFile.FindFirstKey(nHash); 00362 while (iDir != HF_FIND_END) 00363 { 00364 HP_HEAPLENGTH nRecord; 00365 hfAttributeFile.Copy(iDir, &nRecord, &TempRecord); 00366 00367 if ( TempRecord.attrKey.attrnum == nam->attrnum 00368 && TempRecord.attrKey.object == nam->object) 00369 { 00370 hfAttributeFile.Remove(iDir); 00371 } 00372 iDir = hfAttributeFile.FindNextKey(iDir, nHash); 00373 } 00374 00375 TempRecord.attrKey = *nam; 00376 memcpy(TempRecord.attrText, value, len); 00377 TempRecord.attrText[len-1] = '\0'; 00378 00379 // Insertion into DB. 00380 // 00381 if (!hfAttributeFile.Insert((HP_HEAPLENGTH)(len+sizeof(Aname)), nHash, &TempRecord)) 00382 { 00383 Log.tinyprintf("cache_put((%d,%d), '%s', %u) failed" ENDLINE, 00384 nam->object, nam->attrnum, value, len); 00385 } 00386 00387 if (!mudstate.bStandAlone) 00388 { 00389 // Update cache. 00390 // 00391 PCENT_HDR pCacheEntry = (PCENT_HDR)hashfindLEN(nam, sizeof(Aname), 00392 &mudstate.acache_htab); 00393 if (pCacheEntry) 00394 { 00395 // It was in the cache, so delete it. 00396 // 00397 REMOVE_ENTRY(pCacheEntry); 00398 CacheSize -= pCacheEntry->nSize; 00399 hashdeleteLEN((char *)nam, sizeof(Aname), &mudstate.acache_htab); 00400 MEMFREE(pCacheEntry); 00401 pCacheEntry = NULL; 00402 } 00403 00404 // Add information about the new entry back into the cache. 00405 // 00406 size_t nSizeOfEntry = sizeof(CENT_HDR) + len; 00407 pCacheEntry = (PCENT_HDR)MEMALLOC(nSizeOfEntry); 00408 if (pCacheEntry) 00409 { 00410 pCacheEntry->attrKey = *nam; 00411 pCacheEntry->nSize = nSizeOfEntry; 00412 CacheSize += pCacheEntry->nSize; 00413 memcpy((char *)(pCacheEntry+1), TempRecord.attrText, len); 00414 ADD_ENTRY(pCacheEntry); 00415 hashaddLEN(nam, sizeof(Aname), pCacheEntry, 00416 &mudstate.acache_htab); 00417 00418 TrimCache(); 00419 } 00420 } 00421 return true; 00422 }
bool cache_sync | ( | void | ) |
Definition at line 424 of file attrcache.cpp.
References hfAttributeFile, and CHashFile::Sync().
00425 { 00426 hfAttributeFile.Sync(); 00427 return true; 00428 }
void cache_tick | ( | void | ) |
Definition at line 121 of file attrcache.cpp.
References hfAttributeFile, and CHashFile::Tick().
Referenced by dispatch_CacheTick().
00122 { 00123 hfAttributeFile.Tick(); 00124 }