Merge branch 'master' of git://git.pipapo.org/cinelerra/svn into ct
[cinelerra_cv/ct.git] / cinelerra / cache.h
blob14846629e62a9b4b4181ead7f621b3d0bfc4b941
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 "condition.inc"
18 #include "edl.inc"
19 #include "file.inc"
20 #include "garbage.h"
21 #include "linklist.h"
22 #include "mutex.inc"
23 #include "pluginserver.inc"
24 #include "preferences.inc"
26 #include <stdint.h>
28 class CICacheItem : public ListItem<CICacheItem>, public GarbageObject
30 public:
31 CICacheItem(CICache *cache, EDL *edl, Asset_GC asset);
32 CICacheItem();
33 ~CICacheItem();
35 File *file;
36 // Number of last get or put operation involving this object.
37 int age;
38 Asset_GC asset; // Copy of asset. CICache should outlive EDLs.
39 Condition *item_lock;
40 int checked_out;
41 private:
42 CICache *cache;
45 class CICache : public List<CICacheItem>
47 public:
48 CICache(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 // If it's already checked out, the value of block causes it to wait
62 // until it's checked in.
63 File* check_out(Asset_GC asset, EDL *edl, int block = 1);
65 // unlock a file from the cache
66 int check_in(Asset_GC asset);
68 // delete an entry from the cache
69 // before deleting an asset, starting a new project or something
70 int delete_entry(Asset_GC asset);
71 int delete_entry(char *path);
72 // Remove all entries from the cache.
73 void remove_all();
75 // Get ID of oldest member.
76 // Called by MWindow::age_caches.
77 int get_oldest();
78 int64_t get_memory_usage(int use_lock);
80 // Called by age() and MWindow::age_caches
81 // returns 1 if nothing was available to delete
82 // 0 if successful
83 int delete_oldest();
85 // Called by check_in() and modules.
86 // deletes oldest assets until under the memory limit
87 int age();
90 int dump();
92 ArrayList<PluginServer*> *plugindb;
94 private:
96 // for deleting items
97 int lock_all();
98 int unlock_all();
100 // to prevent one from checking the same asset out before it's checked in
101 // yet without blocking the asset trying to get checked in
102 // use a seperate mutex for checkouts and checkins
103 Mutex *total_lock;
104 Condition *check_out_lock;
105 // Copy of EDL
106 EDL *edl;
107 Preferences *preferences;
117 #endif
119 // Local Variables:
120 // mode: C++
121 // c-file-style: "linux"
122 // End: