From 2051770c91c98e55b3cc012f00950e464c196cd1 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 25 Apr 2003 18:21:49 +0000 Subject: [PATCH] Synchronize access to the tile cache so that we can load tiles on other threads. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2460 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/media/tile/TileSet.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/java/com/threerings/media/tile/TileSet.java b/src/java/com/threerings/media/tile/TileSet.java index a891d1e27..6dc2269b6 100644 --- a/src/java/com/threerings/media/tile/TileSet.java +++ b/src/java/com/threerings/media/tile/TileSet.java @@ -1,5 +1,5 @@ // -// $Id: TileSet.java,v 1.46 2003/04/05 01:52:58 mdb Exp $ +// $Id: TileSet.java,v 1.47 2003/04/25 18:21:49 mdb Exp $ package com.threerings.media.tile; @@ -184,23 +184,17 @@ public abstract class TileSet */ public Tile getTile (int tileIndex, Colorization[] zations) { - // create our tile cache if necessary - if (_tiles == null) { - int tcsize = _cacheSize.getValue(); - Log.debug("Creating tile cache [size=" + tcsize + "k]."); - _tiles = new LRUHashMap(tcsize*1024, new LRUHashMap.ItemSizer() { - public int computeSize (Object value) { - return (int)((Tile)value).getEstimatedMemoryUsage(); - } - }); - } - TileKey key = new TileKey(this, tileIndex, zations); - Tile tile = (Tile)_tiles.get(key); + Tile tile = null; + synchronized (_tiles) { + tile = (Tile)_tiles.get(key); + } if (tile == null) { tile = createTile(tileIndex, getTileMirage(tileIndex, zations)); initTile(tile); - _tiles.put(key, tile); + synchronized (_tiles) { + _tiles.put(key, tile); + } } return tile; @@ -413,4 +407,14 @@ public abstract class TileSet "Size (in kb of memory used) of the tile LRU cache " + "[requires restart]", "narya.media.tile.cache_size", MediaPrefs.config, 1024); + + static { + int tcsize = _cacheSize.getValue(); + Log.debug("Creating tile cache [size=" + tcsize + "k]."); + _tiles = new LRUHashMap(tcsize*1024, new LRUHashMap.ItemSizer() { + public int computeSize (Object value) { + return (int)((Tile)value).getEstimatedMemoryUsage(); + } + }); + } }