~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/file_pool.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#endif
39
39
 
40
40
#include <boost/filesystem/path.hpp>
41
 
#include <boost/multi_index_container.hpp>
42
 
#include <boost/multi_index/member.hpp>
43
 
#include <boost/multi_index/ordered_index.hpp>
44
41
#include <boost/shared_ptr.hpp>
45
42
#include <boost/thread.hpp>
46
43
 
53
50
 
54
51
namespace libtorrent
55
52
{
56
 
 
57
 
        using boost::multi_index::multi_index_container;
58
 
        using boost::multi_index::ordered_non_unique;
59
 
        using boost::multi_index::ordered_unique;
60
 
        using boost::multi_index::indexed_by;
61
 
        using boost::multi_index::member;
62
53
        namespace fs = boost::filesystem;
63
54
 
64
55
        struct TORRENT_EXPORT file_pool : boost::noncopyable
65
56
        {
66
 
                file_pool(int size = 40): m_size(size) {}
 
57
                file_pool(int size = 40): m_size(size), m_low_prio_io(true) {}
67
58
 
68
59
                boost::shared_ptr<file> open_file(void* st, fs::path const& p
69
 
                        , file::open_mode m, error_code& ec);
 
60
                        , int m, error_code& ec);
70
61
                void release(void* st);
71
62
                void release(fs::path const& p);
72
63
                void resize(int size);
 
64
                int size_limit() const { return m_size; }
 
65
                void set_low_prio_io(bool b) { m_low_prio_io = b; }
73
66
 
74
67
        private:
 
68
                file_pool(file_pool const&);
 
69
 
 
70
                void remove_oldest();
 
71
 
75
72
                int m_size;
 
73
                bool m_low_prio_io;
76
74
 
77
75
                struct lru_file_entry
78
76
                {
79
77
                        lru_file_entry(): last_use(time_now()) {}
80
78
                        mutable boost::shared_ptr<file> file_ptr;
81
 
                        fs::path file_path;
82
79
                        void* key;
83
80
                        ptime last_use;
84
 
                        file::open_mode mode;
 
81
                        int mode;
85
82
                };
86
83
 
87
 
                typedef multi_index_container<
88
 
                        lru_file_entry, indexed_by<
89
 
                                ordered_unique<member<lru_file_entry, fs::path
90
 
                                        , &lru_file_entry::file_path> >
91
 
                                , ordered_non_unique<member<lru_file_entry, ptime
92
 
                                        , &lru_file_entry::last_use> >
93
 
                                , ordered_non_unique<member<lru_file_entry, void*
94
 
                                        , &lru_file_entry::key> >
95
 
                                > 
96
 
                        > file_set;
 
84
                typedef std::map<std::string, lru_file_entry> file_set;
97
85
                
98
86
                file_set m_files;
99
87
                boost::mutex m_mutex;