Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

pageframetable.h

Go to the documentation of this file.
00001 
00007 /*
00008  *  Copyright (C) 2003,2004,2005 Bregmasoft
00009  * 
00010  * This program is free software; you can redistribute it and/or modify it under
00011  * the terms of the GNU General Public License as published by the Free Software
00012  * Foundation; either version 2 of the License, or (at your option) any later
00013  * version.
00014  * 
00015  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
00016  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
00017  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU General Public License along with
00020  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021  * Place, Suite 330, Boston, MA 02111-1307 USA
00022  */
00023 #ifndef ZYGOMA_PAGEFRAMETABLE_H_ 
00024 #define ZYGOMA_PAGEFRAMETABLE_H_ 
00025 
00026 #include <cstddef>
00027 #include <iterator>
00028 #include <memory.h>
00029 #include <types.h>
00030 #include <pageframe.h>
00031 #include <spinlock.h>
00032 
00033 namespace Zygoma
00034 {
00041   class PageFrameTable;
00042 
00043   bool
00044   operator==(const PageFrameTable& lhs, const PageFrameTable& rhs);
00045 
00059   class PageFrameTableIterator
00060   {
00061   public:
00062     typedef std::random_access_iterator_tag iterator_category;
00063     typedef PageFrame                       value_type;
00064     typedef std::ptrdiff_t                  difference_type;
00065     typedef PageFrame*                      pointer;
00066     typedef PageFrame&                      reference;
00067 
00068   public:
00069 
00070     PageFrameTableIterator(PageFrameTable&, difference_type offset = 0);
00071 
00072     PageFrameTableIterator(const PageFrameTableIterator& rhs);
00073 
00074     PageFrameTableIterator&
00075     operator=(const PageFrameTableIterator& rhs);
00076 
00077     ~PageFrameTableIterator();
00078 
00082     reference
00083     operator*();
00084 
00088     reference
00089     operator[](difference_type);
00090 
00094     pointer
00095     operator->();
00096 
00105     PageFrameTableIterator&
00106     operator++();
00107 
00111     PageFrameTableIterator&
00112     operator++(int);
00113 
00117     PageFrameTableIterator&
00118     operator--();
00119 
00123     PageFrameTableIterator&
00124     operator--(int);
00125 
00129     PageFrameTableIterator&
00130     operator+=(difference_type);
00131 
00135     PageFrameTableIterator&
00136     operator-(difference_type);
00137 
00141     difference_type
00142     operator-(const PageFrameTableIterator&);
00143     /* @} */
00144 
00148     PhysicalAddress
00149     baseAddress() const;
00150 
00155     bool
00156     equals(const PageFrameTableIterator& rhs) const
00157     {
00158       return (m_pageFrameTable == rhs.m_pageFrameTable)
00159           && (m_currentOffset  == rhs.m_currentOffset);
00160     }
00161 
00162     bool
00163     lessThan(const PageFrameTableIterator& rhs) const
00164     {
00165       return (m_pageFrameTable == rhs.m_pageFrameTable)
00166           && (m_currentOffset  < rhs.m_currentOffset);
00167     }
00168     /* @} */
00169 
00170   private:
00171     PageFrameTable& m_pageFrameTable;
00172     difference_type m_currentOffset;
00173   };
00174 
00175 
00185   inline bool
00186   operator==(const PageFrameTableIterator& lhs,
00187              const PageFrameTableIterator& rhs)
00188   { return lhs.equals(rhs); }
00189 
00190 
00200   inline bool
00201   operator!=(const PageFrameTableIterator& lhs,
00202              const PageFrameTableIterator& rhs)
00203   { return !lhs.equals(rhs); }
00204 
00205 
00215   inline bool
00216   operator<(const PageFrameTableIterator& lhs,
00217             const PageFrameTableIterator& rhs)
00218   { return lhs.lessThan(rhs); }
00219 
00220 
00230   PageFrameTableIterator
00231   operator+(PageFrameTableIterator::difference_type n,
00232             const PageFrameTableIterator& i);
00233 
00234 
00244   PageFrameTableIterator
00245   operator+(const PageFrameTableIterator& i,
00246             PageFrameTableIterator::difference_type n);
00247 
00248 
00257   class PageFrameTable
00258   {
00259     friend class PageFrameTableIterator;
00260 
00261   public:
00266     typedef PageFrame                               value_type;
00267     typedef value_type*                             pointer;
00268     typedef const value_type*                       const_pointer;
00269     typedef value_type&                             reference;
00270     typedef const value_type&                       const_reference;
00271     typedef PageFrameTableIterator                  iterator;
00272     typedef const PageFrameTableIterator            const_iterator;
00273     typedef PageFrameTableIterator::difference_type difference_type;
00274     typedef std::size_t                             size_type;
00275     /* @} */
00276 
00277   public:
00281     static PageFrameTable*
00282     create(PhysicalAddress base, PhysicalAddress himem);
00283 
00287     size_type
00288     size() const;
00289 
00296     size_type
00297     max_size() const
00298     { return size(); }
00299 
00306     bool
00307     empty() const
00308     { return false; }
00309 
00318     iterator
00319     begin();
00320 
00321     const_iterator
00322     begin() const;
00323 
00328     iterator
00329     end();
00330 
00331     const_iterator
00332     end() const;
00333 
00334 #if 0
00335 // Replace with locking proxy returned from iterator?
00339     void
00340     markFrameUsed(FrameIndex frameNumber, int taskId);
00341 
00345     void
00346     markFrameUnused(FrameIndex frameNumber);
00347 #endif
00348 
00352     iterator
00353     find(PhysicalAddress address);
00354     /* @} */
00355 
00360     bool
00361     equals(const PageFrameTable& rhs) const
00362     { return &m_frame[0] == &rhs.m_frame[0]; }
00363     /* @} */
00364 
00365   private:
00370     PageFrameTable(size_type numFrames);
00371 
00372     PageFrameTable(const PageFrameTable&);
00373     PageFrameTable& operator=(const PageFrameTable&);
00374 
00375   private:
00376     size_type     m_numberOfFrames;
00377     SpinLockMutex m_spinLock;
00378     PageFrame     m_frame[1];
00379   };
00380 
00390   inline bool
00391   operator==(const PageFrameTable& lhs, const PageFrameTable& rhs)
00392   { return lhs.equals(rhs); }
00393 
00394 } // namespace Zygoma
00395 #endif // ZYGOMA_PAGEFRAMETABLE_H_ 

Generated on Fri Sep 2 10:44:36 2005 for zygoma by doxygen 1.4.2