Here are the examples of the csharp api System.Threading.ReaderWriterLockSlim.EnterReadLock() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
773 Examples
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<PhysicsObj> GetVisibleObjectsValuesWhere(Func<PhysicsObj, bool> predicate)
{
rwLock.EnterReadLock();
try
{
return VisibleObjects.Values.Where(predicate).ToList();
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : PlayerManager.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static int GetOnlineCount()
{
playersLock.EnterReadLock();
try
{
return onlinePlayers.Count;
}
finally
{
playersLock.ExitReadLock();
}
}
19
View Source File : PlayerManager.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static List<Player> GetAllOnline()
{
var results = new List<Player>();
playersLock.EnterReadLock();
try
{
foreach (var player in onlinePlayers.Values)
results.Add(player);
}
finally
{
playersLock.ExitReadLock();
}
return results;
}
19
View Source File : PlayerManager.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static OfflinePlayer GetOfflinePlayer(string name)
{
var admin = "+" + name;
playersLock.EnterReadLock();
try
{
var offlinePlayer = offlinePlayers.Values.FirstOrDefault(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase) || p.Name.Equals(admin, StringComparison.OrdinalIgnoreCase));
if (offlinePlayer != null)
return offlinePlayer;
}
finally
{
playersLock.ExitReadLock();
}
return null;
}
19
View Source File : PlayerManager.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static List<OfflinePlayer> GetAllOffline()
{
var results = new List<OfflinePlayer>();
playersLock.EnterReadLock();
try
{
foreach (var player in offlinePlayers.Values)
results.Add(player);
}
finally
{
playersLock.ExitReadLock();
}
return results;
}
19
View Source File : PlayerManager.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static Player GetOnlinePlayer(uint guid)
{
playersLock.EnterReadLock();
try
{
if (onlinePlayers.TryGetValue(guid, out var value))
return value;
}
finally
{
playersLock.ExitReadLock();
}
return null;
}
19
View Source File : NetworkManager.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static Session Find(uint accountId)
{
sessionLock.EnterReadLock();
try
{
return sessionMap.SingleOrDefault(s => s != null && s.AccountId == accountId);
}
finally
{
sessionLock.ExitReadLock();
}
}
19
View Source File : NetworkManager.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static Session Find(string account)
{
sessionLock.EnterReadLock();
try
{
return sessionMap.SingleOrDefault(s => s != null && s.Account == account);
}
finally
{
sessionLock.ExitReadLock();
}
}
19
View Source File : NetworkManager.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public static void ProcessPacket(ConnectionListener connectionListener, ClientPacket packet, IPEndPoint endPoint)
{
if (connectionListener.ListenerEndpoint.Port == ConfigManager.Config.Server.Network.Port + 1)
{
ServerPerformanceMonitor.RestartEvent(ServerPerformanceMonitor.MonitorType.ProcessPacket_1);
if (packet.Header.Flags.HasFlag(PacketHeaderFlags.ConnectResponse))
{
packetLog.Debug($"{packet}, {endPoint}");
PacketInboundConnectResponse connectResponse = new PacketInboundConnectResponse(packet);
// This should be set on the second packet to the server from the client.
// This completes the three-way handshake.
sessionLock.EnterReadLock();
Session session = null;
try
{
session =
(from k in sessionMap
where
k != null &&
k.State == SessionState.AuthConnectResponse &&
k.Network.ConnectionData.ConnectionCookie == connectResponse.Check &&
k.EndPoint.Address.Equals(endPoint.Address)
select k).FirstOrDefault();
}
finally
{
sessionLock.ExitReadLock();
}
if (session != null)
{
session.State = SessionState.AuthConnected;
session.Network.sendResync = true;
AuthenticationHandler.HandleConnectResponse(session);
}
}
else if (packet.Header.Id == 0 && packet.Header.HasFlag(PacketHeaderFlags.CICMDCommand))
{
// TODO: Not sure what to do with these packets yet
}
else
{
log.ErrorFormat("Packet from {0} rejected. Packet sent to listener 1 and is not a ConnectResponse or CICMDCommand", endPoint);
}
ServerPerformanceMonitor.RegisterEventEnd(ServerPerformanceMonitor.MonitorType.ProcessPacket_1);
}
else // ConfigManager.Config.Server.Network.Port + 0
{
ServerPerformanceMonitor.RestartEvent(ServerPerformanceMonitor.MonitorType.ProcessPacket_0);
if (packet.Header.HasFlag(PacketHeaderFlags.LoginRequest))
{
packetLog.Debug($"{packet}, {endPoint}");
if (GetAuthenticatedSessionCount() >= ConfigManager.Config.Server.Network.MaximumAllowedSessions)
{
log.InfoFormat("Login Request from {0} rejected. Server full.", endPoint);
SendLoginRequestReject(connectionListener, endPoint, CharacterError.LogonServerFull);
}
else if (ServerManager.ShutdownInProgress)
{
log.InfoFormat("Login Request from {0} rejected. Server is shutting down.", endPoint);
SendLoginRequestReject(connectionListener, endPoint, CharacterError.ServerCrash1);
}
else if (ServerManager.ShutdownInitiated && (ServerManager.ShutdownTime - DateTime.UtcNow).TotalMinutes < 2)
{
log.InfoFormat("Login Request from {0} rejected. Server shutting down in less than 2 minutes.", endPoint);
SendLoginRequestReject(connectionListener, endPoint, CharacterError.ServerCrash1);
}
else
{
log.DebugFormat("Login Request from {0}", endPoint);
var ipAllowsUnlimited = ConfigManager.Config.Server.Network.AllowUnlimitedSessionsFromIPAddresses.Contains(endPoint.Address.ToString());
if (ipAllowsUnlimited || ConfigManager.Config.Server.Network.MaximumAllowedSessionsPerIPAddress == -1 || GetSessionEndpointTotalByAddressCount(endPoint.Address) < ConfigManager.Config.Server.Network.MaximumAllowedSessionsPerIPAddress)
{
var session = FindOrCreateSession(connectionListener, endPoint);
if (session != null)
{
if (session.State == SessionState.AuthConnectResponse)
{
// connect request packet sent to the client was corrupted in transit and session entered an unspecified state.
// ignore the request and remove the broken session and the client will start a new session.
RemoveSession(session);
log.Warn($"Bad handshake from {endPoint}, aborting session.");
}
session.ProcessPacket(packet);
}
else
{
log.InfoFormat("Login Request from {0} rejected. Failed to find or create session.", endPoint);
SendLoginRequestReject(connectionListener, endPoint, CharacterError.LogonServerFull);
}
}
else
{
log.InfoFormat("Login Request from {0} rejected. Session would exceed MaximumAllowedSessionsPerIPAddress limit.", endPoint);
SendLoginRequestReject(connectionListener, endPoint, CharacterError.LogonServerFull);
}
}
}
else if (sessionMap.Length > packet.Header.Id)
{
var session = sessionMap[packet.Header.Id];
if (session != null)
{
if (session.EndPoint.Equals(endPoint))
session.ProcessPacket(packet);
else
log.DebugFormat("Session for Id {0} has IP {1} but packet has IP {2}", packet.Header.Id, session.EndPoint, endPoint);
}
else
{
log.DebugFormat("Unsolicited Packet from {0} with Id {1}", endPoint, packet.Header.Id);
}
}
else
{
log.DebugFormat("Unsolicited Packet from {0} with Id {1}", endPoint, packet.Header.Id);
}
ServerPerformanceMonitor.RegisterEventEnd(ServerPerformanceMonitor.MonitorType.ProcessPacket_0);
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<Creature> GetVisibleObjectsValuesOfTypeCreature()
{
rwLock.EnterReadLock();
try
{
return VisibleObjects.Values.Select(v => v.WeenieObj.WorldObject).OfType<Creature>().ToList();
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<PhysicsObj> GetVisibleObjects(ObjCell cell, VisibleObjectType type = VisibleObjectType.All)
{
rwLock.EnterReadLock();
try
{
if (PhysicsObj.CurLandblock == null || cell == null)
return new List<PhysicsObj>();
// use PVS / VisibleCells for EnvCells not seen outside
// (mostly dungeons, also some large indoor areas ie. caves)
if (cell is EnvCell envCell)
return GetVisibleObjects(envCell, type);
// use current landblock + adjacents for outdoors,
// and envcells seen from outside (all buildings)
var visibleObjs = PhysicsObj.CurLandblock.GetServerObjects(true);
return ApplyFilter(visibleObjs, type).Where(i => i.ID != PhysicsObj.ID && (!(i.CurCell is EnvCell indoors) || indoors.SeenOutside)).ToList();
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public int GetKnownPlayersCount()
{
rwLock.EnterReadLock();
try
{
return KnownPlayers.Count;
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public int GetDestructionQueueCount()
{
rwLock.EnterReadLock();
try
{
return DestructionQueue.Count;
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public Dictionary<PhysicsObj, double> GetDestructionQueueCopy()
{
rwLock.EnterReadLock();
try
{
var result = new Dictionary<PhysicsObj, double>();
foreach (var kvp in DestructionQueue)
result[kvp.Key] = kvp.Value;
return result;
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<PhysicsObj> GetKnownPlayersValues()
{
rwLock.EnterReadLock();
try
{
return KnownPlayers.Values.ToList();
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<Player> GetKnownPlayersValuesAsPlayer()
{
rwLock.EnterReadLock();
try
{
return KnownPlayers.Values.Select(v => v.WeenieObj.WorldObject).OfType<Player>().ToList();
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<Creature> GetKnownObjectsValuesAsCreature()
{
rwLock.EnterReadLock();
try
{
return KnownObjects.Values.Select(v => v.WeenieObj.WorldObject).OfType<Creature>().ToList();
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public bool RemoveKnownPlayer(PhysicsObj obj)
{
//Console.WriteLine($"{PhysicsObj.Name} ({PhysicsObj.ID:X8}).ObjectMaint.RemoveKnownPlayer({obj.Name})");
rwLock.EnterReadLock();
try
{
return KnownPlayers.Remove(obj.ID, out _);
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public int GetVisibleTargetsCount()
{
rwLock.EnterReadLock();
try
{
return VisibleTargets.Count;
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public int GetRetaliateTargetsCount()
{
rwLock.EnterReadLock();
try
{
return RetaliateTargets.Count;
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public bool VisibleTargetsContainsKey(uint key)
{
rwLock.EnterReadLock();
try
{
return VisibleTargets.ContainsKey(key);
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public bool RetaliateTargetsContainsKey(uint key)
{
rwLock.EnterReadLock();
try
{
return RetaliateTargets.ContainsKey(key);
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<PhysicsObj> GetVisibleTargetsValues()
{
rwLock.EnterReadLock();
try
{
return VisibleTargets.Values.ToList();
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<PhysicsObj> GetRetaliateTargetsValues()
{
rwLock.EnterReadLock();
try
{
return RetaliateTargets.Values.ToList();
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<Creature> GetVisibleTargetsValuesOfTypeCreature()
{
rwLock.EnterReadLock();
try
{
return VisibleTargets.Values.Select(v => v.WeenieObj.WorldObject).OfType<Creature>().ToList();
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : ObjectMaint.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator
public List<PhysicsObj> GetVisibleObjectsDist(ObjCell cell, VisibleObjectType type)
{
rwLock.EnterReadLock();
try
{
var visibleObjs = GetVisibleObjects(cell, type);
var dist = new List<PhysicsObj>();
foreach (var obj in visibleObjs)
{
var distSq = PhysicsObj.Position.Distance2DSquared(obj.Position);
if (distSq <= InitialClamp_DistSq)
dist.Add(obj);
}
return dist;
}
finally
{
rwLock.ExitReadLock();
}
}
19
View Source File : SecretMasker.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public void AddValue(String value)
{
// Test for empty.
if (String.IsNullOrEmpty(value))
{
return;
}
var valueSecrets = new List<ValueSecret>(new[] { new ValueSecret(value) });
// Read section.
ValueEncoder[] valueEncoders;
try
{
m_lock.EnterReadLock();
// Test whether already added.
if (m_originalValueSecrets.Contains(valueSecrets[0]))
{
return;
}
// Read the value encoders.
valueEncoders = m_valueEncoders.ToArray();
}
finally
{
if (m_lock.IsReadLockHeld)
{
m_lock.ExitReadLock();
}
}
// Compute the encoded values.
foreach (ValueEncoder valueEncoder in valueEncoders)
{
String encodedValue = valueEncoder(value);
if (!String.IsNullOrEmpty(encodedValue))
{
valueSecrets.Add(new ValueSecret(encodedValue));
}
}
// Write section.
try
{
m_lock.EnterWriteLock();
// Add the values.
m_originalValueSecrets.Add(valueSecrets[0]);
foreach (ValueSecret valueSecret in valueSecrets)
{
m_valueSecrets.Add(valueSecret);
}
}
finally
{
if (m_lock.IsWriteLockHeld)
{
m_lock.ExitWriteLock();
}
}
}
19
View Source File : SecretMasker.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public void AddValueEncoder(ValueEncoder encoder)
{
ValueSecret[] originalSecrets;
// Read section.
try
{
m_lock.EnterReadLock();
// Test whether already added.
if (m_valueEncoders.Contains(encoder))
{
return;
}
// Read the original value secrets.
originalSecrets = m_originalValueSecrets.ToArray();
}
finally
{
if (m_lock.IsReadLockHeld)
{
m_lock.ExitReadLock();
}
}
// Compute the encoded values.
var encodedSecrets = new List<ValueSecret>();
foreach (ValueSecret originalSecret in originalSecrets)
{
String encodedValue = encoder(originalSecret.m_value);
if (!String.IsNullOrEmpty(encodedValue))
{
encodedSecrets.Add(new ValueSecret(encodedValue));
}
}
// Write section.
try
{
m_lock.EnterWriteLock();
// Add the encoder.
m_valueEncoders.Add(encoder);
// Add the values.
foreach (ValueSecret encodedSecret in encodedSecrets)
{
m_valueSecrets.Add(encodedSecret);
}
}
finally
{
if (m_lock.IsWriteLockHeld)
{
m_lock.ExitWriteLock();
}
}
}
19
View Source File : SecretMasker.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public String MaskSecrets(String input)
{
if (String.IsNullOrEmpty(input))
{
return String.Empty;
}
var secretPositions = new List<ReplacementPosition>();
// Read section.
try
{
m_lock.EnterReadLock();
// Get indexes and lengths of all substrings that will be replaced.
foreach (RegexSecret regexSecret in m_regexSecrets)
{
secretPositions.AddRange(regexSecret.GetPositions(input));
}
foreach (ValueSecret valueSecret in m_valueSecrets)
{
secretPositions.AddRange(valueSecret.GetPositions(input));
}
}
finally
{
if (m_lock.IsReadLockHeld)
{
m_lock.ExitReadLock();
}
}
// Short-circuit if nothing to replace.
if (secretPositions.Count == 0)
{
return input;
}
// Merge positions into ranges of characters to replace.
List<ReplacementPosition> replacementPositions = new List<ReplacementPosition>();
ReplacementPosition currentReplacement = null;
foreach (ReplacementPosition secretPosition in secretPositions.OrderBy(x => x.Start))
{
if (currentReplacement == null)
{
currentReplacement = new ReplacementPosition(copy: secretPosition);
replacementPositions.Add(currentReplacement);
}
else
{
if (secretPosition.Start <= currentReplacement.End)
{
// Overlap
currentReplacement.Length = Math.Max(currentReplacement.End, secretPosition.End) - currentReplacement.Start;
}
else
{
// No overlap
currentReplacement = new ReplacementPosition(copy: secretPosition);
replacementPositions.Add(currentReplacement);
}
}
}
// Replace
var stringBuilder = new StringBuilder();
Int32 startIndex = 0;
foreach (var replacement in replacementPositions)
{
stringBuilder.Append(input.Substring(startIndex, replacement.Start - startIndex));
stringBuilder.Append("***");
startIndex = replacement.Start + replacement.Length;
}
if (startIndex < input.Length)
{
stringBuilder.Append(input.Substring(startIndex));
}
return stringBuilder.ToString();
}
19
View Source File : LocationCacheManager.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public AccessMapping GetAccessMapping(String moniker)
{
ArgumentUtility.CheckStringForNullOrEmpty(moniker, "moniker");
EnsureDiskCacheLoaded();
m_accessLock.EnterReadLock();
try
{
if (CacheDataExpired)
{
return null;
}
AccessMapping accessMapping;
m_accessMappings.TryGetValue(moniker, out accessMapping);
return accessMapping;
}
finally
{
m_accessLock.ExitReadLock();
}
}
19
View Source File : LocationCacheManager.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public Boolean TryFindService(String serviceType, Guid serviceIdentifier, out ServiceDefinition serviceDefinition)
{
EnsureDiskCacheLoaded();
m_accessLock.EnterReadLock();
try
{
Dictionary<Guid, ServiceDefinition> services = null;
serviceDefinition = null;
if (CacheDataExpired)
{
return false;
}
if (m_services.TryGetValue(serviceType, out services))
{
if (services.TryGetValue(serviceIdentifier, out serviceDefinition))
{
return true;
}
}
// Look in our cachedMisses to see if we can find it there.
if (m_cachedMisses.Contains(BuildCacheMissString(serviceType, serviceIdentifier)))
{
// We found an entry in cached misses so return true.
return true;
}
return false;
}
finally
{
m_accessLock.ExitReadLock();
}
}
19
View Source File : LocationCacheManager.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public IEnumerable<ServiceDefinition> FindServices(String serviceType)
{
EnsureDiskCacheLoaded();
m_accessLock.EnterReadLock();
try
{
Debug.replacedert(m_lastChangeId == -1 || m_services.Count > 0);
if (CacheDataExpired)
{
return null;
}
// We either have all of the services or none. If we have none then return null.
if (m_services.Count == 0)
{
return null;
}
// If service type is null, return all services as long as we know
// that we have all of the services
IEnumerable<Dictionary<Guid, ServiceDefinition>> dictionaries;
if (String.IsNullOrEmpty(serviceType))
{
dictionaries = m_services.Values;
}
else
{
Dictionary<Guid, ServiceDefinition> services = null;
if (!m_services.TryGetValue(serviceType, out services))
{
return null;
}
dictionaries = new Dictionary<Guid, ServiceDefinition>[] { services };
}
// Make a copy of all of the service definitions to preplaced back.
List<ServiceDefinition> serviceDefinitions = new List<ServiceDefinition>();
foreach (Dictionary<Guid, ServiceDefinition> dict in dictionaries)
{
foreach (ServiceDefinition definition in dict.Values)
{
serviceDefinitions.Add(definition.Clone());
}
}
return serviceDefinitions;
}
finally
{
m_accessLock.ExitReadLock();
}
}
19
View Source File : LocationCacheManager.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public Int32 GetLastChangeId()
{
EnsureDiskCacheLoaded();
m_accessLock.EnterReadLock();
try
{
return m_lastChangeId;
}
finally
{
m_accessLock.ExitReadLock();
}
}
19
View Source File : LocationCacheManager.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
internal DateTime GetCacheExpirationDate()
{
EnsureDiskCacheLoaded();
m_accessLock.EnterReadLock();
try
{
return m_cacheExpirationDate;
}
finally
{
m_accessLock.ExitReadLock();
}
}
19
View Source File : LocationServerMapCache.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public static String ReadServerLocation(Guid serverId, Guid serviceOwner)
{
try
{
EnsureCacheLoaded();
s_accessLock.EnterReadLock();
// Iterate through the dictionary to find the location we are looking for
foreach (KeyValuePair<String, ServerMapData> pair in s_serverMappings)
{
if (Guid.Equals(serverId, pair.Value.ServerId) &&
Guid.Equals(serviceOwner, pair.Value.ServiceOwner))
{
return pair.Key;
}
}
return null;
}
finally
{
if (s_accessLock.IsReadLockHeld)
{
s_accessLock.ExitReadLock();
}
}
}
19
View Source File : LocationServerMapCache.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public static ServerMapData ReadServerData(String location)
{
try
{
EnsureCacheLoaded();
s_accessLock.EnterReadLock();
ServerMapData serverData;
if (!s_serverMappings.TryGetValue(location, out serverData))
{
return new ServerMapData();
}
return serverData;
}
finally
{
if (s_accessLock.IsReadLockHeld)
{
s_accessLock.ExitReadLock();
}
}
}
19
View Source File : HashedListCache.cs
License : MIT License
Project Creator : albyho
License : MIT License
Project Creator : albyho
public T Get(Expression key, Func<Expression, T> creator)
{
SortedList<Expression, T> sortedList;
T value;
int hash = new Hasher().Hash(key);
_rwLock.EnterReadLock();
try
{
if (_storage.TryGetValue(hash, out sortedList) &&
sortedList.TryGetValue(key, out value))
{
return value;
}
}
finally
{
_rwLock.ExitReadLock();
}
_rwLock.EnterWriteLock();
try
{
if (!_storage.TryGetValue(hash, out sortedList))
{
sortedList = new SortedList<Expression, T>(new Comparer());
_storage.Add(hash, sortedList);
}
if (!sortedList.TryGetValue(key, out value))
{
value = creator(key);
sortedList.Add(key, value);
}
return value;
}
finally
{
_rwLock.ExitWriteLock();
}
}
19
View Source File : JemApi.cs
License : MIT License
Project Creator : allisterb
License : MIT License
Project Creator : allisterb
public static int GetRefCount(IntPtr ptr)
{
allocLock.EnterReadLock();
int c = _Allocations[ptr];
allocLock.ExitReadLock();
return c;
}
19
View Source File : JemApi.cs
License : MIT License
Project Creator : allisterb
License : MIT License
Project Creator : allisterb
public static bool PtrIsAllocated(IntPtr ptr)
{
allocLock.EnterReadLock();
bool r = _Allocations.ContainsKey(ptr);
allocLock.ExitReadLock();
return r;
}
19
View Source File : JemApi.cs
License : MIT License
Project Creator : allisterb
License : MIT License
Project Creator : allisterb
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool FixedBufferIsAllocatedWith(IntPtr ptr, ulong size, long timestamp, int tid, int rid)
{
fixedBufferLock.EnterReadLock();
bool r1 = _FixedBufferAllocations.ContainsKey(ptr);
if (!r1)
{
fixedBufferLock.ExitReadLock();
return false;
}
else
{
bool r2 = _FixedBufferAllocations[ptr].Equals(new FixedBufferAllocation(ptr, size, timestamp, tid, rid));
fixedBufferLock.ExitReadLock();
return r2;
}
}
19
View Source File : EventDispatcher.cs
License : MIT License
Project Creator : AlternateLife
License : MIT License
Project Creator : AlternateLife
protected bool TryGetSubscriptions(out IReadOnlyCollection<T> subscriptions)
{
_readerWriterLock.EnterReadLock();
try
{
subscriptions = _subscriptions.ToList();
return subscriptions.Any();
}
finally
{
_readerWriterLock.ExitReadLock();
}
}
19
View Source File : PlottingGraphData.cs
License : MIT License
Project Creator : Analogy-LogViewer
License : MIT License
Project Creator : Analogy-LogViewer
private void RefreshDataTimerTick(object sender, EventArgs e)
{
try
{
sync.EnterReadLock();
for (int i = Math.Max(lastRawDataIndex, rawData.Count - DataWindow); i < rawData.Count; i++)
{
ViewportData.Add(rawData[i]);
}
lastRawDataIndex = rawData.Count;
while (ViewportData.Count > DataWindow)
{
ViewportData.RemoveAt(0);
}
}
finally
{
sync.ExitReadLock();
}
}
19
View Source File : PagingManager.cs
License : MIT License
Project Creator : Analogy-LogViewer
License : MIT License
Project Creator : Analogy-LogViewer
public DataTable CurrentPage()
{
lockSlim.EnterReadLock();
var table = currentTable;
lockSlim.ExitReadLock();
return table;
}
19
View Source File : PagingManager.cs
License : MIT License
Project Creator : Analogy-LogViewer
License : MIT License
Project Creator : Analogy-LogViewer
public replacedogyPageInformation PrevPage()
{
lockSlim.EnterReadLock();
if (pages.First() != currentTable)
{
currentPageNumber--;
currentTable = pages[currentPageNumber - 1];
currentPageStartRowIndex = pages.IndexOf(currentTable) * pageSize;
}
lockSlim.ExitReadLock();
return new replacedogyPageInformation(currentTable, currentPageNumber, currentPageStartRowIndex);
}
19
View Source File : PagingManager.cs
License : MIT License
Project Creator : Analogy-LogViewer
License : MIT License
Project Creator : Analogy-LogViewer
public DataTable FirstPage()
{
lockSlim.EnterReadLock();
currentTable = pages.First();
currentPageNumber = 1;
lockSlim.ExitReadLock();
return currentTable;
}
19
View Source File : PagingManager.cs
License : MIT License
Project Creator : Analogy-LogViewer
License : MIT License
Project Creator : Analogy-LogViewer
public DataTable LastPage()
{
lockSlim.EnterReadLock();
currentTable = pages.Last();
currentPageNumber = pages.Count;
lockSlim.ExitReadLock();
return currentTable;
}
19
View Source File : PagingManager.cs
License : MIT License
Project Creator : Analogy-LogViewer
License : MIT License
Project Creator : Analogy-LogViewer
public List<replacedogyLogMessage> GetAllMessages()
{
try
{
lockSlim.EnterReadLock();
var items = allMessages.ToList();
return items;
}
finally
{
lockSlim.ExitReadLock();
}
}
19
View Source File : PagingManager.cs
License : MIT License
Project Creator : Analogy-LogViewer
License : MIT License
Project Creator : Analogy-LogViewer
public bool IsCurrentPageInView(DataTable currentView)
{
lockSlim.EnterReadLock();
var current = currentTable == currentView;
lockSlim.ExitReadLock();
return current;
}
19
View Source File : PagingManager.cs
License : MIT License
Project Creator : Analogy-LogViewer
License : MIT License
Project Creator : Analogy-LogViewer
public replacedogyPageInformation NextPage()
{
lockSlim.EnterReadLock();
if (pages.Last() != currentTable)
{
currentPageNumber++;
currentTable = pages[currentPageNumber - 1];
currentPageStartRowIndex = pages.IndexOf(currentTable) * pageSize;
}
lockSlim.ExitReadLock();
return new replacedogyPageInformation(currentTable, currentPageNumber, currentPageStartRowIndex);
}
19
View Source File : LogLock.cs
License : Apache License 2.0
Project Creator : anjoy8
License : Apache License 2.0
Project Creator : anjoy8
public static string ReadLog(string folderPath, string fileName, Encoding encode, ReadType readType = ReadType.Accurate, int takeOnlyTop = -1)
{
string s = "";
try
{
LogWriteLock.EnterReadLock();
// 根据文件名读取当前文件内容
if (readType == ReadType.Accurate)
{
var filePath = Path.Combine(folderPath, fileName);
if (!File.Exists(filePath))
{
s = null;
}
else
{
StreamReader f2 = new StreamReader(filePath, encode);
s = f2.ReadToEnd();
f2.Close();
f2.Dispose();
}
}
// 根据前缀读取所有文件内容
if (readType == ReadType.Prefix)
{
var allFiles = new DirectoryInfo(folderPath);
var selectFiles = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(fileName.ToLower())).ToList();
selectFiles = takeOnlyTop > 0 ? selectFiles.OrderByDescending(d => d.Name).Take(takeOnlyTop).ToList() : selectFiles;
foreach (var item in selectFiles)
{
if (File.Exists(item.FullName))
{
StreamReader f2 = new StreamReader(item.FullName, encode);
s += f2.ReadToEnd();
f2.Close();
f2.Dispose();
}
}
}
// 根据前缀读取 最新文件 时间倒叙
if (readType == ReadType.PrefixLatest)
{
var allFiles = new DirectoryInfo(folderPath);
var selectLastestFile = allFiles.GetFiles().Where(fi => fi.Name.ToLower().Contains(fileName.ToLower())).OrderByDescending(d => d.Name).FirstOrDefault();
if (selectLastestFile != null && File.Exists(selectLastestFile.FullName))
{
StreamReader f2 = new StreamReader(selectLastestFile.FullName, encode);
s = f2.ReadToEnd();
f2.Close();
f2.Dispose();
}
}
}
catch (Exception)
{
FailedCount++;
}
finally
{
LogWriteLock.ExitReadLock();
}
return s;
}
See More Examples