mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-05 22:04:57 +00:00
(svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
This commit is contained in:
parent
1bd5a29df5
commit
6af1fb2bdd
@ -1187,6 +1187,10 @@
|
||||
RelativePath=".\..\src\oldpool.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\oldpool_func.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\openttd.h"
|
||||
>
|
||||
|
@ -1184,6 +1184,10 @@
|
||||
RelativePath=".\..\src\oldpool.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\oldpool_func.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\..\src\openttd.h"
|
||||
>
|
||||
|
@ -205,6 +205,7 @@ music/null_m.h
|
||||
sound/null_s.h
|
||||
video/null_v.h
|
||||
oldpool.h
|
||||
oldpool_func.h
|
||||
openttd.h
|
||||
order_base.h
|
||||
order_func.h
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "station_base.h"
|
||||
#include "cargopacket.h"
|
||||
#include "saveload.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
/* Initialize the cargopacket-pool */
|
||||
DEFINE_OLD_POOL_GENERIC(CargoPacket, CargoPacket)
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "saveload.h"
|
||||
#include "order_func.h"
|
||||
#include "window_func.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "autoreplace_gui.h"
|
||||
#include "string_func.h"
|
||||
#include "settings_type.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/engines.h"
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "string_func.h"
|
||||
#include "player_func.h"
|
||||
#include "order_func.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "vehicle_func.h"
|
||||
#include "sound_func.h"
|
||||
#include "station_base.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/sprites.h"
|
||||
|
@ -260,32 +260,7 @@ struct PoolItem {
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Allocate a pool item; possibly allocate a new block in the pool.
|
||||
* @param first the first pool item to start searching
|
||||
* @pre first <= Tpool->GetSize()
|
||||
* @return the allocated pool item (or NULL when the pool is full).
|
||||
*/
|
||||
static inline T *AllocateSafeRaw(uint &first)
|
||||
{
|
||||
uint last_minus_one = Tpool->GetSize() - 1;
|
||||
|
||||
for (T *t = Tpool->Get(first); t != NULL; t = (t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
|
||||
if (!t->IsValid()) {
|
||||
first = t->index;
|
||||
Tid index = t->index;
|
||||
|
||||
memset(t, 0, Tpool->item_size);
|
||||
t->index = index;
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if we can add a block to the pool */
|
||||
if (Tpool->AddBlockToPool()) return AllocateRaw(first);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
static T *AllocateSafeRaw(uint &first);
|
||||
|
||||
protected:
|
||||
/**
|
||||
@ -346,7 +321,8 @@ protected:
|
||||
#define DEFINE_OLD_POOL_GENERIC(name, type) \
|
||||
OldMemoryPool<type> _##name##_pool( \
|
||||
#name, name##_POOL_MAX_BLOCKS, name##_POOL_BLOCK_SIZE_BITS, sizeof(type), \
|
||||
PoolNewBlock<type, &_##name##_pool>, PoolCleanBlock<type, &_##name##_pool>);
|
||||
PoolNewBlock<type, &_##name##_pool>, PoolCleanBlock<type, &_##name##_pool>); \
|
||||
template type *PoolItem<type, type##ID, &_##name##_pool>::AllocateSafeRaw(uint &first);
|
||||
|
||||
|
||||
#define STATIC_OLD_POOL(name, type, block_size_bits, max_blocks, new_block_proc, clean_block_proc) \
|
||||
|
34
src/oldpool_func.h
Normal file
34
src/oldpool_func.h
Normal file
@ -0,0 +1,34 @@
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef OLDPOOL_FUNC_H
|
||||
|
||||
#include "oldpool.h"
|
||||
|
||||
/**
|
||||
* Allocate a pool item; possibly allocate a new block in the pool.
|
||||
* @param first the first pool item to start searching
|
||||
* @pre first <= Tpool->GetSize()
|
||||
* @return the allocated pool item (or NULL when the pool is full).
|
||||
*/
|
||||
template<typename T, typename Tid, OldMemoryPool<T> *Tpool> T *PoolItem<T, Tid, Tpool>::AllocateSafeRaw(uint &first)
|
||||
{
|
||||
uint last_minus_one = Tpool->GetSize() - 1;
|
||||
|
||||
for (T *t = Tpool->Get(first); t != NULL; t = (t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
|
||||
if (!t->IsValid()) {
|
||||
first = t->index;
|
||||
Tid index = t->index;
|
||||
|
||||
memset(t, 0, Tpool->item_size);
|
||||
t->index = index;
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if we can add a block to the pool */
|
||||
if (Tpool->AddBlockToPool()) return AllocateRaw(first);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* OLDPOOL_FUNC_H */
|
@ -25,6 +25,7 @@
|
||||
#include "newgrf_cargo.h"
|
||||
#include "timetable.h"
|
||||
#include "vehicle_func.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "window_func.h"
|
||||
#include "map_func.h"
|
||||
#include "string_func.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "vehicle_func.h"
|
||||
#include "string_func.h"
|
||||
#include "signal_func.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/sprites.h"
|
||||
#include "table/strings.h"
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "window_func.h"
|
||||
#include "string_func.h"
|
||||
#include "newgrf_cargo.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/sprites.h"
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "autoreplace_gui.h"
|
||||
#include "string_func.h"
|
||||
#include "settings_type.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/sprites.h"
|
||||
#include "table/strings.h"
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "player_func.h"
|
||||
#include "settings_type.h"
|
||||
#include "newgrf_station.h"
|
||||
#include "oldpool_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user