Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordotnet-bot <dotnet-bot@microsoft.com>2015-10-01 00:47:24 +0300
committerScott Mosier <smosier@microsoft.com>2015-10-01 00:47:24 +0300
commitad0323ab91a7b1469b42ca5457ddd631b94294fe (patch)
tree88fae57e1ec3aae90288463dc07e58f7aebc1de8 /src/Native/Runtime/RWLock.h
parent6763d16387778f126ec510c0421783952602f8f7 (diff)
Initial population of CoreRT Runtime files.
Diffstat (limited to 'src/Native/Runtime/RWLock.h')
-rw-r--r--src/Native/Runtime/RWLock.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Native/Runtime/RWLock.h b/src/Native/Runtime/RWLock.h
new file mode 100644
index 000000000..1684813fa
--- /dev/null
+++ b/src/Native/Runtime/RWLock.h
@@ -0,0 +1,54 @@
+//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+class ReaderWriterLock
+{
+ volatile Int32 m_RWLock; // lock used for R/W synchronization
+ Int32 m_spinCount; // spin count for a reader waiting for a writer to release the lock
+
+#if 0
+ // used to prevent writers from being starved by readers
+ // we currently do not prevent writers from starving readers since writers
+ // are supposed to be rare.
+ bool m_WriterWaiting;
+#endif
+
+ bool TryAcquireReadLock();
+ bool TryAcquireWriteLock();
+
+public:
+ class ReadHolder
+ {
+ ReaderWriterLock * m_pLock;
+ bool m_fLockAcquired;
+ public:
+ ReadHolder(ReaderWriterLock * pLock, bool fAcquireLock = true);
+ ~ReadHolder();
+ };
+
+ class WriteHolder
+ {
+ ReaderWriterLock * m_pLock;
+ bool m_fLockAcquired;
+ public:
+ WriteHolder(ReaderWriterLock * pLock, bool fAcquireLock = true);
+ ~WriteHolder();
+ };
+
+ ReaderWriterLock();
+
+ void AcquireReadLock();
+ void ReleaseReadLock();
+
+ bool DangerousTryPulseReadLock();
+
+protected:
+ void AcquireWriteLock();
+ void ReleaseWriteLock();
+
+ void AcquireReadLockWorker();
+
+};
+