Esempio n. 1
0
 public static void GetAllInfoAsync(MalockClient malock, int timeout, Action <int, IEnumerable <HandleInfo> > callback)
 {
     if (malock == null)
     {
         throw new ArgumentNullException("malock");
     }
     malock.GetAllInfoAsync(timeout, callback);
 }
Esempio n. 2
0
 public static bool TryGetAllInfo(MalockClient malock, int timeout, out IEnumerable <HandleInfo> s, ref Exception exception)
 {
     if (malock == null)
     {
         throw new ArgumentNullException("handle");
     }
     return(malock.TryGetAllInfo(timeout, out s, ref exception));
 }
Esempio n. 3
0
 public static int TryGetAllInfo(MalockClient malock, int timeout, out IEnumerable <HandleInfo> s)
 {
     if (malock == null)
     {
         throw new ArgumentNullException("malock");
     }
     return(malock.TryGetAllInfo(timeout, out s));
 }
Esempio n. 4
0
 public static IEnumerable <HandleInfo> GetAllInfo(MalockClient malock)
 {
     if (malock == null)
     {
         throw new ArgumentNullException("malock");
     }
     return(malock.GetAllInfo());
 }
Esempio n. 5
0
        protected static TSyncBlockIndex NewOrGet <TSyncBlockIndex>(string key, MalockClient malock,
                                                                    Func <TSyncBlockIndex> constructor)
            where TSyncBlockIndex : SyncBlockIndex
        {
            if (constructor == null)
            {
                throw new ArgumentNullException("constructor");
            }
            if (malock == null)
            {
                throw new ArgumentNullException("malock");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (key.Length <= 0)
            {
                throw new ArgumentOutOfRangeException("key");
            }
            Exception      exception = null;
            SyncBlockIndex block     = null;

            lock (g_syncobj)
            {
                if (!g_blocks.TryGetValue(key, out block))
                {
                    try
                    {
                        block = constructor(); // BUG
                        if (block == null)
                        {
                            exception = new ArgumentOutOfRangeException("The calling type constructor returns a null value that is not allowed");
                        }
                        else
                        {
                            g_blocks.TryAdd(key, block);
                        }
                    }
                    catch (Exception e)
                    {
                        exception = e;
                    }
                }
            }
            if (exception != null)
            {
                throw exception;
            }
            return(block as TSyncBlockIndex);
        }
Esempio n. 6
0
        internal SyncBlockIndex(string key, MalockClient malock)
        {
            Exception exception = null;

            lock (g_syncobj)
            {
                if (g_blocks.ContainsKey(key))
                {
                    exception = new InvalidOperationException("Do not allow duplicate instances of locks of the same key");
                }
            }
            if (exception != null)
            {
                throw exception;
            }
            this.Handle = this.NewWaitHandle(key, malock);
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            //NN_Test();
            //Console.ReadKey(false);

            MalockClient malock = Malock.GetClient("test013", "127.0.0.1:6800", "127.0.0.1:6801").Run();

            malock.Ready += delegate
            {
                Monitor m   = Monitor.New("OMFG", malock);
                int     num = 0;
                for (int i = 0; i < 5; i++)
                {
                    EventWaitHandle.Run(() =>
                    {
                        for (int k = 0; k < 10; k++)
                        {
                            try
                            {
                                Stopwatch sw = new Stopwatch();
                                sw.Start();
                                if (m.TryEnter())
                                {
                                    sw.Stop();
                                    Console.WriteLine("n: {0}, time: {1}ms", Interlocked.Increment(ref num), sw.ElapsedMilliseconds);
                                    m.Exit();
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        }
                    });
                }
            };
            Console.ReadKey(false);
        }
Esempio n. 8
0
 public static AutoResetEvent New(string key, MalockClient malock)
 {
     return(NewOrGet(key, malock, () => new AutoResetEvent(key, malock)));
 }
Esempio n. 9
0
 protected abstract EventWaitHandle NewWaitHandle(string key, MalockClient malock);
Esempio n. 10
0
 public static SpinLock New(string key, MalockClient malock, bool reduce)
 {
     return(NewOrGet(key, malock, () => new SpinLock(key, malock, reduce)));
 }
Esempio n. 11
0
 public static SpinLock New(string key, MalockClient malock)
 {
     return(New(key, malock, true));
 }
Esempio n. 12
0
 private SpinLock(string key, MalockClient malock, bool reduce) : base(key, malock)
 {
     this.Reduce = reduce;
 }
Esempio n. 13
0
 public SpinLockWaitHandle(SpinLock owner, string key, MalockClient malock) :
     base(owner, key, malock)
 {
     this.locker = owner;
 }
Esempio n. 14
0
 protected override EventWaitHandle NewWaitHandle(string key, MalockClient malock)
 {
     return(new SpinLockWaitHandle(this, key, malock));
 }
Esempio n. 15
0
 protected override EventWaitHandle NewWaitHandle(string key, MalockClient malock)
 {
     return(EventWaitHandle.NewDefaultWaitHandle(this, key, malock));
 }
Esempio n. 16
0
 private AutoResetEvent(string key, MalockClient malock) : base(key, malock)
 {
 }
Esempio n. 17
0
 private Monitor(string key, MalockClient malock) : base(key, malock)
 {
 }
Esempio n. 18
0
 public static Monitor New(string key, MalockClient malock)
 {
     return(NewOrGet(key, malock, () => new Monitor(key, malock)));
 }
Esempio n. 19
0
 public MonitorWaitHandle(object owner, string key, MalockClient malock) : base(owner, key, malock)
 {
 }