Ejemplo n.º 1
0
 internal void Enter(ref bool lockTaken)
 {
     try {
         MonitorUtils.Enter(this, ref lockTaken);
     } finally {
         if (lockTaken)
         {
             _locked++;
         }
     }
 }
Ejemplo n.º 2
0
        public static RubyMutex /*!*/ Lock(RubyMutex /*!*/ self)
        {
            bool lockTaken = false;

            try {
                MonitorUtils.Enter(self._mutex, ref lockTaken);
            } finally {
                if (lockTaken)
                {
                    self._isLocked = true;
                }
            }
            return(self);
        }
Ejemplo n.º 3
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;
                }
            }
        }
Ejemplo n.º 4
0
 private static void SetCritical(RubyContext /*!*/ context, bool value)
 {
     Debug.Assert(context.RubyOptions.Compatibility < RubyCompatibility.Ruby19);
     if (value)
     {
         bool lockTaken = false;
         try {
             MonitorUtils.Enter(context.CriticalMonitor, ref lockTaken);
         } finally {
             // thread could have been aborted just before/after Monitor.Enter acquired the lock:
             if (lockTaken)
             {
                 context.CriticalThread = Thread.CurrentThread;
             }
         }
     }
     else
     {
         Monitor.Exit(context.CriticalMonitor);
         context.CriticalThread = null;
     }
 }