csutil/mmapio.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2002 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_MEMORY_MAPPED_IO__ 00020 #define __CS_MEMORY_MAPPED_IO__ 00021 00026 #include "bitarray.h" 00027 00028 struct iVFS; 00029 00031 const unsigned csmmioDefaultCacheBlockSize = 256; 00032 00034 const unsigned csmmioDefaultCacheSize = 256;//2048; 00035 00037 const unsigned csmmioDefaultHashSize = 211;//1559; 00038 00039 00071 class csMemoryMappedIO 00072 { 00073 private: 00075 unsigned int block_size; 00076 00078 bool valid_mmio_object; 00079 00081 unsigned cache_block_size; 00082 00087 unsigned int cache_max_size; 00088 00090 unsigned int cache_block_count; 00091 00096 csBitArray *page_map; 00097 00098 #ifdef CS_DEBUG 00099 00100 public: 00102 unsigned int hits; 00103 00105 unsigned int misses; 00106 00107 private: 00108 #endif 00109 00111 struct CacheBlock 00112 { 00114 unsigned age; 00115 00117 unsigned offset; 00118 00120 unsigned page; 00121 00123 CacheBlock *next; 00124 00126 unsigned char *data; 00127 }; 00128 00130 CacheBlock *cache[csmmioDefaultHashSize]; 00131 00132 // Software specific mmioInfo struct, should only be defined for 00133 // platforms w/o hardware mmio. 00134 struct emulatedMmioInfo 00135 { 00137 FILE *hMappedFile; 00138 00140 unsigned char *data; 00141 00143 unsigned int file_size; 00144 } emulatedPlatform; 00145 00146 #ifdef CS_HAS_MEMORY_MAPPED_IO 00147 00148 mmioInfo platform; 00149 00151 bool valid_platform; 00152 #endif 00153 public: 00161 csMemoryMappedIO(unsigned _block_size, char const *filename, iVFS* vfs = 0); 00162 00166 csMemoryMappedIO::~csMemoryMappedIO(); 00167 00174 void *GetPointer(unsigned int index); 00175 00179 bool IsValid(); 00180 00181 private: 00183 void CachePage(unsigned int page); 00184 00186 bool SoftMemoryMapFile(emulatedMmioInfo *platform, char const *filename); 00187 00189 void SoftUnMemoryMapFile(emulatedMmioInfo *platform); 00190 }; 00191 00192 #endif // __CS_MEMORY_MAPPED_IO__ 00193
Generated for Crystal Space by doxygen 1.2.18