4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // CICache for quickly reading data that is hard to decompress yet used
28 // Actual caching is done in the File object
29 // the CICache keeps files open while rendering.
31 // Since the CICache outlives EDLs it must copy every parameter given to it.
33 // Files given as arguments must outlive the cache.
37 #include "condition.inc"
43 #include "preferences.inc"
47 class CICacheItem : public Garbage, public ListItem<CICacheItem>
50 CICacheItem(CICache *cache, EDL *edl, Asset *asset);
55 // Number of last get or put operation involving this object.
57 Asset *asset; // Copy of asset. CICache should outlive EDLs.
59 long checked_out; // thread id of owner
64 class CICache : public List<CICacheItem>
67 CICache(Preferences *preferences);
70 friend class CICacheItem;
72 // Enter a new file into the cache which is already open.
73 // If the file doesn't exist return the arguments.
74 // If the file exists delete the arguments and return the file which exists.
75 // void update(File* &file);
76 // void set_edl(EDL *edl);
78 // open it, lock it and add it to the cache if it isn't here already
79 // If it's already checked out, the value of block causes it to wait
80 // until it's checked in.
81 File* check_out(Asset *asset, EDL *edl, int block = 1);
83 // unlock a file from the cache
84 int check_in(Asset *asset);
86 // delete an entry from the cache
87 // before deleting an asset, starting a new project or something
88 int delete_entry(Asset *asset);
89 int delete_entry(char *path);
90 // Remove all entries from the cache.
93 // Get ID of oldest member.
94 // Called by MWindow::age_caches.
96 int64_t get_memory_usage(int use_lock);
98 // Called by age() and MWindow::age_caches
99 // returns 1 if nothing was available to delete
103 // Called by check_in() and modules.
104 // deletes oldest assets until under the memory limit
113 // for deleting items
117 // to prevent one from checking the same asset out before it's checked in
118 // yet without blocking the asset trying to get checked in
119 // use a seperate mutex for checkouts and checkins
121 Condition *check_out_lock;
124 Preferences *preferences;