Example #1
0
        public static RubyConditionVariable /*!*/ Broadcast(RubyConditionVariable /*!*/ self)
        {
            RubyMutex m = self._mutex;

            if (m != null)
            {
                lock (self._lock) {
                    int waits = self._waits;
                    for (int i = 0; i < waits; i++)
                    {
                        self._signal.Set();
                        //
                        // WARNING
                        //
                        // There is no guarantee that every call to the Set method will release a waiting thread.
                        // If two calls are too close together, so that the second call occurs before a thread
                        // has been released, only one thread is released.
                        // We add a sleep to increase the chance that all waiting threads will be released.
                        //
                        Thread.CurrentThread.Join(1);
                    }
                }
            }
            return(self);
        }
Example #2
0
        public static RubyConditionVariable /*!*/ Signal(RubyConditionVariable /*!*/ self)
        {
            RubyMutex m = self._mutex;

            if (m != null)
            {
                self._signal.Set();
            }
            return(self);
        }
        public static RubyConditionVariable /*!*/ Broadcast(RubyConditionVariable /*!*/ self)
        {
            RubyMutex m = self._mutex;

            if (m != null)
            {
                Monitor.PulseAll(m);
            }
            return(self);
        }
        public static RubyConditionVariable /*!*/ Signal(RubyConditionVariable /*!*/ self)
        {
            RubyMutex m = self._mutex;

            if (m != null)
            {
                Monitor.Pulse(m);
            }
            return(self);
        }
Example #5
0
 public static bool TryLock(RubyMutex/*!*/ self) {
     bool lockTaken = false;
     try {
         MonitorUtils.TryEnter(self._mutex, ref lockTaken);
     } finally {
         if (lockTaken) {
             self._isLocked = true;
         }
     }
     return lockTaken;
 }
Example #6
0
 public static RubyMutex/*!*/ Unlock(RubyMutex/*!*/ self) {
     bool lockTaken = true;
     try {
         MonitorUtils.Exit(self._mutex, ref lockTaken);
     } finally {
         if (!lockTaken) {
             self._isLocked = false;
         }
     }
     return self;
 }
Example #7
0
        public static RubyConditionVariable /*!*/ Wait(RubyConditionVariable /*!*/ self, [NotNull] RubyMutex /*!*/ mutex)
        {
            self._mutex = mutex;
            RubyMutex.Unlock(mutex);
            lock (self._lock) { self._waits++; }

            self._signal.WaitOne();

            lock (self._lock) { self._waits--; }
            RubyMutex.Lock(mutex);
            return(self);
        }
Example #8
0
 public static object Synchronize(BlockParam criticalSection, RubyMutex/*!*/ self) {
     lock (self._mutex) {
         self._isLocked = true;
         try {
             object result;
             criticalSection.Yield(out result);
             return result;
         } finally {
             self._isLocked = false;
         }
     }
 }
Example #9
0
 public static object Synchronize(BlockParam criticalSection, RubyMutex /*!*/ self)
 {
     lock (self._mutex) {
         self._isLocked = true;
         try {
             object result;
             criticalSection.Yield(out result);
             return(result);
         } finally {
             self._isLocked = false;
         }
     }
 }
Example #10
0
        public static bool TryLock(RubyMutex /*!*/ self)
        {
            bool lockTaken = false;

            try {
                MonitorUtils.TryEnter(self._mutex, ref lockTaken);
            } finally {
                if (lockTaken)
                {
                    self._isLocked = true;
                }
            }
            return(lockTaken);
        }
Example #11
0
        public static RubyMutex /*!*/ Unlock(RubyMutex /*!*/ self)
        {
            bool lockTaken = true;

            try {
                MonitorUtils.Exit(self._mutex, ref lockTaken);
            } finally {
                if (!lockTaken)
                {
                    self._isLocked = false;
                }
            }
            return(self);
        }
Example #12
0
 public static object Synchronize(BlockParam criticalSection, RubyMutex/*!*/ self) {
     bool lockTaken = false;
     try {
         MonitorUtils.Enter(self._mutex, ref lockTaken);
         self._isLocked = lockTaken;
         object result;
         criticalSection.Yield(out result);
         return result;
     } finally {
         if (lockTaken) {
             MonitorUtils.Exit(self._mutex, ref lockTaken);
             self._isLocked = lockTaken;
         }
     }
 }
Example #13
0
        public static object Synchronize(BlockParam criticalSection, RubyMutex /*!*/ self)
        {
            bool lockTaken = false;

            try {
                MonitorUtils.Enter(self._mutex, ref lockTaken);
                self._isLocked = lockTaken;
                object result;
                criticalSection.Yield(out result);
                return(result);
            } finally {
                if (lockTaken)
                {
                    MonitorUtils.Exit(self._mutex, ref lockTaken);
                    self._isLocked = lockTaken;
                }
            }
        }
Example #14
0
 public static bool TryLock(RubyMutex /*!*/ self)
 {
     return(self._isLocked = Monitor.TryEnter(self._mutex));
 }
Example #15
0
 public static bool ExclusiveUnlock(BlockParam criticalSection, RubyMutex/*!*/ self) {
     // TODO:
     throw new NotImplementedException();            
 }
Example #16
0
 public static RubyMutex/*!*/ Lock(RubyMutex/*!*/ self) {
     Monitor.Enter(self._mutex);
     self._isLocked = true;
     return self;
 }
Example #17
0
 public static RubyMutex/*!*/ Unlock(RubyMutex/*!*/ self) {
     self._isLocked = false;
     Monitor.Exit(self._mutex);
     return self;
 }
Example #18
0
 public static bool IsLocked(RubyMutex/*!*/ self) {
     return self._isLocked;
 }
Example #19
0
 public static bool TryLock(RubyMutex/*!*/ self) {
     return self._isLocked = Monitor.TryEnter(self._mutex);
 }
Example #20
0
 public static RubyMutex /*!*/ Lock(RubyMutex /*!*/ self)
 {
     Monitor.Enter(self._mutex);
     self._isLocked = true;
     return(self);
 }
 public static RubyConditionVariable /*!*/ Wait(RubyConditionVariable /*!*/ self, [NotNull] RubyMutex /*!*/ mutex)
 {
     self._mutex = mutex;
     Monitor.Wait(mutex.Mutex);
     return(self);
 }
Example #22
0
 public static RubyMutex /*!*/ Unlock(RubyMutex /*!*/ self)
 {
     self._isLocked = false;
     Monitor.Exit(self._mutex);
     return(self);
 }
Example #23
0
 public static bool IsLocked(RubyMutex /*!*/ self)
 {
     return(self._isLocked);
 }
Example #24
0
 public static bool ExclusiveUnlock(BlockParam criticalSection, RubyMutex /*!*/ self)
 {
     // TODO:
     throw new NotImplementedException();
 }