| 1859 | |
| 1860 | |
| 1861 | bool |
| 1862 | ImageCacheImpl::find_tile_main_cache (const TileID &id, ImageCacheTileRef &tile, |
| 1863 | ImageCachePerThreadInfo *thread_info) |
| 1864 | { |
| 1865 | DASSERT (! id.file().broken()); |
| 1866 | ImageCacheStatistics &stats (thread_info->m_stats); |
| 1867 | |
| 1868 | ++stats.find_tile_microcache_misses; |
| 1869 | |
| 1870 | { |
| 1871 | #if IMAGECACHE_TIME_STATS |
| 1872 | Timer timer1; |
| 1873 | #endif |
| 1874 | TileCache::iterator found = m_tilecache.find (id); |
| 1875 | #if IMAGECACHE_TIME_STATS |
| 1876 | stats.find_tile_time += timer1(); |
| 1877 | #endif |
| 1878 | if (found) { |
| 1879 | tile = (*found).second; |
| 1880 | found.unlock(); // release the lock |
| 1881 | // We found the tile in the cache, but we need to make sure we |
| 1882 | // wait until the pixels are ready to read. We purposely have |
| 1883 | // released the lock (above) before calling wait_pixels_ready, |
| 1884 | // otherwise we could deadlock if another thread reading the |
| 1885 | // pixels needs to lock the cache because it's doing automip. |
| 1886 | tile->wait_pixels_ready (); |
| 1887 | tile->use (); |
| 1888 | DASSERT (id == tile->id()); |
| 1889 | DASSERT (tile); |
| 1890 | return true; |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | // The tile was not found in cache. |
| 1895 | |
| 1896 | ++stats.find_tile_cache_misses; |
| 1897 | |
| 1898 | // Yes, we're creating and reading a tile with no lock -- this is to |
| 1899 | // prevent all the other threads from blocking because of our |
| 1900 | // expensive disk read. We believe this is safe, since underneath |
| 1901 | // the ImageCacheFile will lock itself for the read_tile and there are |
| 1902 | // no other non-threadsafe side effects. |
| 1903 | Timer timer; |
| 1904 | tile = new ImageCacheTile (id, thread_info, m_read_before_insert); |
| 1905 | // N.B. the ImageCacheTile ctr starts the tile out as 'used' |
| 1906 | DASSERT (tile); |
| 1907 | DASSERT (id == tile->id()); |
| 1908 | double readtime = timer(); |
| 1909 | stats.fileio_time += readtime; |
| 1910 | id.file().iotime() += readtime; |
| 1911 | |
| 1912 | add_tile_to_cache (tile, thread_info); |
| 1913 | DASSERT (id == tile->id()); |
| 1914 | return tile->valid(); |
| 1915 | } |
| 1916 | |
| 1917 | |
| 1918 |
nothing calls this directly
no test coverage detected