Used StampedLock to synchronize auto attack method.

This commit is contained in:
MobiusDev
2018-11-26 00:03:16 +00:00
parent 4bdbc57157
commit ca236013fd
11 changed files with 2296 additions and 2131 deletions

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{

View File

@@ -30,6 +30,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.StampedLock;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -222,6 +223,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -840,7 +843,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAttack(L2Character target)
public void doAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1087,6 +1097,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
// Notify AI with EVT_READY_TO_ACT
ThreadPool.schedule(new NotifyAITask(this, CtrlEvent.EVT_READY_TO_ACT), timeAtk + reuse);
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
/**
* Launch a Bow attack.<br>

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{

View File

@@ -34,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Predicate;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -219,6 +220,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
private final byte[] _zones = new byte[ZoneId.getZoneCount()];
protected byte _zoneValidateCounter = 4;
private final StampedLock _attackLock = new StampedLock();
private Team _team = Team.NONE;
protected long _exceptions = 0;
@@ -891,7 +894,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
* </ul>
* @param target The L2Character targeted
*/
public synchronized void doAutoAttack(L2Character target)
public void doAutoAttack(L2Character target)
{
final long stamp = _attackLock.tryWriteLock();
if (stamp == 0)
{
return;
}
try
{
if ((target == null) || isAttackingDisabled() || !target.isTargetable())
{
@@ -1149,6 +1159,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe
}
}
}
finally
{
_attackLock.unlockWrite(stamp);
}
}
private Attack generateAttackTargetData(L2Character target, L2Weapon weapon, WeaponType weaponType)
{