r851: Merge 2.1:
[cinelerra_cv/ct.git] / cinelerra / cache.h
blobeb8645d47d558ebf90cd66ae3724e6015aafb782
1 #ifndef CACHE_H
2 #define CACHE_H
4 // CICache for quickly reading data that is hard to decompress yet used
5 // over and over.
7 // Actual caching is done in the File object
8 // the CICache keeps files open while rendering.
10 // Since the CICache outlives EDLs it must copy every parameter given to it.
12 // Files given as arguments must outlive the cache.
14 #include "arraylist.h"
15 #include "asset.inc"
16 #include "cache.inc"
17 #include "edl.inc"
18 #include "file.inc"
19 #include "linklist.h"
20 #include "mutex.inc"
21 #include "pluginserver.inc"
22 #include "preferences.inc"
24 #include <stdint.h>
26 class CICacheItem : public ListItem<CICacheItem>
28 public:
29 CICacheItem(CICache *cache, File *file);
30 CICacheItem(CICache *cache, Asset *asset);
31 CICacheItem() {};
32 ~CICacheItem();
34 File *file;
35 int64_t counter; // number of age calls ago this asset was last needed
36 // assets used in the last render have counter == 1
37 Asset *asset; // Copy of asset. CICache should outlive EDLs.
38 Mutex *item_lock;
39 int checked_out;
40 private:
41 CICache *cache;
44 class CICache : public List<CICacheItem>
46 public:
47 CICache(EDL *edl,
48 Preferences *preferences,
49 ArrayList<PluginServer*> *plugindb);
50 ~CICache();
52 friend class CICacheItem;
54 // Enter a new file into the cache which is already open.
55 // If the file doesn't exist return the arguments.
56 // If the file exists delete the arguments and return the file which exists.
57 void update(File* &file);
58 void set_edl(EDL *edl);
60 // open it, lock it and add it to the cache if it isn't here already
61 File* check_out(Asset *asset);
63 // unlock a file from the cache
64 int check_in(Asset *asset);
66 // delete an entry from the cache
67 // before deleting an asset, starting a new project or something
68 int delete_entry(Asset *asset);
69 int delete_entry(char *path);
71 int64_t get_memory_usage(int use_lock);
74 // increment counters after rendering a buffer length
75 // since you can't know how big the cache is until after rendering the buffer
76 // deletes oldest assets until under the memory limit
77 int age();
80 int dump();
82 ArrayList<PluginServer*> *plugindb;
84 private:
85 // returns 1 if nothing was available to delete
86 // 0 if successful
87 int delete_oldest();
89 // for deleting items
90 int lock_all();
91 int unlock_all();
93 // to prevent one from checking the same asset out before it's checked in
94 // yet without blocking the asset trying to get checked in
95 // use a seperate mutex for checkouts and checkins
96 Mutex *check_in_lock, *check_out_lock, *total_lock;
97 // Copy of EDL
98 EDL *edl;
99 Preferences *preferences;
109 #endif