* Remove CellLock class and all cell-level thread locking.

** It was wasting CPU power as cell-level locking is not needed.
** Our multithreading is on map-level, not cell-level.
** CellLock was just a 'proxy' between Cell and CellPair and in some cases carried redundant data.
** Some minor cleanup in Cell::Visit/Map::Visit.

--HG--
branch : trunk
This commit is contained in:
XTZGZoReX
2010-01-23 22:24:41 +01:00
parent fe07518baf
commit 9f00ca3eb8
24 changed files with 110 additions and 212 deletions
+12 -39
View File
@@ -53,26 +53,6 @@ struct ScriptAction;
struct Position;
class BattleGround;
typedef ACE_RW_Thread_Mutex GridRWLock;
template<class MUTEX, class LOCK_TYPE>
struct RGuard
{
RGuard(MUTEX &l) : i_lock(l.getReadLock()) {}
Trinity::GeneralLock<LOCK_TYPE> i_lock;
};
template<class MUTEX, class LOCK_TYPE>
struct WGuard
{
WGuard(MUTEX &l) : i_lock(l.getWriteLock()) {}
Trinity::GeneralLock<LOCK_TYPE> i_lock;
};
typedef RGuard<GridRWLock, ACE_Thread_Mutex> GridReadGuard;
typedef WGuard<GridRWLock, ACE_Thread_Mutex> GridWriteGuard;
typedef Trinity::SingleThreaded<GridRWLock>::Lock NullGuard;
//******************************************
// Map file format defines
//******************************************
@@ -294,7 +274,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
void PlayerRelocation(Player *, float x, float y, float z, float orientation);
void CreatureRelocation(Creature *creature, float x, float y, float z, float ang);
template<class LOCK_TYPE, class T, class CONTAINER> void Visit(const CellLock<LOCK_TYPE> &cell, TypeContainerVisitor<T, CONTAINER> &visitor);
template<class T, class CONTAINER> void Visit(const Cell& cell, TypeContainerVisitor<T, CONTAINER> &visitor);
bool IsRemovalGrid(float x, float y) const
{
@@ -531,9 +511,6 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
//InstanceMaps and BattleGroundMaps...
Map* m_parentMap;
typedef GridReadGuard ReadGuard;
typedef GridWriteGuard WriteGuard;
NGridType* i_grids[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
GridMap *GridMaps[MAX_NUMBER_OF_GRIDS][MAX_NUMBER_OF_GRIDS];
std::bitset<TOTAL_NUMBER_OF_CELLS_PER_MAP*TOTAL_NUMBER_OF_CELLS_PER_MAP> marked_cells;
@@ -659,19 +636,18 @@ Map::CalculateGridMask(const uint32 &y) const
}
*/
template<class LOCK_TYPE, class T, class CONTAINER>
template<class T, class CONTAINER>
inline void
Map::Visit(const CellLock<LOCK_TYPE> &cell, TypeContainerVisitor<T, CONTAINER> &visitor)
Map::Visit(const Cell& cell, TypeContainerVisitor<T, CONTAINER> &visitor)
{
const uint32 x = cell->GridX();
const uint32 y = cell->GridY();
const uint32 cell_x = cell->CellX();
const uint32 cell_y = cell->CellY();
const uint32 x = cell.GridX();
const uint32 y = cell.GridY();
const uint32 cell_x = cell.CellX();
const uint32 cell_y = cell.CellY();
if( !cell->NoCreate() || loaded(GridPair(x,y)) )
if( !cell.NoCreate() || loaded(GridPair(x,y)) )
{
EnsureGridLoaded(cell);
//LOCK_TYPE guard(i_info[x][y]->i_lock);
getNGrid(x, y)->Visit(cell_x, cell_y, visitor);
}
}
@@ -684,12 +660,11 @@ Map::VisitAll(const float &x, const float &y, float radius, NOTIFIER &notifier)
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
CellLock<GridReadGuard> cell_lock(cell, p);
TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier);
cell_lock->Visit(cell_lock, world_object_notifier, *this, radius, x, y);
cell.Visit(p, world_object_notifier, *this, radius, x, y);
TypeContainerVisitor<NOTIFIER, GridTypeMapContainer > grid_object_notifier(notifier);
cell_lock->Visit(cell_lock, grid_object_notifier, *this, radius, x, y);
cell.Visit(p, grid_object_notifier, *this, radius, x, y);
}
template<class NOTIFIER>
@@ -700,10 +675,9 @@ Map::VisitWorld(const float &x, const float &y, float radius, NOTIFIER &notifier
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
CellLock<GridReadGuard> cell_lock(cell, p);
TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier);
cell_lock->Visit(cell_lock, world_object_notifier, *this, radius, x, y);
cell.Visit(p, world_object_notifier, *this, radius, x, y);
}
template<class NOTIFIER>
@@ -714,9 +688,8 @@ Map::VisitGrid(const float &x, const float &y, float radius, NOTIFIER &notifier)
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
CellLock<GridReadGuard> cell_lock(cell, p);
TypeContainerVisitor<NOTIFIER, GridTypeMapContainer > grid_object_notifier(notifier);
cell_lock->Visit(cell_lock, grid_object_notifier, *this, radius, x, y);
cell.Visit(p, grid_object_notifier, *this, radius, x, y);
}
#endif