Fixed recalculateStats deadlock.
This commit is contained in:
@@ -732,14 +732,14 @@ public class CharStat
|
|||||||
* @param broadcast
|
* @param broadcast
|
||||||
*/
|
*/
|
||||||
public final void recalculateStats(boolean broadcast)
|
public final void recalculateStats(boolean broadcast)
|
||||||
{
|
|
||||||
_lock.writeLock().lock();
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Copy old data before wiping it out
|
// Copy old data before wiping it out
|
||||||
final Map<Stats, Double> adds = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsAdd);
|
final Map<Stats, Double> adds = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsAdd);
|
||||||
final Map<Stats, Double> muls = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsMul);
|
final Map<Stats, Double> muls = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsMul);
|
||||||
|
|
||||||
|
_lock.writeLock().lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
// Wipe all the data
|
// Wipe all the data
|
||||||
resetStats();
|
resetStats();
|
||||||
|
|
||||||
@@ -760,6 +760,11 @@ public class CharStat
|
|||||||
// Merge with additional stats
|
// Merge with additional stats
|
||||||
_additionalAdd.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeAdd(holder.getStat(), holder.getValue()));
|
_additionalAdd.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeAdd(holder.getStat(), holder.getValue()));
|
||||||
_additionalMul.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeMul(holder.getStat(), holder.getValue()));
|
_additionalMul.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeMul(holder.getStat(), holder.getValue()));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_lock.writeLock().unlock();
|
||||||
|
}
|
||||||
|
|
||||||
// Notify recalculation to child classes
|
// Notify recalculation to child classes
|
||||||
onRecalculateStats(broadcast);
|
onRecalculateStats(broadcast);
|
||||||
@@ -783,11 +788,6 @@ public class CharStat
|
|||||||
_activeChar.broadcastModifiedStats(changed);
|
_activeChar.broadcastModifiedStats(changed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
_lock.writeLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onRecalculateStats(boolean broadcast)
|
protected void onRecalculateStats(boolean broadcast)
|
||||||
{
|
{
|
||||||
|
@@ -732,14 +732,14 @@ public class CharStat
|
|||||||
* @param broadcast
|
* @param broadcast
|
||||||
*/
|
*/
|
||||||
public final void recalculateStats(boolean broadcast)
|
public final void recalculateStats(boolean broadcast)
|
||||||
{
|
|
||||||
_lock.writeLock().lock();
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Copy old data before wiping it out
|
// Copy old data before wiping it out
|
||||||
final Map<Stats, Double> adds = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsAdd);
|
final Map<Stats, Double> adds = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsAdd);
|
||||||
final Map<Stats, Double> muls = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsMul);
|
final Map<Stats, Double> muls = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsMul);
|
||||||
|
|
||||||
|
_lock.writeLock().lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
// Wipe all the data
|
// Wipe all the data
|
||||||
resetStats();
|
resetStats();
|
||||||
|
|
||||||
@@ -760,6 +760,11 @@ public class CharStat
|
|||||||
// Merge with additional stats
|
// Merge with additional stats
|
||||||
_additionalAdd.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeAdd(holder.getStat(), holder.getValue()));
|
_additionalAdd.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeAdd(holder.getStat(), holder.getValue()));
|
||||||
_additionalMul.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeMul(holder.getStat(), holder.getValue()));
|
_additionalMul.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeMul(holder.getStat(), holder.getValue()));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_lock.writeLock().unlock();
|
||||||
|
}
|
||||||
|
|
||||||
// Notify recalculation to child classes
|
// Notify recalculation to child classes
|
||||||
onRecalculateStats(broadcast);
|
onRecalculateStats(broadcast);
|
||||||
@@ -783,11 +788,6 @@ public class CharStat
|
|||||||
_activeChar.broadcastModifiedStats(changed);
|
_activeChar.broadcastModifiedStats(changed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
_lock.writeLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onRecalculateStats(boolean broadcast)
|
protected void onRecalculateStats(boolean broadcast)
|
||||||
{
|
{
|
||||||
|
@@ -732,14 +732,14 @@ public class CharStat
|
|||||||
* @param broadcast
|
* @param broadcast
|
||||||
*/
|
*/
|
||||||
public final void recalculateStats(boolean broadcast)
|
public final void recalculateStats(boolean broadcast)
|
||||||
{
|
|
||||||
_lock.writeLock().lock();
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Copy old data before wiping it out
|
// Copy old data before wiping it out
|
||||||
final Map<Stats, Double> adds = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsAdd);
|
final Map<Stats, Double> adds = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsAdd);
|
||||||
final Map<Stats, Double> muls = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsMul);
|
final Map<Stats, Double> muls = !broadcast ? Collections.emptyMap() : new HashMap<>(_statsMul);
|
||||||
|
|
||||||
|
_lock.writeLock().lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
// Wipe all the data
|
// Wipe all the data
|
||||||
resetStats();
|
resetStats();
|
||||||
|
|
||||||
@@ -760,6 +760,11 @@ public class CharStat
|
|||||||
// Merge with additional stats
|
// Merge with additional stats
|
||||||
_additionalAdd.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeAdd(holder.getStat(), holder.getValue()));
|
_additionalAdd.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeAdd(holder.getStat(), holder.getValue()));
|
||||||
_additionalMul.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeMul(holder.getStat(), holder.getValue()));
|
_additionalMul.stream().filter(holder -> holder.verifyCondition(_activeChar)).forEach(holder -> mergeMul(holder.getStat(), holder.getValue()));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_lock.writeLock().unlock();
|
||||||
|
}
|
||||||
|
|
||||||
// Notify recalculation to child classes
|
// Notify recalculation to child classes
|
||||||
onRecalculateStats(broadcast);
|
onRecalculateStats(broadcast);
|
||||||
@@ -783,11 +788,6 @@ public class CharStat
|
|||||||
_activeChar.broadcastModifiedStats(changed);
|
_activeChar.broadcastModifiedStats(changed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
_lock.writeLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onRecalculateStats(boolean broadcast)
|
protected void onRecalculateStats(boolean broadcast)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user