# HG changeset patch # User peter1138 # Date 1145386130 0 # Node ID 43461f26b7293f6f7d11662fba0c40d77c914f58 # Parent 1af7d6e9d1bac508f85fcfa810c877f8c9207075 (svn r4471) - Pools: Add a facility for calling a custom function during pool block clean up. diff -r 1af7d6e9d1ba -r 43461f26b729 depot.c --- a/depot.c Tue Apr 18 18:02:52 2006 +0000 +++ b/depot.c Tue Apr 18 18:48:50 2006 +0000 @@ -28,7 +28,7 @@ } /* Initialize the town-pool */ -MemoryPool _depot_pool = { "Depots", DEPOT_POOL_MAX_BLOCKS, DEPOT_POOL_BLOCK_SIZE_BITS, sizeof(Depot), &DepotPoolNewBlock, 0, 0, NULL }; +MemoryPool _depot_pool = { "Depots", DEPOT_POOL_MAX_BLOCKS, DEPOT_POOL_BLOCK_SIZE_BITS, sizeof(Depot), &DepotPoolNewBlock, NULL, 0, 0, NULL }; /** diff -r 1af7d6e9d1ba -r 43461f26b729 engine.c --- a/engine.c Tue Apr 18 18:02:52 2006 +0000 +++ b/engine.c Tue Apr 18 18:48:50 2006 +0000 @@ -507,7 +507,7 @@ ENGINE_RENEW_POOL_MAX_BLOCKS = 8000, }; -MemoryPool _engine_renew_pool = { "EngineRe", ENGINE_RENEW_POOL_MAX_BLOCKS, ENGINE_RENEW_POOL_BLOCK_SIZE_BITS, sizeof(EngineRenew), &EngineRenewPoolNewBlock, 0, 0, NULL }; +MemoryPool _engine_renew_pool = { "EngineRe", ENGINE_RENEW_POOL_MAX_BLOCKS, ENGINE_RENEW_POOL_BLOCK_SIZE_BITS, sizeof(EngineRenew), &EngineRenewPoolNewBlock, NULL, 0, 0, NULL }; static inline uint16 GetEngineRenewPoolSize(void) { diff -r 1af7d6e9d1ba -r 43461f26b729 industry_cmd.c --- a/industry_cmd.c Tue Apr 18 18:02:52 2006 +0000 +++ b/industry_cmd.c Tue Apr 18 18:48:50 2006 +0000 @@ -38,7 +38,7 @@ } /* Initialize the industry-pool */ -MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, 0, 0, NULL }; +MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, NULL, 0, 0, NULL }; static byte _industry_sound_ctr; static TileIndex _industry_sound_tile; diff -r 1af7d6e9d1ba -r 43461f26b729 order_cmd.c --- a/order_cmd.c Tue Apr 18 18:02:52 2006 +0000 +++ b/order_cmd.c Tue Apr 18 18:48:50 2006 +0000 @@ -33,7 +33,7 @@ } /* Initialize the order-pool */ -MemoryPool _order_pool = { "Orders", ORDER_POOL_MAX_BLOCKS, ORDER_POOL_BLOCK_SIZE_BITS, sizeof(Order), &OrderPoolNewBlock, 0, 0, NULL }; +MemoryPool _order_pool = { "Orders", ORDER_POOL_MAX_BLOCKS, ORDER_POOL_BLOCK_SIZE_BITS, sizeof(Order), &OrderPoolNewBlock, NULL, 0, 0, NULL }; /** * diff -r 1af7d6e9d1ba -r 43461f26b729 pool.c --- a/pool.c Tue Apr 18 18:02:52 2006 +0000 +++ b/pool.c Tue Apr 18 18:48:50 2006 +0000 @@ -16,8 +16,12 @@ DEBUG(misc, 4)("[Pool] (%s) Cleaning pool..", pool->name); /* Free all blocks */ - for (i = 0; i < pool->current_blocks; i++) + for (i = 0; i < pool->current_blocks; i++) { + if (pool->clean_block_proc != NULL) { + pool->clean_block_proc(i * (1 << pool->block_size_bits), (i + 1) * (1 << pool->block_size_bits) - 1); + } free(pool->blocks[i]); + } /* Free the block itself */ free(pool->blocks); diff -r 1af7d6e9d1ba -r 43461f26b729 pool.h --- a/pool.h Tue Apr 18 18:02:52 2006 +0000 +++ b/pool.h Tue Apr 18 18:48:50 2006 +0000 @@ -8,6 +8,8 @@ /* The function that is called after a new block is added start_item is the first item of the new made block */ typedef void MemoryPoolNewBlock(uint start_item); +/* The function that is called before a block is cleaned up */ +typedef void MemoryPoolCleanBlock(uint start_item, uint end_item); /** * Stuff for dynamic vehicles. Use the wrappers to access the MemoryPool @@ -22,6 +24,8 @@ /// Pointer to a function that is called after a new block is added MemoryPoolNewBlock *new_block_proc; + /// Pointer to a function that is called to clean a block + MemoryPoolCleanBlock *clean_block_proc; uint current_blocks; ///< How many blocks we have in our pool uint total_items; ///< How many items we now have in this pool diff -r 1af7d6e9d1ba -r 43461f26b729 saveload.c --- a/saveload.c Tue Apr 18 18:02:52 2006 +0000 +++ b/saveload.c Tue Apr 18 18:48:50 2006 +0000 @@ -1021,7 +1021,7 @@ } ThreadedSave; /* A maximum size of of 128K * 500 = 64.000KB savegames */ -static MemoryPool _save_pool = {"Savegame", SAVE_POOL_MAX_BLOCKS, SAVE_POOL_BLOCK_SIZE_BITS, sizeof(byte), NULL, 0, 0, NULL}; +static MemoryPool _save_pool = {"Savegame", SAVE_POOL_MAX_BLOCKS, SAVE_POOL_BLOCK_SIZE_BITS, sizeof(byte), NULL, NULL, 0, 0, NULL}; static ThreadedSave _ts; static bool InitMem(void) diff -r 1af7d6e9d1ba -r 43461f26b729 signs.c --- a/signs.c Tue Apr 18 18:02:52 2006 +0000 +++ b/signs.c Tue Apr 18 18:48:50 2006 +0000 @@ -30,7 +30,7 @@ } /* Initialize the sign-pool */ -MemoryPool _sign_pool = { "Signs", SIGN_POOL_MAX_BLOCKS, SIGN_POOL_BLOCK_SIZE_BITS, sizeof(SignStruct), &SignPoolNewBlock, 0, 0, NULL }; +MemoryPool _sign_pool = { "Signs", SIGN_POOL_MAX_BLOCKS, SIGN_POOL_BLOCK_SIZE_BITS, sizeof(SignStruct), &SignPoolNewBlock, NULL, 0, 0, NULL }; /** * diff -r 1af7d6e9d1ba -r 43461f26b729 station_cmd.c --- a/station_cmd.c Tue Apr 18 18:02:52 2006 +0000 +++ b/station_cmd.c Tue Apr 18 18:48:50 2006 +0000 @@ -61,8 +61,8 @@ } /* Initialize the station-pool and roadstop-pool */ -MemoryPool _station_pool = { "Stations", STATION_POOL_MAX_BLOCKS, STATION_POOL_BLOCK_SIZE_BITS, sizeof(Station), &StationPoolNewBlock, 0, 0, NULL }; -MemoryPool _roadstop_pool = { "RoadStop", ROADSTOP_POOL_MAX_BLOCKS, ROADSTOP_POOL_BLOCK_SIZE_BITS, sizeof(RoadStop), &RoadStopPoolNewBlock, 0, 0, NULL }; +MemoryPool _station_pool = { "Stations", STATION_POOL_MAX_BLOCKS, STATION_POOL_BLOCK_SIZE_BITS, sizeof(Station), &StationPoolNewBlock, NULL, 0, 0, NULL }; +MemoryPool _roadstop_pool = { "RoadStop", ROADSTOP_POOL_MAX_BLOCKS, ROADSTOP_POOL_BLOCK_SIZE_BITS, sizeof(RoadStop), &RoadStopPoolNewBlock, NULL, 0, 0, NULL }; // FIXME -- need to be embedded into Airport variable. Is dynamically diff -r 1af7d6e9d1ba -r 43461f26b729 town_cmd.c --- a/town_cmd.c Tue Apr 18 18:02:52 2006 +0000 +++ b/town_cmd.c Tue Apr 18 18:48:50 2006 +0000 @@ -45,7 +45,7 @@ } /* Initialize the town-pool */ -MemoryPool _town_pool = { "Towns", TOWN_POOL_MAX_BLOCKS, TOWN_POOL_BLOCK_SIZE_BITS, sizeof(Town), &TownPoolNewBlock, 0, 0, NULL }; +MemoryPool _town_pool = { "Towns", TOWN_POOL_MAX_BLOCKS, TOWN_POOL_BLOCK_SIZE_BITS, sizeof(Town), &TownPoolNewBlock, NULL, 0, 0, NULL }; // Local static int _grow_town_result; diff -r 1af7d6e9d1ba -r 43461f26b729 vehicle.c --- a/vehicle.c Tue Apr 18 18:02:52 2006 +0000 +++ b/vehicle.c Tue Apr 18 18:48:50 2006 +0000 @@ -80,7 +80,7 @@ } /* Initialize the vehicle-pool */ -MemoryPool _vehicle_pool = { "Vehicle", VEHICLES_POOL_MAX_BLOCKS, VEHICLES_POOL_BLOCK_SIZE_BITS, sizeof(Vehicle), &VehiclePoolNewBlock, 0, 0, NULL }; +MemoryPool _vehicle_pool = { "Vehicle", VEHICLES_POOL_MAX_BLOCKS, VEHICLES_POOL_BLOCK_SIZE_BITS, sizeof(Vehicle), &VehiclePoolNewBlock, NULL, 0, 0, NULL }; void VehicleServiceInDepot(Vehicle *v) { diff -r 1af7d6e9d1ba -r 43461f26b729 waypoint.c --- a/waypoint.c Tue Apr 18 18:02:52 2006 +0000 +++ b/waypoint.c Tue Apr 18 18:48:50 2006 +0000 @@ -39,7 +39,7 @@ } /* Initialize the town-pool */ -MemoryPool _waypoint_pool = { "Waypoints", WAYPOINT_POOL_MAX_BLOCKS, WAYPOINT_POOL_BLOCK_SIZE_BITS, sizeof(Waypoint), &WaypointPoolNewBlock, 0, 0, NULL }; +MemoryPool _waypoint_pool = { "Waypoints", WAYPOINT_POOL_MAX_BLOCKS, WAYPOINT_POOL_BLOCK_SIZE_BITS, sizeof(Waypoint), &WaypointPoolNewBlock, NULL, 0, 0, NULL }; /* Create a new waypoint */ static Waypoint* AllocateWaypoint(void)