Changeset 506


Ignore:
Timestamp:
Apr 18, 2011, 3:37:17 PM (6 years ago)
Author:
sam
Message:

cache: get rid of more Lisp cache code.

Location:
abuse/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/cache.cpp

    r505 r506  
    3333#include "specache.h"
    3434#include "netface.h"
    35 
    36 char lfname[100]="";          // name of compiled lisp code cache file
    3735
    3836#define touch(x) { (x)->last_access=last_access++; \
     
    666664}
    667665
    668 static void cache_cleanup2()
    669 { unlink(lfname);
    670 }
    671 
    672 static void cache_cleanup(int ret, void *arg)
    673 { unlink(lfname);
    674 }
    675 
    676 void CacheList::create_lcache()
    677 {
    678 #ifdef WIN32
    679     char *prefix="c:\\";
    680 #else
    681     char const *prefix = "/tmp/";     // for UNIX store lisp cache in tmp dir
    682     int flags = O_CREAT | O_RDWR;
    683 #endif
    684 
    685     int cfail = 1, num = 0;
    686     do
    687     {
    688         sprintf(lfname,"%slcache%02d.tmp",prefix,num);
    689 
    690 #if defined( __APPLE__ )
    691         unlink(lfname);
    692         FILE *fp=fopen(lfname,"wb");
    693         if (fp)
    694         {
    695             fclose(fp);
    696             cfail=0;
    697         }
    698 #else
    699         int fd=open(lfname,flags,S_IRWXU | S_IRWXG | S_IRWXO);     // can we get exclusive rights to this file?
    700         if (fd<0) close(fd); else cfail=0;
    701 #endif
    702 
    703         if (cfail)
    704             num++;
    705 
    706     } while (cfail && num<15);
    707 
    708     if (cfail)
    709     {
    710         fprintf(stderr,"Error : Unable to open cache file for compiled code.\n"
    711             "        Please delete all files named lcacheXX.tmp\n"
    712             "        and make sure you have write permission to\n"
    713             "        directory (%s)\n",prefix);
    714         exit(0);
    715     }
    716     else
    717     {
    718         exit_proc(cache_cleanup,cache_cleanup2);    // make sure this file gets deleted on exit..
    719     }
    720     lcache_number=-1;
    721 }
    722 
    723666CacheList::CacheList()
    724667{
    725   // start out with a decent sized cache buffer because it's going to get allocated anyway.
    726   total=0;
    727   list=NULL;
    728   last_registered=-1;
    729   cache_file=fp=NULL;
    730   last_access=1;
    731   used=ful=0;
    732   last_dir=NULL;
    733   last_file=-1;
    734   prof_data=NULL;
    735   cache_read_file=NULL;
    736   create_lcache();
     668    // Start out with a decent sized cache buffer because it's going to
     669    // get allocated anyway.
     670    total = 0;
     671    list = NULL;
     672    last_registered = -1;
     673    fp = NULL;
     674    last_access = 1;
     675    used = ful = 0;
     676    last_dir = NULL;
     677    last_file = -1;
     678    prof_data = NULL;
    737679}
    738680
     
    751693  if (fp) delete fp;
    752694  if (last_dir) delete last_dir;
    753   if (cache_file)
    754   {
    755     delete cache_file;
    756     cache_file=NULL;
    757   }
    758   unlink(lfname);
    759695
    760696  if (prof_data)
     
    767703  list=NULL;
    768704  last_registered=-1;
    769   cache_file=fp=NULL;
    770   if (cache_read_file)
    771   {
    772     delete cache_read_file;
    773     cache_read_file=NULL;
    774   }
     705  fp=NULL;
    775706
    776707  last_access=1;
  • abuse/trunk/src/cache.h

    r503 r506  
    8484    int16_t last_file; // for speed leave the last file accessed open
    8585
    86     bFILE *fp,*cache_file,*cache_read_file;
     86    bFILE *fp;
    8787    spec_directory *last_dir;
    8888    int32_t last_offset; // store the last offset so we don't have to seek if
    8989                         // we don't need to
    90 
    91     int16_t lcache_number;
    9290
    9391    int AllocId();
     
    105103    ~CacheList();
    106104
    107     void create_lcache();
    108105    void free_oldest();
    109106    int in_use() { if (used) { used = 0; return 1; } else return 0; }
Note: See TracChangeset for help on using the changeset viewer.