ReactOS  0.4.15-dev-2972-gda2a567
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:124

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()

VOID WINAPI AcquireSRWLockShared ( PSRWLOCK  Lock)

Definition at line 61 of file sync.c.

62 {
64 }
VOID NTAPI RtlAcquireSRWLockShared(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:325
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124

Referenced by cache_lookup(), cl_addr_compare(), cl_exid_compare(), client_server(), client_supports_pnfs(), compound_encode_send_decode(), deleg_lock_find(), delegation_flush_locks(), delegation_return(), file_layout_return(), get_path_fhs(), get_volume_size_info(), layout_commit(), lock_stateid_arg(), nfs41_attr_cache_lookup(), nfs41_create(), nfs41_create_session(), nfs41_delegation_getattr(), nfs41_delegation_to_open(), nfs41_delegreturn(), nfs41_link(), nfs41_lookup(), nfs41_name_cache_lookup(), nfs41_name_cache_remove_stale(), nfs41_open_stateid_arg(), nfs41_remove(), nfs41_rename(), nfs41_rpc_netaddr(), nfs41_send_compound(), nfs41_server_addrs(), nfs41_session_bump_seq(), nfs41_session_create(), nfs41_session_free_slot(), nfs41_session_get_slot(), nfs41_session_recall_slot(), nfs41_superblock_for_fh(), open_deleg_cmp(), open_lock_delegate(), open_update_cache(), pnfs_data_server_client(), pnfs_layout_state_close(), pnfs_layout_state_open(), recover_delegation_open(), recover_delegation_want(), recover_open(), recover_stateid_delegation(), recover_stateid_lock(), recover_stateid_open(), session_get_lease(), stateid_array(), and thread_next_unit().

◆ 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 }
uint64_t ULONGLONG
Definition: typedefs.h:67
static ULONG Timeout
Definition: ping.c:61
#define NULL
Definition: types.h:112
#define INFINITE
Definition: serial.h:102
static PLARGE_INTEGER Time
Definition: time.c:105
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:477

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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSectionAndSpinCount(_In_ PRTL_CRITICAL_SECTION CriticalSection, _In_ ULONG SpinCount)
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:611

◆ InitializeSRWLock()

VOID WINAPI InitializeSRWLock ( PSRWLOCK  Lock)

◆ 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
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124

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()

VOID WINAPI ReleaseSRWLockShared ( PSRWLOCK  Lock)

◆ 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 
623  NewValue = (ULONG_PTR)&StackWaitBlock | RTL_SRWLOCK_SHARED | RTL_SRWLOCK_CONTENDED | RTL_SRWLOCK_OWNED;
624 
625  if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr,
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  {
645 AddWaitBlock:
646  StackWaitBlock.Exclusive = TRUE;
647  StackWaitBlock.SharedCount = 0;
648  StackWaitBlock.Next = NULL;
649  StackWaitBlock.Last = &StackWaitBlock;
650  StackWaitBlock.Wake = 0;
651 
652  First = RtlpAcquireWaitBlockLock(SRWLock);
653  if (First != NULL)
654  {
655  Last = First->Last;
656  Last->Next = &StackWaitBlock;
657  First->Last = &StackWaitBlock;
658 
659  RtlpReleaseWaitBlockLock(SRWLock);
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;
679  if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr,
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 
702  YieldProcessor();
703  }
704  }
705 }
#define InterlockedBitTestAndSetPointer(ptr, val)
Definition: srw.c:30
#define TRUE
Definition: types.h:120
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
typedef __ALIGNED(16) struct _EX_PUSH_LOCK_WAIT_BLOCK
Definition: extypes.h:483
if(dx==0 &&dy==0)
Definition: linetemp.h:174
volatile struct _RTLP_SRWLOCK_WAITBLOCK * Next
Definition: srw.c:65
FORCEINLINE VOID YieldProcessor(VOID)
Definition: ke.h:32
WCHAR First[]
Definition: FormatMessage.c:11
#define RTL_SRWLOCK_CONTENDED
Definition: srw.c:42
long LONG
Definition: pedump.c:60
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
volatile struct _RTLP_SRWLOCK_WAITBLOCK * Last
Definition: srw.c:62
#define RTL_SRWLOCK_BITS
Definition: srw.c:47
#define RTL_SRWLOCK_OWNED
Definition: srw.c:41
#define RTL_SRWLOCK_SHARED
Definition: srw.c:43
BOOLEAN Exclusive
Definition: srw.c:79
#define RTL_SRWLOCK_OWNED_BIT
Definition: srw.c:37
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
static PRTLP_SRWLOCK_WAITBLOCK NTAPI RtlpAcquireWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:199
static VOID NTAPI RtlpAcquireSRWLockExclusiveWait(IN OUT PRTL_SRWLOCK SRWLock, IN PRTLP_SRWLOCK_WAITBLOCK WaitBlock)
Definition: srw.c:232
static VOID NTAPI RtlpReleaseWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:190

Referenced by 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 */
344  First = RtlpAcquireWaitBlockLock(SRWLock);
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 
389  RtlpReleaseWaitBlockLock(SRWLock);
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 
412  if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr,
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 
441  First = RtlpAcquireWaitBlockLock(SRWLock);
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 
462  RtlpReleaseWaitBlockLock(SRWLock);
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;
487  if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr,
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 
509  if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr,
510  (PVOID)NewValue,
511  (PVOID)CurrentValue) == CurrentValue)
512  {
513  /* Successfully set the shared count, we acquired the lock */
514  break;
515  }
516  }
517  }
518 
519  YieldProcessor();
520  }
521 }
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
volatile struct _RTLP_SRWLOCK_SHARED_WAKE * Next
Definition: srw.c:52
PRTLP_SRWLOCK_SHARED_WAKE LastSharedWake
Definition: srw.c:75
typedef __ALIGNED(16) struct _EX_PUSH_LOCK_WAIT_BLOCK
Definition: extypes.h:483
if(dx==0 &&dy==0)
Definition: linetemp.h:174
volatile struct _RTLP_SRWLOCK_WAITBLOCK * Next
Definition: srw.c:65
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
FORCEINLINE VOID YieldProcessor(VOID)
Definition: ke.h:32
WCHAR First[]
Definition: FormatMessage.c:11
#define FALSE
Definition: types.h:117
#define RTL_SRWLOCK_CONTENDED
Definition: srw.c:42
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
volatile struct _RTLP_SRWLOCK_WAITBLOCK * Last
Definition: srw.c:62
#define RTL_SRWLOCK_BITS
Definition: srw.c:47
#define RTL_SRWLOCK_MASK
Definition: srw.c:45
#define ASSERT(a)
Definition: mode.c:44
#define RTL_SRWLOCK_OWNED
Definition: srw.c:41
PRTLP_SRWLOCK_SHARED_WAKE SharedWakeChain
Definition: srw.c:74
#define RTL_SRWLOCK_SHARED
Definition: srw.c:43
BOOLEAN Exclusive
Definition: srw.c:79
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
static PRTLP_SRWLOCK_WAITBLOCK NTAPI RtlpAcquireWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:199
static VOID NTAPI RtlpReleaseWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:190

Referenced by AcquireSRWLockShared().

◆ RtlInitializeConditionVariable()

VOID NTAPI RtlInitializeConditionVariable ( OUT PRTL_CONDITION_VARIABLE  ConditionVariable)

Definition at line 477 of file condvar.c.

478 {
479  ConditionVariable->Ptr = NULL;
480 }
#define NULL
Definition: types.h:112

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 }
#define NULL
Definition: types.h:112

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;
749  if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr,
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 
765  YieldProcessor();
766  }
767 }
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
if(dx==0 &&dy==0)
Definition: linetemp.h:174
FORCEINLINE VOID YieldProcessor(VOID)
Definition: ke.h:32
#define RTL_SRWLOCK_CONTENDED
Definition: srw.c:42
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
#define ASSERT(a)
Definition: mode.c:44
#define RTL_SRWLOCK_OWNED
Definition: srw.c:41
#define RTL_SRWLOCK_SHARED
Definition: srw.c:43
static VOID NTAPI RtlpReleaseWaitBlockLockExclusive(IN OUT PRTL_SRWLOCK SRWLock, IN PRTLP_SRWLOCK_WAITBLOCK FirstWaitBlock)
Definition: srw.c:85
#define STATUS_RESOURCE_NOT_OWNED
Definition: ntstatus.h:737
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
static PRTLP_SRWLOCK_WAITBLOCK NTAPI RtlpAcquireWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:199

Referenced by 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
551  RtlpReleaseWaitBlockLock(SRWLock);
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 
568  if ((LONG_PTR)InterlockedCompareExchangePointer(&SRWLock->Ptr,
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 
584  YieldProcessor();
585  }
586 }
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
if(dx==0 &&dy==0)
Definition: linetemp.h:174
FORCEINLINE VOID YieldProcessor(VOID)
Definition: ke.h:32
#define RTL_SRWLOCK_CONTENDED
Definition: srw.c:42
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
unsigned char BOOLEAN
#define RTL_SRWLOCK_BITS
Definition: srw.c:47
#define RTL_SRWLOCK_OWNED
Definition: srw.c:41
#define RTL_SRWLOCK_SHARED
Definition: srw.c:43
static VOID NTAPI RtlpReleaseWaitBlockLockLastShared(IN OUT PRTL_SRWLOCK SRWLock, IN PRTLP_SRWLOCK_WAITBLOCK FirstWaitBlock)
Definition: srw.c:155
#define STATUS_RESOURCE_NOT_OWNED
Definition: ntstatus.h:737
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
static PRTLP_SRWLOCK_WAITBLOCK NTAPI RtlpAcquireWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:199
static VOID NTAPI RtlpReleaseWaitBlockLock(IN OUT PRTL_SRWLOCK SRWLock)
Definition: srw.c:190

Referenced by 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 491 of file condvar.c.

492 {
493  InternalWake(ConditionVariable, TRUE);
494 }
static VOID InternalWake(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable, IN BOOLEAN ReleaseAll)
Definition: condvar.c:259
#define TRUE
Definition: types.h:120

Referenced by WakeAllConditionVariable().

◆ RtlWakeConditionVariable()

VOID NTAPI RtlWakeConditionVariable ( IN OUT PRTL_CONDITION_VARIABLE  ConditionVariable)

Definition at line 484 of file condvar.c.

485 {
486  InternalWake(ConditionVariable, FALSE);
487 }
static VOID InternalWake(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable, IN BOOLEAN ReleaseAll)
Definition: condvar.c:259
#define FALSE
Definition: types.h:117

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 }
NTSTATUS NTAPI RtlSleepConditionVariableCS(IN OUT PRTL_CONDITION_VARIABLE ConditionVariable, IN OUT PRTL_CRITICAL_SECTION CriticalSection, IN PLARGE_INTEGER TimeOut OPTIONAL)
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define FALSE
Definition: types.h:117
CRITICAL_SECTION CriticalSection
Definition: iprtprio.c:40
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:611
FORCEINLINE PLARGE_INTEGER GetNtTimeout(PLARGE_INTEGER Time, DWORD Timeout)
Definition: sync.c:96
static ULONG Timeout
Definition: ping.c:61
static PLARGE_INTEGER Time
Definition: time.c:105

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 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:611
FORCEINLINE PLARGE_INTEGER GetNtTimeout(PLARGE_INTEGER Time, DWORD Timeout)
Definition: sync.c:96
static ULONG Timeout
Definition: ping.c:61
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_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
static PLARGE_INTEGER Time
Definition: time.c:105

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:491

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:484

Referenced by file_layout_return(), and layout_fetch().