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 "csextern.h" 00027 #include "bitarray.h" 00028 00029 struct iVFS; 00030 00032 const unsigned csmmioDefaultCacheBlockSize = 256; 00033 00035 const unsigned csmmioDefaultCacheSize = 256;//2048; 00036 00038 const unsigned csmmioDefaultHashSize = 211;//1559; 00039 00040 00072 class CS_CSUTIL_EXPORT csMemoryMappedIO 00073 { 00074 private: 00076 unsigned int block_size; 00077 00079 bool valid_mmio_object; 00080 00082 unsigned cache_block_size; 00083 00088 unsigned int cache_max_size; 00089 00091 unsigned int cache_block_count; 00092 00097 csBitArray *page_map; 00098 00099 #ifdef CS_DEBUG 00100 00101 public: 00103 unsigned int hits; 00104 00106 unsigned int misses; 00107 00108 private: 00109 #endif 00110 00112 struct CacheBlock 00113 { 00115 unsigned age; 00116 00118 unsigned offset; 00119 00121 unsigned page; 00122 00124 CacheBlock *next; 00125 00127 unsigned char *data; 00128 }; 00129 00131 CacheBlock *cache[csmmioDefaultHashSize]; 00132 00133 // Software specific mmioInfo struct, should only be defined for 00134 // platforms w/o hardware mmio. 00135 struct emulatedMmioInfo 00136 { 00138 FILE *hMappedFile; 00139 00141 unsigned char *data; 00142 00144 unsigned int file_size; 00145 } emulatedPlatform; 00146 00147 #ifdef CS_HAS_MEMORY_MAPPED_IO 00148 00149 mmioInfo platform; 00150 00152 bool valid_platform; 00153 #endif 00154 public: 00162 csMemoryMappedIO(unsigned _block_size, char const *filename, iVFS* vfs = 0); 00163 00167 csMemoryMappedIO::~csMemoryMappedIO(); 00168 00175 void *GetPointer(unsigned int index); 00176 00180 bool IsValid(); 00181 00182 private: 00184 void CachePage(unsigned int page); 00185 00187 bool SoftMemoryMapFile(emulatedMmioInfo *platform, char const *filename); 00188 00190 void SoftUnMemoryMapFile(emulatedMmioInfo *platform); 00191 }; 00192 00193 #endif // __CS_MEMORY_MAPPED_IO__ 00194
Generated for Crystal Space by doxygen 1.2.18