Пример #1
0
 private ClassFactory()
 {
     AssemblyName name = new AssemblyName("DynamicClasses");
     this.module = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run).DefineDynamicModule("Module");
     this.classes = new Dictionary<System.Linq.Dynamic.Signature, Type>();
     this.rwLock = new ReaderWriterLock();
 }
Пример #2
0
		private Class5()
		{
			AssemblyName name = new AssemblyName("DynamicClasses");
			AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
			try
			{
				this.moduleBuilder_0 = assemblyBuilder.DefineDynamicModule("Module");
			}
			finally
			{
			}
			this.dictionary_0 = new Dictionary<Class4, Type>();
			this.readerWriterLock_0 = new ReaderWriterLock();
		}
 private ClassFactory()
 {
     AssemblyName name = new AssemblyName("DynamicClasses");
     AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
     #if ENABLE_LINQ_PARTIAL_TRUST
     new ReflectionPermission(PermissionState.Unrestricted).Assert();
     #endif
     try
     {
         _module = assembly.DefineDynamicModule("Module");
     }
     finally
     {
     #if ENABLE_LINQ_PARTIAL_TRUST
         PermissionSet.RevertAssert();
     #endif
     }
     _classes = new Dictionary<Signature, Type>();
     _rwLock = new ReaderWriterLock();
 }
Пример #4
0
        static void Main(string[] args)
        {
            ReaderWriterLock rwLock = new ReaderWriterLock();

            for (int i = 0; i < 4; i++)
            {
                new Thread(() =>
                {
                    while (true)
                    {
                        var r = new Random();
                        Console.WriteLine("{0} acquiring write", Thread.CurrentThread.Name);
                        rwLock.AcquireWrite();
                        Console.WriteLine("{0} acquired write", Thread.CurrentThread.Name);
                        Thread.Sleep(r.Next(3000, 5000));
                        Console.WriteLine("{0} releasing write", Thread.CurrentThread.Name);
                        rwLock.ReleaseWrite();
                    }
                }) { Name = "Writer " + i }.Start();
            }

            for (int i = 0; i < 12; i++)
            {
                new Thread(() =>
                    {
                        while (true)
                        {
                            var r = new Random();
                            Console.WriteLine("{0} acquiring read", Thread.CurrentThread.Name);
                            rwLock.AcquireRead();
                            Console.WriteLine("{0} acquired read", Thread.CurrentThread.Name);
                            Thread.Sleep(r.Next(250, 500));
                            Console.WriteLine("{0} releasing read", Thread.CurrentThread.Name);
                            rwLock.ReleaseRead();
                        }
                    }) { Name = "Reader " + i }.Start();
            }
        }
 /// <summary>
 /// Initializes a new instance of the SortedDictionary class that is empty and uses the default IComparer implementation for the key type.
 /// </summary>
 public SynchronizedSortedDictionary()
 {
     rwLock           = new ReaderWriterLock();
     sortedDictionary = new SortedDictionary <TKey, TValue>();
 }
Пример #6
0
 public ExclusiveCookie(ReaderWriterLock rwlock)
 {
     this.Lock = rwlock;
     this.Lock.AcquireWriterLock(-1);
 }
Пример #7
0
 public TemplateMgr()
 {
     m_lock = new ReaderWriterLock();
 }
Пример #8
0
 /// <summary> 利用IDisposable的using语法糖方便的释放锁定操作
 /// <para>构造函数</para>
 /// </summary>
 /// <param name="rwl">读写锁</param>
 /// <param name="isWrite">写入模式为true,读取模式为false</param>
 public Lock(ReaderWriterLock rwl, bool isWrite)
 {
     _Lock    = rwl;
     _IsWrite = isWrite;
 }
Пример #9
0
 public AutoReaderRelease(ReaderWriterLock rwLock)
 {
     _lock = rwLock;
 }
Пример #10
0
 public AutoWriterLock(ReaderWriterLock readerWriterLock, int timeout)
 {
     this.readerWriterLock = readerWriterLock;
     this.readerWriterLock.AcquireWriterLock(timeout);
 }
Пример #11
0
        public static void InvalidTimeoutTest_ChangedInDotNetCore()
        {
            var rwl = new ReaderWriterLock();
            Assert.Throws<ArgumentOutOfRangeException>(() => rwl.AcquireReaderLock(-2));
            Assert.Throws<ArgumentOutOfRangeException>(() => rwl.AcquireReaderLock(TimeSpan.FromMilliseconds(-2)));
            Assert.Throws<ArgumentOutOfRangeException>(
                () => rwl.AcquireReaderLock(TimeSpan.FromMilliseconds((uint)int.MaxValue + 1)));

            Assert.Throws<ArgumentOutOfRangeException>(() => rwl.AcquireWriterLock(-2));
            Assert.Throws<ArgumentOutOfRangeException>(() => rwl.AcquireWriterLock(TimeSpan.FromMilliseconds(-2)));
            Assert.Throws<ArgumentOutOfRangeException>(
                () => rwl.AcquireWriterLock(TimeSpan.FromMilliseconds((uint)int.MaxValue + 1)));

            Assert.Throws<ArgumentOutOfRangeException>(() => rwl.UpgradeToWriterLock(-2));
            Assert.Throws<ArgumentOutOfRangeException>(() => rwl.UpgradeToWriterLock(TimeSpan.FromMilliseconds(-2)));
            Assert.Throws<ArgumentOutOfRangeException>(
                () => rwl.UpgradeToWriterLock(TimeSpan.FromMilliseconds((uint)int.MaxValue + 1)));
        }
Пример #12
0
 public override void InitializeConfiguration()
 {
     _Entities = new Dictionary<string, Entity>(10000);
     _RWL = new ReaderWriterLock();
     InitializeData();
 }
Пример #13
0
    public AutoLock(ReaderWriterLock l, bool forWrite)
    {
        this.l = l;

        if (this.forWrite = forWrite)
            l.AcquireWriterLock(timeout);
        else
            l.AcquireReaderLock(timeout);
    }
Пример #14
0
 public PSMoveClientThreadedRead()
 {
     _readerThread = new Thread(new ThreadStart(PSMoveClientThreadedReadThreadStart));
         _rwl = new ReaderWriterLock();
         _readerThreadExit = 0;
         _latest_state = new PSMoveSharpState();
         _latest_camera_frame_state = new PSMoveSharpCameraFrameState();
         _reading = false;
 }
 /// <summary>
 /// Initializes a new instance of the SortedDictionary class that contains elements copied from the specified IDictionary and uses the specified IComparer implementation to compare keys.
 /// </summary>
 /// <param name="dictionary">The IDictionary whose elements are copied to the new SortedDictionary.</param>
 /// <param name="comparer">The IComparer implementation to use when comparing keys, or a null reference (Nothing in Visual Basic) to use the default Comparer for the type of the key.</param>
 public SynchronizedSortedDictionary(IDictionary <TKey, TValue> dictionary, IComparer <TKey> comparer)
 {
     rwLock = new ReaderWriterLock();
     this.sortedDictionary = new SortedDictionary <TKey, TValue>(dictionary, comparer);
 }
Пример #16
0
 public AutoWriterLock(ReaderWriterLock readerWriterLock)
 {
     this.readerWriterLock = readerWriterLock;
 }
Пример #17
0
 public TestReaderWriterLock()
 {
     _rwl = new ReaderWriterLock();
     VerifyState();
 }
Пример #18
0
 /// <summary>			 Constructor. </summary>
 /// <param name="rwLock">The rw lock.</param>
 public RWLock(ReaderWriterLock rwLock) : this(rwLock, State.ReadLock)
 {
 }
 public Lock()
 {
     _lock = new ReaderWriterLock();
 }
 public ReaderWriterLockScope(ReaderWriterLock myLock, bool isReaderLock, bool isUpgradable)
 {
     this.isReaderLock = isReaderLock;
     this.isUpgradable = isUpgradable;
     this.readerWriterlock = myLock;
 }
Пример #21
0
 /// <summary>
 /// Overloaded constructor. Takes the max objects limit, and the listener as parameters.
 /// </summary>
 /// <param name="maxLimit">maximum number of objects to contain.</param>
 public StorageProviderBase(long maxSize)
 {
     _syncObj = new ReaderWriterLock();
     _maxSize = maxSize;
     //			DEFAULT_CAPACITY = (_maxLimit > 0) ? (int)Math.Min(10000, _maxLimit):10000;
 }
Пример #22
0
 public MemoryStorageSafe()
 {
     dictionary = new Dictionary <TKey, TValue>();
     rwLock     = new ReaderWriterLock();
 }
 public ReadLockDisposable(ReaderWriterLock readerWriterLock)
 {
     this._readerWriterLock = readerWriterLock;
 }
Пример #24
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="cfg">Configuration</param>
        public TfsCore(TfsMigrationDataSource cfg)
        {
            m_rwLock = new ReaderWriterLock();
            m_cfg    = cfg;
            //m_missingArea = missingArea;
            //m_missingIteration = missingIteration;

            m_srv = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(cfg.ServerName));
            m_srv.EnsureAuthenticated();
            TraceManager.TraceInformation("Authenticated User for Uri {0} is '{1}'", m_srv.Uri, m_srv.AuthorizedIdentity.DisplayName);

            //// Verify whether the user is in the service account group. Throw an exception if it is not.
            //// TODO: move this to proper location
            //IGroupSecurityService gss = (IGroupSecurityService)m_srv.GetService(typeof(IGroupSecurityService));
            //Identity serviceAccountIdentity = gss.ReadIdentity(SearchFactor.ServiceApplicationGroup, null, QueryMembership.None);
            //if (!gss.IsMember(serviceAccountIdentity.Sid, m_srv.AuthenticatedUserIdentity.Sid))
            //{
            //    throw new MigrationException(
            //        string.Format(TfsWITAdapterResources.UserNotInServiceAccountGroup, m_srv.AuthenticatedUserName, m_srv.Name));
            //}

            m_store = CreateWorkItemStore();
            m_name  = string.Format(
                CultureInfo.InvariantCulture,
                "{0} ({1})",
                m_store.TeamProjectCollection.Name,
                m_cfg.Project);

            Project p = m_store.Projects[cfg.Project];

            m_projectUri = p.Uri.ToString();
            m_projectId  = p.Id;

            //// Check existence of default area and iteration, if any
            //if (!string.IsNullOrEmpty(cfg.DefaultArea))
            //{
            //    m_defaultAreaId = GetNode(Node.TreeType.Area, cfg.DefaultArea, false);
            //}
            //else
            //{
            //    m_defaultAreaId = p.Id;
            //}
            //if (!string.IsNullOrEmpty(cfg.DefaultIteration))
            //{
            //    m_defaultIterationId = GetNode(Node.TreeType.Iteration, cfg.DefaultIteration, false);
            //}
            //else
            //{
            //    m_defaultIterationId = p.Id;
            //}
            /// TODO: replace the code below with configuration in consideration
            m_defaultAreaId      = p.Id;
            m_defaultIterationId = p.Id;

            // Obtain registration info
            IRegistration regSvc = (IRegistration)m_store.TeamProjectCollection.GetService(typeof(IRegistration));

            RegistrationEntry[] res = regSvc.GetRegistrationEntries(ToolNames.WorkItemTracking);

            if (res.Length != 1)
            {
                throw new MigrationException(TfsWITAdapterResources.ErrorMalformedRegistrationData, cfg.ServerName);
            }

            RegistrationEntry e = res[0];

            // Extract all data from the registration entry.
            for (int i = 0; i < e.ServiceInterfaces.Length; i++)
            {
                ServiceInterface si = e.ServiceInterfaces[i];

                if (TFStringComparer.ServiceInterface.Equals(si.Name, ServiceInterfaces.WorkItem))
                {
                    m_witUrl = si.Url;
                }
                else if (TFStringComparer.ServiceInterface.Equals(si.Name, "ConfigurationSettingsUrl"))
                {
                    m_configUrl = si.Url;
                }
            }

            for (int i = 0; i < e.RegistrationExtendedAttributes.Length; i++)
            {
                RegistrationExtendedAttribute a = e.RegistrationExtendedAttributes[i];

                if (RegistrationUtilities.Compare(a.Name, "AttachmentServerUrl") == 0)
                {
                    m_attachUrl = a.Value;
                    break;
                }
            }

            if (string.IsNullOrEmpty(m_witUrl) || string.IsNullOrEmpty(m_configUrl) ||
                string.IsNullOrEmpty(m_attachUrl))
            {
                throw new MigrationException(TfsWITAdapterResources.ErrorMalformedRegistrationData,
                                             m_cfg.ServerName);
            }

            m_attachUrl = CombineUrl(m_attachUrl, m_witUrl);
        }
Пример #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardReaderWriterLock"/> class.
 /// </summary>
 public StandardReaderWriterLock(int lockTimeout)
 {
     _rwLock   = new ReaderWriterLock();
     ReadLock  = new CommonReadLock(this, lockTimeout);
     WriteLock = new CommonWriteLock(this, lockTimeout);
 }
Пример #26
0
 public SharedCookie(ReaderWriterLock rwlock)
 {
     this.Lock = rwlock;
     this.Lock.AcquireReaderLock(-1);
 }
Пример #27
0
 public static WriterLock WriteLock(this ReaderWriterLock _this, Int32 timeout = Int32.MaxValue)
 {
     return(new WriterLock(_this, timeout));
 }
Пример #28
0
 public PromotedCookie(ReaderWriterLock rwlock)
 {
     this.Lock   = rwlock;
     this.Cookie = this.Lock.UpgradeToWriterLock(-1);
 }
Пример #29
0
 public WriterLock(ReaderWriterLock rwlock, Int32 timeout)
 {
     _RWLock = rwlock;
     _RWLock.AcquireWriterLock(timeout);
 }
 /// <summary>
 /// Initializes a new instance of the SortedDictionary class that contains elements copied from the specified IDictionary and uses the default IComparer implementation for the key type.
 /// </summary>
 /// <param name="dictionary">The IDictionary whose elements are copied to the new SortedDictionary.</param>
 public SynchronizedSortedDictionary(IDictionary <TKey, TValue> dictionary)
 {
     rwLock = new ReaderWriterLock();
     this.sortedDictionary = new SortedDictionary <TKey, TValue>(dictionary);
 }
Пример #31
0
 static LoggingLogWrittenEvent()
 {
     string[] counterNames = new string[] {LoggingServiceEvent.counters[(int)CounterID.LogWritten].CounterName};
     logEvent = new LoggingLogWrittenEvent(counterNames);
     writerLock = new ReaderWriterLock();
 }
Пример #32
0
 internal EnumeratorJoinerBase(ReaderWriterLock rwLock, params IEnumerator[] enumerators)
 {
     this._rwLock      = rwLock;
     this._enumerators = new List <IEnumerator>(enumerators);
 }
 public ReaderLockGuard(ReaderWriterLock readerWriterLock)
 {
     _lock = readerWriterLock;
 }
Пример #34
0
 public AutoWriterLock(ReaderWriterLock readerWriterLock)
     : this(readerWriterLock, Timeout.Infinite)
 {
 }
Пример #35
0
        /// <inheritdoc />
        public void Run(Action <string> log)
        {
            log($"## Synchronization Primitives Benchmark (no contention and high contention)\n");

            var monitor = new object();

            SynchronizationTestInternal(log, 1, "Monitor", () => Monitor.Enter(monitor), () => Monitor.Exit(monitor));
            SynchronizationTestInternal(log, 100, "Monitor", () => Monitor.Enter(monitor), () => Monitor.Exit(monitor));

            var sema = new Semaphore(1, 1);

            SynchronizationTestInternal(log, 1, "Semaphore", () => sema.WaitOne(), () => sema.Release());
            SynchronizationTestInternal(log, 100, "Semaphore", () => sema.WaitOne(), () => sema.Release());

            var rwl = new ReaderWriterLock();

            SynchronizationTestInternal(log, 1, "ReaderWriterLock", () => rwl.AcquireWriterLock(1000), () => rwl.ReleaseWriterLock());
            SynchronizationTestInternal(log, 100, "ReaderWriterLock", () => rwl.AcquireWriterLock(1000), () => rwl.ReleaseWriterLock());

            var semaSlim = new SemaphoreSlim(1, 1);

            SynchronizationTestInternal(log, 1, "SemaphoreSlim", () => semaSlim.Wait(), () => semaSlim.Release());
            SynchronizationTestInternal(log, 100, "SemaphoreSlim", () => semaSlim.Wait(), () => semaSlim.Release());

            var rwlSlim = new ReaderWriterLockSlim();

            SynchronizationTestInternal(log, 1, "ReaderWriterLockSlim", () => rwlSlim.EnterWriteLock(), () => rwlSlim.ExitWriteLock());
            SynchronizationTestInternal(log, 100, "ReaderWriterLockSlim", () => rwlSlim.EnterWriteLock(), () => rwlSlim.ExitWriteLock());

            var evtA = new ManualResetEvent(false);
            var evtB = new ManualResetEvent(false);

            SyncPingPongInternal(
                log,
                "ManualResetEvent",
                () =>
            {
                evtB.Reset();
                evtA.WaitOne();
            },
                () => evtA.Set(),
                () =>
            {
                evtB.WaitOne();
                evtA.WaitOne();
            },
                () => evtB.Set());

            var evtSlimA = new ManualResetEventSlim(false);
            var evtSlimB = new ManualResetEventSlim(false);

            SyncPingPongInternal(
                log,
                "ManualResetEventSlim",
                () =>
            {
                evtB.Reset();
                evtA.WaitOne();
            },
                () => evtA.Set(),
                () =>
            {
                evtB.WaitOne();
                evtA.WaitOne();
            },
                () => evtB.Set());
        }
Пример #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StandardReaderWriterLock"/> class.
 /// </summary>
 public StandardReaderWriterLock()
 {
     _rwLock   = new ReaderWriterLock();
     ReadLock  = new CommonReadLock(this);
     WriteLock = new CommonWriteLock(this);
 }
Пример #37
0
 public static LruLock GetWriteLock(ReaderWriterLock lockObj)
 {
     return(new LruLock(lockObj, LruLockStatus.WriteLock, defaultTimeout));
 }
Пример #38
0
 /// <summary>				Constructor.</summary>
 /// <param name="rwLock">   The rw lock.</param>
 /// <param name="lockState">State of the lock.</param>
 public RWLock(ReaderWriterLock rwLock, State lockState)
 {
     lockObj   = rwLock;
     Timeout   = 90000;
     LockState = lockState;
 }
Пример #39
0
 public LruLock(ReaderWriterLock lockObj, LruLockStatus status, int timeoutMS)
 {
     this.lockObj = lockObj;
     this.timeout = timeoutMS;
     this.Status  = status;
 }
Пример #40
0
 public MemoryCommandProcessor(IDictionary<string, Entity> entities, ReaderWriterLock rwl)
 {
     _Entities = entities;
     _RWL = rwl;
 }
Пример #41
0
 static TraceContext()
 {
     contextDictionary = new Dictionary <string, TraceContext>();
     syncLock          = new ReaderWriterLock();
 }