UberEmu Timedlock.cs (Edited)

Results 1 to 7 of 7
  1. #1
    Account Upgraded | Title Enabled! wichard is offline
    MemberRank
    Jul 2009 Join Date
    The NetherlandsLocation
    649Posts

    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")
        {
        }
    }
    Last edited by wichard; 28-03-11 at 05:23 PM.


  2. #2
    Valued Member jordyhouben is offline
    MemberRank
    Aug 2009 Join Date
    EuropaLocation
    111Posts

    Re: UberEmu Timedlock.cs (Edited)

    This is Great! <3

  3. #3
    Lurking since '06 1ntel is offline
    MemberRank
    Jul 2006 Join Date
    401Posts

    Re: UberEmu Timedlock.cs (Edited)

    Its not recommended to use Timedlock in a live environment but only for debugging which locks are causing issues!

  4. #4
    Account Upgraded | Title Enabled! wichard is offline
    MemberRank
    Jul 2009 Join Date
    The NetherlandsLocation
    649Posts

    Re: UberEmu Timedlock.cs (Edited)

    @matty uberemu is causing issues?

  5. #5
    <insert title here> Shorty is offline
    MemberRank
    Feb 2007 Join Date
    United KingdomLocation
    1,861Posts

    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.

  6. #6
    Account Upgraded | Title Enabled! wichard is offline
    MemberRank
    Jul 2009 Join Date
    The NetherlandsLocation
    649Posts

    Re: UberEmu Timedlock.cs (Edited)

    yea lol

  7. #7
    Lurking since '06 1ntel is offline
    MemberRank
    Jul 2006 Join Date
    401Posts

    Re: UberEmu Timedlock.cs (Edited)

    Quote Originally Posted by Habchop View Post
    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 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
    Last edited by 1ntel; 28-03-11 at 11:25 PM.



Advertisement