The core of the predictive file cacheing thread must keep a priority queue of filenames to load, and a queue of files to save to disk. It would have a file request function like

    void fetch_file( filename fn, time t );

where fn is a filename (whether std::string or char*, I don’t care right now), and where time is the estimate time at which the client predicts it will need the file. The file cacher will try to fetch it earlier. ASAP, in fact. But if the load on the disk drive is heavy, requests will be prioritiezed by time. Calls to this function will come from many threads, therefore it must have a thread-safe way of queueing up requests.

The name of the function should convey the fact that it does NOT return a handle to the file. Another function does that:

    fhandle get_file( filename, mode ) const;

‘fhandle’ is a type coming from findshare.hpp, that implements ref-count handles on objects and resources. When the file cacher successfully fetches the file, it acquires a first fhandle to it, to keep the file alive. The handle has a time-out, however. The requester of the file has up to, say, 5 seconds to take delivery of the fhandle by calling get_file() with the same name as it priorly called fetch_file() with.

When it does, the file cacher gives its own handle to it, so now the lifetime of that file remaining open depends on the client.

If get_file() is called without prior call to fetch_file(), the file won’t have been precached. Calls to get_file() are considered urgent, however, and reading this file from disk will be done ahead of any pending requests in the queue.

The file-writer part of this class also maintains a queue of files to retire. However, writing to disk is considered less urgent, and is done during periods of low or no file reading activity.


At a higher level, the above kernel could be wrapped into a model, composite, scene -precacheing disk manager.

 
deep/thrd/thrd_pfl.txt · Last modified: 2006/10/08 01:11 by chuck_starchaser