Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryEnterReadLockCore()

bool System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore ( TimeoutTracker timeout)
inlineprivate

Definition at line 469 of file ReaderWriterLockSlim.cs.

470 {
471 if (_fDisposed)
472 {
473 throw new ObjectDisposedException(null);
474 }
475 int currentManagedThreadId = Environment.CurrentManagedThreadId;
476 ReaderWriterCount threadRWCount;
477 if (!_fIsReentrant)
478 {
479 if (currentManagedThreadId == _writeLockOwnerId)
480 {
481 throw new LockRecursionException(SR.LockRecursionException_ReadAfterWriteNotAllowed);
482 }
483 _spinLock.Enter(EnterSpinLockReason.EnterAnyRead);
484 threadRWCount = GetThreadRWCount(dontAllocate: false);
485 if (threadRWCount.readercount > 0)
486 {
487 _spinLock.Exit();
488 throw new LockRecursionException(SR.LockRecursionException_RecursiveReadNotAllowed);
489 }
490 if (currentManagedThreadId == _upgradeLockOwnerId)
491 {
492 threadRWCount.readercount++;
493 _owners++;
494 _spinLock.Exit();
495 return true;
496 }
497 }
498 else
499 {
500 _spinLock.Enter(EnterSpinLockReason.EnterAnyRead);
501 threadRWCount = GetThreadRWCount(dontAllocate: false);
502 if (threadRWCount.readercount > 0)
503 {
504 threadRWCount.readercount++;
505 _spinLock.Exit();
506 return true;
507 }
508 if (currentManagedThreadId == _upgradeLockOwnerId)
509 {
510 threadRWCount.readercount++;
511 _owners++;
512 _spinLock.Exit();
514 return true;
515 }
516 if (currentManagedThreadId == _writeLockOwnerId)
517 {
518 threadRWCount.readercount++;
519 _owners++;
520 _spinLock.Exit();
521 return true;
522 }
523 }
524 bool flag = true;
525 int num = 0;
526 while (true)
527 {
528 if (_owners < 268435454)
529 {
530 _owners++;
531 threadRWCount.readercount++;
532 _spinLock.Exit();
533 return flag;
534 }
535 if (timeout.IsExpired)
536 {
537 _spinLock.Exit();
538 return false;
539 }
540 if (num < 20 && ShouldSpinForEnterAnyRead())
541 {
542 _spinLock.Exit();
543 num++;
544 SpinWait(num);
545 _spinLock.Enter(EnterSpinLockReason.EnterAnyRead);
546 if (IsRwHashEntryChanged(threadRWCount))
547 {
548 threadRWCount = GetThreadRWCount(dontAllocate: false);
549 }
550 }
551 else if (_readEvent == null)
552 {
554 if (IsRwHashEntryChanged(threadRWCount))
555 {
556 threadRWCount = GetThreadRWCount(dontAllocate: false);
557 }
558 }
559 else
560 {
562 if (!flag)
563 {
564 break;
565 }
566 if (IsRwHashEntryChanged(threadRWCount))
567 {
568 threadRWCount = GetThreadRWCount(dontAllocate: false);
569 }
570 }
571 }
572 return false;
573 }
void LazyCreateEvent([NotNull] ref EventWaitHandle waitEvent, EnterLockType enterLockType)
ReaderWriterCount GetThreadRWCount(bool dontAllocate)
bool WaitOnEvent(EventWaitHandle waitEvent, ref uint numWaiters, TimeoutTracker timeout, EnterLockType enterLockType)
bool IsRwHashEntryChanged(ReaderWriterCount lrwc)

References System.Threading.ReaderWriterLockSlim._fDisposed, System.Threading.ReaderWriterLockSlim._fIsReentrant, System.Threading.ReaderWriterLockSlim._fUpgradeThreadHoldingRead, System.Threading.ReaderWriterLockSlim._numReadWaiters, System.Threading.ReaderWriterLockSlim._owners, System.Threading.ReaderWriterLockSlim._readEvent, System.Threading.ReaderWriterLockSlim._spinLock, System.Threading.ReaderWriterLockSlim._upgradeLockOwnerId, System.Threading.ReaderWriterLockSlim._writeLockOwnerId, System.Environment.CurrentManagedThreadId, System.Threading.ReaderWriterLockSlim.SpinLock.Enter(), System.Threading.ReaderWriterLockSlim.SpinLock.Exit(), System.Threading.ReaderWriterLockSlim.GetThreadRWCount(), System.Threading.ReaderWriterLockSlim.IsRwHashEntryChanged(), System.Threading.ReaderWriterLockSlim.LazyCreateEvent(), System.SR.LockRecursionException_ReadAfterWriteNotAllowed, System.SR.LockRecursionException_RecursiveReadNotAllowed, System.Threading.ReaderWriterCount.readercount, System.Threading.ReaderWriterLockSlim.ShouldSpinForEnterAnyRead(), System.Threading.ReaderWriterLockSlim.SpinWait(), System.timeout, and System.Threading.ReaderWriterLockSlim.WaitOnEvent().

Referenced by System.Threading.ReaderWriterLockSlim.TryEnterReadLock().