UberEmu Timedlock.cs (Edited)
Hello ragezone,
I see allot people has laggs / dreadlocks by an high amout of users online.
Ive edited the timedlock, maby its helpfull for someone.
Replace the whole TimedLock.cs with:
Code:
using System;
using System.Threading;
using Uber;
// # Edited by Breakz0ne.
//
// # DONT EDIT THIS!
public struct TimedLock : IDisposable
{
public static TimedLock Lock(object o)
{
return Lock(o, TimeSpan.FromSeconds(10));
}
public static TimedLock Lock(object o, TimeSpan timeout)
{
TimedLock tl = new TimedLock(o);
if (!Monitor.TryEnter(o, timeout))
{
#if DEBUG
System.GC.SuppressFinalize(tl.leakDetector);
#endif
throw new LockTimeoutException();
}
return tl;
}
private TimedLock(object o)
{
target = o;
#if DEBUG
leakDetector = new Sentinel();
#endif
}
private object target;
public void Dispose()
{
Monitor.Exit(target);
#if DEBUG
GC.SuppressFinalize(leakDetector);
#endif
}
#if DEBUG
private class Sentinel
{
~Sentinel()
{
System.Diagnostics.Debug.Fail("Undisposed lock");
}
}
private Sentinel leakDetector;
#endif
}
public class LockTimeoutException : ApplicationException
{
public LockTimeoutException()
: base("Timeout waiting for lock")
{
}
}
Re: UberEmu Timedlock.cs (Edited)
Re: UberEmu Timedlock.cs (Edited)
Its not recommended to use Timedlock in a live environment but only for debugging which locks are causing issues!
Re: UberEmu Timedlock.cs (Edited)
@matty uberemu is causing issues?
Re: UberEmu Timedlock.cs (Edited)
What he means is, if you are coding UberEmu and debugging it then use them. But don't use them on a live hotel.
Re: UberEmu Timedlock.cs (Edited)
Re: UberEmu Timedlock.cs (Edited)
Quote:
Originally Posted by
Habchop
What he means is, if you are coding UberEmu and debugging it then use them. But don't use them on a live hotel.
This :ott1: you don't even need Timedlock to debug the locks, the reality is, you can't lock an object in one class, from another class.
Take for example...
Room.cs contains UserList..
and Rooms.cs in Messages which is part of the "GameClientMessageHandler",
You do; lock (Room.UserList) < Deadlocked at random points