00001 #ifndef CACHE_H 00002 #define CACHE_H 00003 00004 // CICache for quickly reading data that is hard to decompress yet used 00005 // over and over. 00006 00007 // Actual caching is done in the File object 00008 // the CICache keeps files open while rendering. 00009 00010 // Since the CICache outlives EDLs it must copy every parameter given to it. 00011 00012 // Files given as arguments must outlive the cache. 00013 00014 #include "arraylist.h" 00015 #include "asset.inc" 00016 #include "cache.inc" 00017 #include "edl.inc" 00018 #include "file.inc" 00019 #include "linklist.h" 00020 #include "mutex.inc" 00021 #include "pluginserver.inc" 00022 #include "preferences.inc" 00023 00024 #include <stdint.h> 00025 00026 class CICacheItem : public ListItem<CICacheItem> 00027 { 00028 public: 00029 CICacheItem(CICache *cache, File *file); 00030 CICacheItem(CICache *cache, Asset *asset); 00031 CICacheItem() {}; 00032 ~CICacheItem(); 00033 00034 File *file; 00035 int64_t counter; // number of age calls ago this asset was last needed 00036 // assets used in the last render have counter == 1 00037 Asset *asset; // Copy of asset. CICache should outlive EDLs. 00038 Mutex *item_lock; 00039 int checked_out; 00040 private: 00041 CICache *cache; 00042 }; 00043 00044 class CICache : public List<CICacheItem> 00045 { 00046 public: 00047 CICache(EDL *edl, 00048 Preferences *preferences, 00049 ArrayList<PluginServer*> *plugindb); 00050 ~CICache(); 00051 00052 friend class CICacheItem; 00053 00054 // Enter a new file into the cache which is already open. 00055 // If the file doesn't exist return the arguments. 00056 // If the file exists delete the arguments and return the file which exists. 00057 void update(File* &file); 00058 void set_edl(EDL *edl); 00059 00060 // open it, lock it and add it to the cache if it isn't here already 00061 File* check_out(Asset *asset); 00062 00063 // unlock a file from the cache 00064 int check_in(Asset *asset); 00065 00066 // delete an entry from the cache 00067 // before deleting an asset, starting a new project or something 00068 int delete_entry(Asset *asset); 00069 int delete_entry(char *path); 00070 00071 // increment counters after rendering a buffer length 00072 // since you can't know how big the cache is until after rendering the buffer 00073 // deletes oldest assets until under the memory limit 00074 int age(); 00075 00076 int dump(); 00077 00078 ArrayList<PluginServer*> *plugindb; 00079 00080 private: 00081 // returns 1 if nothing was available to delete 00082 // 0 if successful 00083 int delete_oldest(); 00084 int64_t get_memory_usage(); 00085 00086 // for deleting items 00087 int lock_all(); 00088 int unlock_all(); 00089 00090 // to prevent one from checking the same asset out before it's checked in 00091 // yet without blocking the asset trying to get checked in 00092 // use a seperate mutex for checkouts and checkins 00093 Mutex *check_in_lock, *check_out_lock, *total_lock; 00094 // Copy of EDL 00095 EDL *edl; 00096 Preferences *preferences; 00097 }; 00098 00099 00100 00101 00102 00103 00104 00105 00106 #endif
1.4.4