| 1917 | |
| 1918 | |
| 1919 | void |
| 1920 | ImageCacheImpl::add_tile_to_cache (ImageCacheTileRef &tile, |
| 1921 | ImageCachePerThreadInfo *thread_info) |
| 1922 | { |
| 1923 | bool ourtile = true; |
| 1924 | { |
| 1925 | // Protect us from using too much memory if another thread added the |
| 1926 | // same tile just before us |
| 1927 | TileCache::iterator found = m_tilecache.find (tile->id()); |
| 1928 | if (found != m_tilecache.end ()) { |
| 1929 | // Already added! Use the other one, discard ours. |
| 1930 | tile = (*found).second; |
| 1931 | found.unlock (); |
| 1932 | ourtile = false; // Don't need to add it |
| 1933 | } else { |
| 1934 | // Still not in cache, add ours to the cache. |
| 1935 | // N.B. at this time, we do not hold any locks. |
| 1936 | check_max_mem (thread_info); |
| 1937 | m_tilecache.insert (tile->id(), tile); |
| 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | // At this point, we no longer have the write lock, and we are no |
| 1942 | // longer modifying the cache itself. However, if we added a new |
| 1943 | // tile to the cache, we may still need to read the pixels; and if |
| 1944 | // we found the tile in cache, we may need to wait for somebody else |
| 1945 | // to read the pixels. |
| 1946 | if (ourtile) { |
| 1947 | if (! tile->pixels_ready ()) { |
| 1948 | Timer timer; |
| 1949 | tile->read (thread_info); |
| 1950 | double readtime = timer(); |
| 1951 | thread_info->m_stats.fileio_time += readtime; |
| 1952 | tile->id().file().iotime() += readtime; |
| 1953 | } |
| 1954 | } else { |
| 1955 | tile->wait_pixels_ready (); |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | |
| 1960 |
no test coverage detected