ReactOS 0.4.15-dev-7924-g5949c20
sync.c File Reference
#include "k32_vista.h"
#include <debug.h>
Include dependency graph for sync.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI RtlInitializeConditionVariable (OUT PRTL_CONDITION_VARIABLE ConditionVariable)
 
VOID NTAPI RtlWakeConditionVariable (IN OUT PRTL_CONDITION_VARIABLE ConditionVariable)
 
VOID NTAPI RtlWakeAllConditionVariable (IN OUT PRTL_CONDITION_VARIABLE ConditionVariable)
 
NTSTATUS NTAPI RtlSleepConditionVariableCS (IN OUT PRTL_CONDITION_VARIABLE ConditionVariable, IN OUT PRTL_CRITICAL_SECTION CriticalSection, IN PLARGE_INTEGER TimeOut OPTIONAL)
 
NTSTATUS NTAPI RtlSleepConditionVariableSRW (IN OUT PRTL_CONDITION_VARIABLE ConditionVariable, IN OUT PRTL_SRWLOCK SRWLock, IN PLARGE_INTEGER TimeOut OPTIONAL, IN ULONG Flags)
 
VOID NTAPI RtlInitializeSRWLock (OUT PRTL_SRWLOCK SRWLock)
 
VOID NTAPI RtlAcquireSRWLockShared (IN OUT PRTL_SRWLOCK SRWLock)
 
VOID NTAPI RtlReleaseSRWLockShared (IN OUT PRTL_SRWLOCK SRWLock)
 
VOID NTAPI RtlAcquireSRWLockExclusive (IN OUT PRTL_SRWLOCK SRWLock)
 
VOID NTAPI RtlReleaseSRWLockExclusive (IN OUT PRTL_SRWLOCK SRWLock)
 
VOID WINAPI AcquireSRWLockExclusive (PSRWLOCK Lock)
 
VOID WINAPI AcquireSRWLockShared (PSRWLOCK Lock)
 
VOID WINAPI InitializeConditionVariable (PCONDITION_VARIABLE ConditionVariable)
 
VOID WINAPI InitializeSRWLock (PSRWLOCK Lock)
 
VOID WINAPI ReleaseSRWLockExclusive (PSRWLOCK Lock)
 
VOID WINAPI ReleaseSRWLockShared (PSRWLOCK Lock)
 
FORCEINLINE PLARGE_INTEGER GetNtTimeout (PLARGE_INTEGER Time, DWORD Timeout)
 
BOOL WINAPI SleepConditionVariableCS (PCONDITION_VARIABLE ConditionVariable, PCRITICAL_SECTION CriticalSection, DWORD Timeout)
 
BOOL WINAPI SleepConditionVariableSRW (PCONDITION_VARIABLE ConditionVariable, PSRWLOCK Lock, DWORD Timeout, ULONG Flags)
 
VOID WINAPI WakeAllConditionVariable (PCONDITION_VARIABLE ConditionVariable)
 
VOID WINAPI WakeConditionVariable (PCONDITION_VARIABLE ConditionVariable)
 
BOOL WINAPI InitializeCriticalSectionEx (OUT LPCRITICAL_SECTION lpCriticalSection, IN DWORD dwSpinCount, IN DWORD flags)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 3 of file sync.c.

Function Documentation

◆ AcquireSRWLockExclusive()

VOID WINAPI AcquireSRWLockExclusive ( PSRWLOCK  Lock)

Definition at line 54 of file sync.c.

55{
57}
VOID NTAPI RtlAcquireSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:591
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127

Referenced by cache_insert(), compound_encode_send_decode(), create_new_rpc_auth(), deleg_lock_update(), delegation_flush_locks(), delegation_recovery_status(), delegation_remove(), delete_stale_component(), device_fetch(), do_open(), file_layout_fetch(), file_layout_recall(), file_layout_return(), get_volume_size_info(), handle_nfs41_set_size(), layout_commit(), nfs41_attr_cache_update(), nfs41_client_delegation_return_lru(), nfs41_client_renew(), nfs41_delegate_open(), nfs41_delegation_recall(), nfs41_delegation_remove_srvopen(), nfs41_delegation_return(), nfs41_delegation_to_open(), nfs41_name_cache_delegreturn(), nfs41_name_cache_insert(), nfs41_name_cache_remove(), nfs41_name_cache_rename(), nfs41_send_compound(), nfs41_session_create(), nfs41_session_free(), nfs41_session_renew(), nfs41_superblock_for_fh(), nfs41_superblock_space_changed(), open_lock_add(), open_lock_delegate(), open_state_rename(), open_unlock_delegate(), open_unlock_remove(), pnfs_data_server_client(), pnfs_layout_io_finished(), pnfs_layout_recall_fenced(), pnfs_layout_state_close(), pnfs_layout_state_open(), pnfs_read(), pnfs_write(), recover_delegation_open(), recover_delegation_want(), recover_locks(), recover_open(), referral_resolve(), rpc_reconnect(), rpc_renew_in_progress(), rpc_should_retry(), and server_addrs_add().

◆ AcquireSRWLockShared()

◆ GetNtTimeout()

FORCEINLINE PLARGE_INTEGER GetNtTimeout ( PLARGE_INTEGER  Time,
DWORD  Timeout 
)

Definition at line 96 of file sync.c.

97{
98 if (Timeout == INFINITE) return NULL;
99 Time->QuadPart = (ULONGLONG)Timeout * -10000;
100 return Time;
101}
#define NULL
Definition: types.h:112
#define INFINITE
Definition: serial.h:102
static PLARGE_INTEGER Time
Definition: time.c:105
static ULONG Timeout
Definition: ping.c:61
uint64_t ULONGLONG
Definition: typedefs.h:67
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by SleepConditionVariableCS(), and SleepConditionVariableSRW().

◆ InitializeConditionVariable()

VOID WINAPI InitializeConditionVariable ( PCONDITION_VARIABLE  ConditionVariable)

Definition at line 68 of file sync.c.

69{
71}
VOID NTAPI RtlInitializeConditionVariable(OUT PRTL_CONDITION_VARIABLE ConditionVariable)
Definition: condvar.c:479

Referenced by delegation_create(), layout_state_create(), nfs41_client_create(), and session_alloc().

◆ InitializeCriticalSectionEx()

BOOL WINAPI InitializeCriticalSectionEx ( OUT LPCRITICAL_SECTION  lpCriticalSection,
IN DWORD  dwSpinCount,
IN DWORD  flags 
)

Definition at line 153 of file sync.c.

156{
158
159 /* FIXME: Flags ignored */
160
161 /* Initialize the critical section */
163 (PRTL_CRITICAL_SECTION)lpCriticalSection,
164 dwSpinCount);
165 if (!NT_SUCCESS(Status))
166 {
167 /* Set failure code */
169 return FALSE;
170 }
171
172 /* Success */
173 return TRUE;
174}
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:752
Status
Definition: gdiplustypes.h:25
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSectionAndSpinCount(_In_ PRTL_CRITICAL_SECTION CriticalSection, _In_ ULONG SpinCount)

◆ InitializeSRWLock()

◆ ReleaseSRWLockExclusive()

VOID WINAPI ReleaseSRWLockExclusive ( PSRWLOCK  Lock)

Definition at line 82 of file sync.c.

83{
85}
VOID NTAPI RtlReleaseSRWLockExclusive(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:710

Referenced by cache_insert(), compound_encode_send_decode(), create_new_rpc_auth(), deleg_lock_update(), delegation_flush_locks(), delegation_recovery_status(), delegation_remove(), delete_stale_component(), device_fetch(), do_open(), file_layout_fetch(), file_layout_recall(), file_layout_return(), get_volume_size_info(), handle_nfs41_set_size(), layout_commit(), nfs41_attr_cache_update(), nfs41_client_delegation_return_lru(), nfs41_client_renew(), nfs41_delegate_open(), nfs41_delegation_recall(), nfs41_delegation_remove_srvopen(), nfs41_delegation_return(), nfs41_delegation_to_open(), nfs41_name_cache_delegreturn(), nfs41_name_cache_insert(), nfs41_name_cache_remove(), nfs41_name_cache_rename(), nfs41_send_compound(), nfs41_session_create(), nfs41_session_free(), nfs41_session_renew(), nfs41_superblock_for_fh(), nfs41_superblock_space_changed(), open_lock_add(), open_lock_delegate(), open_state_rename(), open_unlock_delegate(), open_unlock_remove(), pnfs_data_server_client(), pnfs_layout_io_finished(), pnfs_layout_recall_fenced(), pnfs_layout_state_close(), pnfs_layout_state_open(), pnfs_read(), pnfs_write(), recover_delegation_open(), recover_delegation_want(), recover_locks(), recover_open(), referral_resolve(), rpc_reconnect(), rpc_renew_in_progress(), rpc_should_retry(), and server_addrs_add().

◆ ReleaseSRWLockShared()

◆ RtlAcquireSRWLockExclusive()

VOID NTAPI RtlAcquireSRWLockExclusive ( IN OUT PRTL_SRWLOCK  SRWLock)

Definition at line 591 of file srw.c.

592{
593 __ALIGNED(16) RTLP_SRWLOCK_WAITBLOCK StackWaitBlock;
595
598 {
599 LONG_PTR CurrentValue, NewValue;
600
601 while (1)
602 {
603 CurrentValue = *(volatile LONG_PTR *)&SRWLock->Ptr;
604
605 if (CurrentValue & RTL_SRWLOCK_SHARED)
606 {
607 /* A shared lock is being held right now. We need to add a wait block! */
608
609 if (CurrentValue & RTL_SRWLOCK_CONTENDED)
610 {
611 goto AddWaitBlock;
612 }
613 else
614 {
615 /* There are no wait blocks so far, we need to add ourselves as the first
616 wait block. We need to keep the shared count! */
617 StackWaitBlock.Exclusive = TRUE;
618 StackWaitBlock.SharedCount = (LONG)(CurrentValue >> RTL_SRWLOCK_BITS);
619 StackWaitBlock.Next = NULL;
620 StackWaitBlock.Last = &StackWaitBlock;
621 StackWaitBlock.Wake = 0;
622
624
626 (PVOID)NewValue,
627 (PVOID)CurrentValue) == CurrentValue)
628 {
630 &StackWaitBlock);
631
632 /* Successfully acquired the exclusive lock */
633 break;
634 }
635 }
636 }
637 else
638 {
639 if (CurrentValue & RTL_SRWLOCK_OWNED)
640 {
641 /* An exclusive lock is being held right now. We need to add a wait block! */
642
643 if (CurrentValue & RTL_SRWLOCK_CONTENDED)
644 {
645AddWaitBlock:
646 StackWaitBlock.Exclusive = TRUE;
647 StackWaitBlock.SharedCount = 0;
648 StackWaitBlock.Next = NULL;
649 StackWaitBlock.Last = &StackWaitBlock;
650 StackWaitBlock.Wake = 0;
651
653 if (First != NULL)
654 {
655 Last = First->Last;
656 Last->Next = &StackWaitBlock;
657 First->Last = &StackWaitBlock;
658
660
662 &StackWaitBlock);
663
664 /* Successfully acquired the exclusive lock */
665 break;
666 }
667 }
668 else
669 {
670 /* There are no wait blocks so far, we need to add ourselves as the first
671 wait block. We need to keep the shared count! */
672 StackWaitBlock.Exclusive = TRUE;
673 StackWaitBlock.SharedCount = 0;
674 StackWaitBlock.Next = NULL;
675 StackWaitBlock.Last = &StackWaitBlock;
676 StackWaitBlock.Wake = 0;
677
678 NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED;
680 (PVOID)NewValue,
681 (PVOID)CurrentValue) == CurrentValue)
682 {
684 &StackWaitBlock);
685
686 /* Successfully acquired the exclusive lock */
687 break;
688 }
689 }
690 }
691 else
692 {
693 if (!InterlockedBitTestAndSetPointer(&SRWLock->Ptr,
695 {
696 /* We managed to get hold of a simple exclusive lock! */
697 break;
698 }
699 }
700 }
701
703 }
704 }
705}
WCHAR First[]
Definition: FormatMessage.c:11
#define ULONG_PTR
Definition: config.h:101
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
if(dx< 0)
Definition: linetemp.h:194
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
typedef __ALIGNED(16) struct _EX_PUSH_LOCK_WAIT_BLOCK
Definition: extypes.h:483
long LONG
Definition: pedump.c:60
#define YieldProcessor
Definition: ke.h:48
#define RTL_SRWLOCK_CONTENDED
Definition: srw.c:42
static VOID NTAPI RtlpReleaseWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:190
#define RTL_SRWLOCK_BITS
Definition: srw.c:47
static VOID NTAPI RtlpAcquireSRWLockExclusiveWait(IN OUT PRTL_SRWLOCK SRWLock, IN PRTLP_SRWLOCK_WAITBLOCK WaitBlock)
Definition: srw.c:232
#define RTL_SRWLOCK_SHARED
Definition: srw.c:43
#define RTL_SRWLOCK_OWNED
Definition: srw.c:41
#define InterlockedBitTestAndSetPointer(ptr, val)
Definition: srw.c:30
#define RTL_SRWLOCK_OWNED_BIT
Definition: srw.c:37
static PRTLP_SRWLOCK_WAITBLOCK NTAPI RtlpAcquireWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:199
volatile struct _RTLP_SRWLOCK_WAITBLOCK * Last
Definition: srw.c:62
BOOLEAN Exclusive
Definition: srw.c:79
volatile struct _RTLP_SRWLOCK_WAITBLOCK * Next
Definition: srw.c:65

Referenced by AcquireDynamicFunctionTableLockExclusive(), and AcquireSRWLockExclusive().

◆ RtlAcquireSRWLockShared()

VOID NTAPI RtlAcquireSRWLockShared ( IN OUT PRTL_SRWLOCK  SRWLock)

Definition at line 325 of file srw.c.

326{
327 __ALIGNED(16) RTLP_SRWLOCK_WAITBLOCK StackWaitBlock;
328 RTLP_SRWLOCK_SHARED_WAKE SharedWake;
329 LONG_PTR CurrentValue, NewValue;
330 PRTLP_SRWLOCK_WAITBLOCK First, Shared, FirstWait;
331
332 while (1)
333 {
334 CurrentValue = *(volatile LONG_PTR *)&SRWLock->Ptr;
335
336 if (CurrentValue & RTL_SRWLOCK_SHARED)
337 {
338 /* NOTE: It is possible that the RTL_SRWLOCK_OWNED bit is set! */
339
340 if (CurrentValue & RTL_SRWLOCK_CONTENDED)
341 {
342 /* There's other waiters already, lock the wait blocks and
343 increment the shared count */
345 if (First != NULL)
346 {
347 FirstWait = NULL;
348
349 if (First->Exclusive)
350 {
351 /* We need to setup a new wait block! Although
352 we're currently in a shared lock and we're acquiring
353 a shared lock, there are exclusive locks queued. We need
354 to wait until those are released. */
355 Shared = First->Last;
356
357 if (Shared->Exclusive)
358 {
359 StackWaitBlock.Exclusive = FALSE;
360 StackWaitBlock.SharedCount = 1;
361 StackWaitBlock.Next = NULL;
362 StackWaitBlock.Last = &StackWaitBlock;
363 StackWaitBlock.SharedWakeChain = &SharedWake;
364
365 Shared->Next = &StackWaitBlock;
366 First->Last = &StackWaitBlock;
367
368 Shared = &StackWaitBlock;
369 FirstWait = &StackWaitBlock;
370 }
371 else
372 {
373 Shared->LastSharedWake->Next = &SharedWake;
374 Shared->SharedCount++;
375 }
376 }
377 else
378 {
379 Shared = First;
380 Shared->LastSharedWake->Next = &SharedWake;
381 Shared->SharedCount++;
382 }
383
384 SharedWake.Next = NULL;
385 SharedWake.Wake = 0;
386
387 Shared->LastSharedWake = &SharedWake;
388
390
392 FirstWait,
393 &SharedWake);
394
395 /* Successfully incremented the shared count, we acquired the lock */
396 break;
397 }
398 }
399 else
400 {
401 /* This is a fastest path, just increment the number of
402 current shared locks */
403
404 /* Since the RTL_SRWLOCK_SHARED bit is set, the RTL_SRWLOCK_OWNED bit also has
405 to be set! */
406
407 ASSERT(CurrentValue & RTL_SRWLOCK_OWNED);
408
409 NewValue = (CurrentValue >> RTL_SRWLOCK_BITS) + 1;
410 NewValue = (NewValue << RTL_SRWLOCK_BITS) | (CurrentValue & RTL_SRWLOCK_MASK);
411
413 (PVOID)NewValue,
414 (PVOID)CurrentValue) == CurrentValue)
415 {
416 /* Successfully incremented the shared count, we acquired the lock */
417 break;
418 }
419 }
420 }
421 else
422 {
423 if (CurrentValue & RTL_SRWLOCK_OWNED)
424 {
425 /* The resource is currently acquired exclusively */
426 if (CurrentValue & RTL_SRWLOCK_CONTENDED)
427 {
428 SharedWake.Next = NULL;
429 SharedWake.Wake = 0;
430
431 /* There's other waiters already, lock the wait blocks and
432 increment the shared count. If the last block in the chain
433 is an exclusive lock, add another block. */
434
435 StackWaitBlock.Exclusive = FALSE;
436 StackWaitBlock.SharedCount = 0;
437 StackWaitBlock.Next = NULL;
438 StackWaitBlock.Last = &StackWaitBlock;
439 StackWaitBlock.SharedWakeChain = &SharedWake;
440
442 if (First != NULL)
443 {
444 Shared = First->Last;
445 if (Shared->Exclusive)
446 {
447 Shared->Next = &StackWaitBlock;
448 First->Last = &StackWaitBlock;
449
450 Shared = &StackWaitBlock;
451 FirstWait = &StackWaitBlock;
452 }
453 else
454 {
455 FirstWait = NULL;
456 Shared->LastSharedWake->Next = &SharedWake;
457 }
458
459 Shared->SharedCount++;
460 Shared->LastSharedWake = &SharedWake;
461
463
465 FirstWait,
466 &SharedWake);
467
468 /* Successfully incremented the shared count, we acquired the lock */
469 break;
470 }
471 }
472 else
473 {
474 SharedWake.Next = NULL;
475 SharedWake.Wake = 0;
476
477 /* We need to setup the first wait block. Currently an exclusive lock is
478 held, change the lock to contended mode. */
479 StackWaitBlock.Exclusive = FALSE;
480 StackWaitBlock.SharedCount = 1;
481 StackWaitBlock.Next = NULL;
482 StackWaitBlock.Last = &StackWaitBlock;
483 StackWaitBlock.SharedWakeChain = &SharedWake;
484 StackWaitBlock.LastSharedWake = &SharedWake;
485
486 NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_OWNED | RTL_SRWLOCK_CONTENDED;
488 (PVOID)NewValue,
489 (PVOID)CurrentValue) == CurrentValue)
490 {
492 &StackWaitBlock,
493 &SharedWake);
494
495 /* Successfully set the shared count, we acquired the lock */
496 break;
497 }
498 }
499 }
500 else
501 {
502 /* This is a fast path, we can simply try to set the shared count to 1 */
504
505 /* The RTL_SRWLOCK_CONTENDED bit should never be set if neither the
506 RTL_SRWLOCK_SHARED nor the RTL_SRWLOCK_OWNED bit is set */
507 ASSERT(!(CurrentValue & RTL_SRWLOCK_CONTENDED));
508
510 (PVOID)NewValue,
511 (PVOID)CurrentValue) == CurrentValue)
512 {
513 /* Successfully set the shared count, we acquired the lock */
514 break;
515 }
516 }
517 }
518
520 }
521}
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
#define ASSERT(a)
Definition: mode.c:44
static VOID NTAPI RtlpAcquireSRWLockSharedWait(IN OUT PRTL_SRWLOCK SRWLock, IN OUT PRTLP_SRWLOCK_WAITBLOCK FirstWait OPTIONAL, IN OUT PRTLP_SRWLOCK_SHARED_WAKE WakeChain)
Definition: srw.c:267
#define RTL_SRWLOCK_MASK
Definition: srw.c:45
volatile struct _RTLP_SRWLOCK_SHARED_WAKE * Next
Definition: srw.c:52
PRTLP_SRWLOCK_SHARED_WAKE SharedWakeChain
Definition: srw.c:74
PRTLP_SRWLOCK_SHARED_WAKE LastSharedWake
Definition: srw.c:75

Referenced by AcquireDynamicFunctionTableLockShared(), and AcquireSRWLockShared().

◆ RtlInitializeConditionVariable()

VOID NTAPI RtlInitializeConditionVariable ( OUT PRTL_CONDITION_VARIABLE  ConditionVariable)

Definition at line 479 of file condvar.c.

480{
481 ConditionVariable->Ptr = NULL;
482}

Referenced by InitializeConditionVariable().

◆ RtlInitializeSRWLock()

VOID NTAPI RtlInitializeSRWLock ( OUT PRTL_SRWLOCK  SRWLock)

Definition at line 317 of file srw.c.

318{
319 SRWLock->Ptr = NULL;
320}

Referenced by InitializeSRWLock().

◆ RtlReleaseSRWLockExclusive()

VOID NTAPI RtlReleaseSRWLockExclusive ( IN OUT PRTL_SRWLOCK  SRWLock)

Definition at line 710 of file srw.c.

711{
712 LONG_PTR CurrentValue, NewValue;
713 PRTLP_SRWLOCK_WAITBLOCK WaitBlock;
714
715 while (1)
716 {
717 CurrentValue = *(volatile LONG_PTR *)&SRWLock->Ptr;
718
719 if (!(CurrentValue & RTL_SRWLOCK_OWNED))
720 {
722 }
723
724 if (!(CurrentValue & RTL_SRWLOCK_SHARED))
725 {
726 if (CurrentValue & RTL_SRWLOCK_CONTENDED)
727 {
728 /* There's a wait block, we need to wake the next pending
729 acquirer (exclusive or shared) */
730 WaitBlock = RtlpAcquireWaitBlockLock(SRWLock);
731 if (WaitBlock != NULL)
732 {
734 WaitBlock);
735
736 /* We released the lock */
737 break;
738 }
739 }
740 else
741 {
742 /* This is a fast path, we can simply clear the RTL_SRWLOCK_OWNED
743 bit. All other bits should be 0 now because this is a simple
744 exclusive lock and no one is waiting. */
745
746 ASSERT(!(CurrentValue & ~RTL_SRWLOCK_OWNED));
747
748 NewValue = 0;
750 (PVOID)NewValue,
751 (PVOID)CurrentValue) == CurrentValue)
752 {
753 /* We released the lock */
754 break;
755 }
756 }
757 }
758 else
759 {
760 /* The RTL_SRWLOCK_SHARED bit must not be present now,
761 not even in the contended case! */
763 }
764
766 }
767}
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#define STATUS_RESOURCE_NOT_OWNED
Definition: ntstatus.h:737
static VOID NTAPI RtlpReleaseWaitBlockLockExclusive(IN OUT PRTL_SRWLOCK SRWLock, IN PRTLP_SRWLOCK_WAITBLOCK FirstWaitBlock)
Definition: srw.c:85

Referenced by ReleaseDynamicFunctionTableLockExclusive(), and ReleaseSRWLockExclusive().

◆ RtlReleaseSRWLockShared()

VOID NTAPI RtlReleaseSRWLockShared ( IN OUT PRTL_SRWLOCK  SRWLock)

Definition at line 526 of file srw.c.

527{
528 LONG_PTR CurrentValue, NewValue;
529 PRTLP_SRWLOCK_WAITBLOCK WaitBlock;
530 BOOLEAN LastShared;
531
532 while (1)
533 {
534 CurrentValue = *(volatile LONG_PTR *)&SRWLock->Ptr;
535
536 if (CurrentValue & RTL_SRWLOCK_SHARED)
537 {
538 if (CurrentValue & RTL_SRWLOCK_CONTENDED)
539 {
540 /* There's a wait block, we need to wake a pending
541 exclusive acquirer if this is the last shared release */
542 WaitBlock = RtlpAcquireWaitBlockLock(SRWLock);
543 if (WaitBlock != NULL)
544 {
545 LastShared = (--WaitBlock->SharedCount == 0);
546
547 if (LastShared)
549 WaitBlock);
550 else
552
553 /* We released the lock */
554 break;
555 }
556 }
557 else
558 {
559 /* This is a fast path, we can simply decrement the shared
560 count and store the pointer */
561 NewValue = CurrentValue >> RTL_SRWLOCK_BITS;
562
563 if (--NewValue != 0)
564 {
565 NewValue = (NewValue << RTL_SRWLOCK_BITS) | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_OWNED;
566 }
567
569 (PVOID)NewValue,
570 (PVOID)CurrentValue) == CurrentValue)
571 {
572 /* Successfully released the lock */
573 break;
574 }
575 }
576 }
577 else
578 {
579 /* The RTL_SRWLOCK_SHARED bit has to be present now,
580 even in the contended case! */
582 }
583
585 }
586}
unsigned char BOOLEAN
static VOID NTAPI RtlpReleaseWaitBlockLockLastShared(IN OUT PRTL_SRWLOCK SRWLock, IN PRTLP_SRWLOCK_WAITBLOCK FirstWaitBlock)
Definition: srw.c:155

Referenced by ReleaseDynamicFunctionTableLockShared(), and ReleaseSRWLockShared().

◆ RtlSleepConditionVariableCS()

NTSTATUS NTAPI RtlSleepConditionVariableCS ( IN OUT PRTL_CONDITION_VARIABLE  ConditionVariable,
IN OUT PRTL_CRITICAL_SECTION  CriticalSection,
IN PLARGE_INTEGER TimeOut  OPTIONAL 
)

◆ RtlSleepConditionVariableSRW()

NTSTATUS NTAPI RtlSleepConditionVariableSRW ( IN OUT PRTL_CONDITION_VARIABLE  ConditionVariable,
IN OUT PRTL_SRWLOCK  SRWLock,
IN PLARGE_INTEGER TimeOut  OPTIONAL,
IN ULONG  Flags 
)

◆ RtlWakeAllConditionVariable()

VOID NTAPI RtlWakeAllConditionVariable ( IN OUT PRTL_CONDITION_VARIABLE  ConditionVariable)

Definition at line 493 of file condvar.c.

494{
495 InternalWake(ConditionVariable, TRUE);
496}
static VOID InternalWake(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable, IN BOOLEAN ReleaseAll)
Definition: condvar.c:259

Referenced by WakeAllConditionVariable().

◆ RtlWakeConditionVariable()

VOID NTAPI RtlWakeConditionVariable ( IN OUT PRTL_CONDITION_VARIABLE  ConditionVariable)

Definition at line 486 of file condvar.c.

487{
488 InternalWake(ConditionVariable, FALSE);
489}

Referenced by WakeConditionVariable().

◆ SleepConditionVariableCS()

BOOL WINAPI SleepConditionVariableCS ( PCONDITION_VARIABLE  ConditionVariable,
PCRITICAL_SECTION  CriticalSection,
DWORD  Timeout 
)

Definition at line 105 of file sync.c.

106{
109
112 {
114 return FALSE;
115 }
116 return TRUE;
117}
FORCEINLINE PLARGE_INTEGER GetNtTimeout(PLARGE_INTEGER Time, DWORD Timeout)
Definition: sync.c:96
NTSTATUS NTAPI RtlSleepConditionVariableCS(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable, IN OUT PRTL_CRITICAL_SECTION CriticalSection, IN PLARGE_INTEGER TimeOut OPTIONAL)
CRITICAL_SECTION CriticalSection
Definition: iprtprio.c:40
#define STATUS_TIMEOUT
Definition: ntstatus.h:81

Referenced by nfs41_recover_stateid(), nfs41_recovery_start_or_wait(), and nfs41_session_get_slot().

◆ SleepConditionVariableSRW()

BOOL WINAPI SleepConditionVariableSRW ( PCONDITION_VARIABLE  ConditionVariable,
PSRWLOCK  Lock,
DWORD  Timeout,
ULONG  Flags 
)

Definition at line 121 of file sync.c.

122{
125
128 {
130 return FALSE;
131 }
132 return TRUE;
133}
NTSTATUS NTAPI RtlSleepConditionVariableSRW(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable, IN OUT PRTL_SRWLOCK SRWLock, IN PLARGE_INTEGER TimeOut OPTIONAL, IN ULONG Flags)
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by file_layout_return(), layout_fetch(), nfs41_delegate_open(), nfs41_delegation_return(), nfs41_delegation_to_open(), and nfs41_open_stateid_arg().

◆ WakeAllConditionVariable()

VOID WINAPI WakeAllConditionVariable ( PCONDITION_VARIABLE  ConditionVariable)

Definition at line 137 of file sync.c.

138{
140}
VOID NTAPI RtlWakeAllConditionVariable(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable)
Definition: condvar.c:493

Referenced by delegation_remove(), init_slot_table(), nfs41_delegation_to_open(), nfs41_recovery_finish(), nfs41_session_free_slot(), and resize_slot_table().

◆ WakeConditionVariable()

VOID WINAPI WakeConditionVariable ( PCONDITION_VARIABLE  ConditionVariable)

Definition at line 144 of file sync.c.

145{
147}
VOID NTAPI RtlWakeConditionVariable(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable)
Definition: condvar.c:486

Referenced by file_layout_return(), and layout_fetch().