#include <rtl_vista.h>
#include <debug.h>
Go to the source code of this file.
◆ _ONE
Definition at line 34 of file srw.c.
◆ InterlockedAddPointer
Definition at line 31 of file srw.c.
◆ InterlockedAndPointer
Definition at line 32 of file srw.c.
◆ InterlockedBitTestAndSetPointer
Definition at line 30 of file srw.c.
◆ InterlockedOrPointer
Definition at line 33 of file srw.c.
◆ NDEBUG
Definition at line 18 of file srw.c.
◆ RTL_SRWLOCK_BITS
Definition at line 47 of file srw.c.
◆ RTL_SRWLOCK_CONTENDED
Definition at line 42 of file srw.c.
◆ RTL_SRWLOCK_CONTENDED_BIT
| #define RTL_SRWLOCK_CONTENDED_BIT 1 |
Definition at line 38 of file srw.c.
◆ RTL_SRWLOCK_CONTENTION_LOCK
Definition at line 44 of file srw.c.
◆ RTL_SRWLOCK_CONTENTION_LOCK_BIT
| #define RTL_SRWLOCK_CONTENTION_LOCK_BIT 3 |
Definition at line 40 of file srw.c.
◆ RTL_SRWLOCK_MASK
Value:
#define RTL_SRWLOCK_CONTENDED
#define RTL_SRWLOCK_CONTENTION_LOCK
#define RTL_SRWLOCK_SHARED
#define RTL_SRWLOCK_OWNED
Definition at line 45 of file srw.c.
◆ RTL_SRWLOCK_OWNED
Definition at line 41 of file srw.c.
◆ RTL_SRWLOCK_OWNED_BIT
| #define RTL_SRWLOCK_OWNED_BIT 0 |
Definition at line 37 of file srw.c.
◆ RTL_SRWLOCK_SHARED
Definition at line 43 of file srw.c.
◆ RTL_SRWLOCK_SHARED_BIT
| #define RTL_SRWLOCK_SHARED_BIT 2 |
Definition at line 39 of file srw.c.
◆ PRTLP_SRWLOCK_SHARED_WAKE
◆ PRTLP_SRWLOCK_WAITBLOCK
◆ RTLP_SRWLOCK_SHARED_WAKE
◆ RTLP_SRWLOCK_WAITBLOCK
◆ RtlAcquireSRWLockExclusive()
Definition at line 591 of file srw.c.
592{
595
598 {
600
601 while (1)
602 {
603 CurrentValue = *(
volatile LONG_PTR *)&SRWLock->Ptr;
604
606 {
607
608
610 {
611 goto AddWaitBlock;
612 }
613 else
614 {
615
616
620 StackWaitBlock.
Last = &StackWaitBlock;
621 StackWaitBlock.
Wake = 0;
622
624
627 (
PVOID)CurrentValue) == CurrentValue)
628 {
630 &StackWaitBlock);
631
632
633 break;
634 }
635 }
636 }
637 else
638 {
640 {
641
642
644 {
645AddWaitBlock:
649 StackWaitBlock.
Last = &StackWaitBlock;
650 StackWaitBlock.
Wake = 0;
651
654 {
656 Last->
Next = &StackWaitBlock;
657 First->Last = &StackWaitBlock;
658
660
662 &StackWaitBlock);
663
664
665 break;
666 }
667 }
668 else
669 {
670
671
675 StackWaitBlock.
Last = &StackWaitBlock;
676 StackWaitBlock.
Wake = 0;
677
681 (
PVOID)CurrentValue) == CurrentValue)
682 {
684 &StackWaitBlock);
685
686
687 break;
688 }
689 }
690 }
691 else
692 {
695 {
696
697 break;
698 }
699 }
700 }
701
703 }
704 }
705}
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
#define InterlockedCompareExchangePointer
typedef __ALIGNED(16) struct _EX_PUSH_LOCK_WAIT_BLOCK
static VOID NTAPI RtlpReleaseWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
static VOID NTAPI RtlpAcquireSRWLockExclusiveWait(IN OUT PRTL_SRWLOCK SRWLock, IN PRTLP_SRWLOCK_WAITBLOCK WaitBlock)
#define InterlockedBitTestAndSetPointer(ptr, val)
#define RTL_SRWLOCK_OWNED_BIT
static PRTLP_SRWLOCK_WAITBLOCK NTAPI RtlpAcquireWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
volatile struct _RTLP_SRWLOCK_WAITBLOCK * Last
volatile struct _RTLP_SRWLOCK_WAITBLOCK * Next
Referenced by AcquireDynamicFunctionTableLockExclusive(), AcquireSRWLockExclusive(), and InternalSleep().
◆ RtlAcquireSRWLockShared()
Definition at line 325 of file srw.c.
326{
331
333 {
334 CurrentValue = *(
volatile LONG_PTR *)&SRWLock->Ptr;
335
337 {
338
339
341 {
342
343
346 {
348
349 if (
First->Exclusive)
350 {
351
352
353
354
355 Shared =
First->Last;
356
358 {
362 StackWaitBlock.
Last = &StackWaitBlock;
364
365 Shared->
Next = &StackWaitBlock;
366 First->Last = &StackWaitBlock;
367
368 Shared = &StackWaitBlock;
369 FirstWait = &StackWaitBlock;
370 }
371 else
372 {
375 }
376 }
377 else
378 {
382 }
383
386
388
390
392 FirstWait,
393 &SharedWake);
394
395
396 break;
397 }
398 }
399 else
400 {
401
402
403
404
405
406
408
411
414 (
PVOID)CurrentValue) == CurrentValue)
415 {
416
417 break;
418 }
419 }
420 }
421 else
422 {
424 {
425
427 {
430
431
432
433
434
438 StackWaitBlock.
Last = &StackWaitBlock;
440
443 {
444 Shared =
First->Last;
446 {
447 Shared->
Next = &StackWaitBlock;
448 First->Last = &StackWaitBlock;
449
450 Shared = &StackWaitBlock;
451 FirstWait = &StackWaitBlock;
452 }
453 else
454 {
457 }
458
461
463
465 FirstWait,
466 &SharedWake);
467
468
469 break;
470 }
471 }
472 else
473 {
476
477
478
482 StackWaitBlock.
Last = &StackWaitBlock;
485
489 (
PVOID)CurrentValue) == CurrentValue)
490 {
492 &StackWaitBlock,
493 &SharedWake);
494
495
496 break;
497 }
498 }
499 }
500 else
501 {
502
504
505
506
508
511 (
PVOID)CurrentValue) == CurrentValue)
512 {
513
514 break;
515 }
516 }
517 }
518
520 }
521}
static VOID NTAPI RtlpAcquireSRWLockSharedWait(IN OUT PRTL_SRWLOCK SRWLock, IN OUT PRTLP_SRWLOCK_WAITBLOCK FirstWait OPTIONAL, IN OUT PRTLP_SRWLOCK_SHARED_WAKE WakeChain)
volatile struct _RTLP_SRWLOCK_SHARED_WAKE * Next
PRTLP_SRWLOCK_SHARED_WAKE SharedWakeChain
PRTLP_SRWLOCK_SHARED_WAKE LastSharedWake
Referenced by AcquireDynamicFunctionTableLockShared(), AcquireSRWLockShared(), and InternalSleep().
◆ RtlInitializeSRWLock()
◆ RtlpAcquireSRWLockExclusiveWait()
Definition at line 232 of file srw.c.
234{
236
237 while (1)
238 {
239 CurrentValue = *(
volatile LONG_PTR *)&SRWLock->Ptr;
241 {
243 {
244 if (WaitBlock->Wake != 0)
245 {
246
247
248 break;
249 }
250 }
251 else
252 {
253
254
255
256 break;
257 }
258 }
259
261 }
262}
Referenced by RtlAcquireSRWLockExclusive().
◆ RtlpAcquireSRWLockSharedWait()
Definition at line 267 of file srw.c.
270{
271 if (FirstWait !=
NULL)
272 {
273 while (WakeChain->Wake == 0)
274 {
276 }
277 }
278 else
279 {
281
282 while (1)
283 {
284 CurrentValue = *(
volatile LONG_PTR *)&SRWLock->Ptr;
286 {
287
288
290
292 {
293 if (WakeChain->Wake != 0)
294 {
295
296
297 break;
298 }
299 }
300 else
301 {
302
303
304
305 break;
306 }
307 }
308
310 }
311 }
312}
Referenced by RtlAcquireSRWLockShared().
◆ RtlpAcquireWaitBlockLock()
◆ RtlpReleaseWaitBlockLock()
◆ RtlpReleaseWaitBlockLockExclusive()
Definition at line 85 of file srw.c.
87{
90
91
92
93 Next = FirstWaitBlock->Next;
95 {
96
97
99 if (!FirstWaitBlock->Exclusive)
100 {
101
103
104
105 Next->SharedCount = FirstWaitBlock->SharedCount;
106
108 }
109
110 Next->Last = FirstWaitBlock->Last;
111 }
112 else
113 {
114
115 if (FirstWaitBlock->Exclusive)
117 else
118 {
119 ASSERT(FirstWaitBlock->SharedCount > 0);
120
123 }
124 }
125
127
128 if (FirstWaitBlock->Exclusive)
129 {
132 }
133 else
134 {
136
137
138
139 WakeChain = FirstWaitBlock->SharedWakeChain;
140 do
141 {
142 NextWake = WakeChain->
Next;
143
146
147 WakeChain = NextWake;
148 }
while (WakeChain !=
NULL);
149 }
150}
#define InterlockedExchangePointer(Target, Value)
PACPI_METHOD_ARGUMENT Next
Referenced by RtlReleaseSRWLockExclusive().
◆ RtlpReleaseWaitBlockLockLastShared()
Definition at line 155 of file srw.c.
157{
160
161
162
163
164 ASSERT(FirstWaitBlock->Exclusive);
165
166 Next = FirstWaitBlock->Next;
168 {
169
170
172
173 Next->Last = FirstWaitBlock->Last;
174 }
175 else
176 {
177
179 }
180
182
185}
Referenced by RtlReleaseSRWLockShared().
◆ RtlReleaseSRWLockExclusive()
Definition at line 710 of file srw.c.
711{
714
715 while (1)
716 {
717 CurrentValue = *(
volatile LONG_PTR *)&SRWLock->Ptr;
718
720 {
722 }
723
725 {
727 {
728
729
731 if (WaitBlock !=
NULL)
732 {
734 WaitBlock);
735
736
737 break;
738 }
739 }
740 else
741 {
742
743
744
745
747
748 NewValue = 0;
751 (
PVOID)CurrentValue) == CurrentValue)
752 {
753
754 break;
755 }
756 }
757 }
758 else
759 {
760
761
763 }
764
766 }
767}
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#define STATUS_RESOURCE_NOT_OWNED
static VOID NTAPI RtlpReleaseWaitBlockLockExclusive(IN OUT PRTL_SRWLOCK SRWLock, IN PRTLP_SRWLOCK_WAITBLOCK FirstWaitBlock)
Referenced by InternalSleep(), ReleaseDynamicFunctionTableLockExclusive(), and ReleaseSRWLockExclusive().
◆ RtlReleaseSRWLockShared()
Definition at line 526 of file srw.c.
527{
531
532 while (1)
533 {
534 CurrentValue = *(
volatile LONG_PTR *)&SRWLock->Ptr;
535
537 {
539 {
540
541
543 if (WaitBlock !=
NULL)
544 {
546
547 if (LastShared)
549 WaitBlock);
550 else
552
553
554 break;
555 }
556 }
557 else
558 {
559
560
562
563 if (--NewValue != 0)
564 {
566 }
567
570 (
PVOID)CurrentValue) == CurrentValue)
571 {
572
573 break;
574 }
575 }
576 }
577 else
578 {
579
580
582 }
583
585 }
586}
static VOID NTAPI RtlpReleaseWaitBlockLockLastShared(IN OUT PRTL_SRWLOCK SRWLock, IN PRTLP_SRWLOCK_WAITBLOCK FirstWaitBlock)
Referenced by InternalSleep(), ReleaseDynamicFunctionTableLockShared(), and ReleaseSRWLockShared().
◆ RtlTryAcquireSRWLockExclusive()
◆ RtlTryAcquireSRWLockShared()
Definition at line 771 of file srw.c.
772{
773
774 LONG_PTR CompareValue, NewValue, GotValue;
775
776 do
777 {
778 CompareValue = *(
volatile LONG_PTR *)&SRWLock->
Ptr;
780
781
783 } while (
786
788}