ReactOS 0.4.15-dev-8393-g61b7fb9
runonce.c File Reference
#include <rtl_vista.h>
#include <wine/config.h>
#include <wine/port.h>
Include dependency graph for runonce.c:

Go to the source code of this file.

Functions

VOID NTAPI RtlRunOnceInitialize (_Out_ PRTL_RUN_ONCE RunOnce)
 
_Must_inspect_result_ NTSTATUS NTAPI RtlRunOnceBeginInitialize (_Inout_ PRTL_RUN_ONCE RunOnce, _In_ ULONG Flags, _Outptr_opt_result_maybenull_ PVOID *Context)
 
NTSTATUS NTAPI RtlRunOnceComplete (_Inout_ PRTL_RUN_ONCE RunOnce, _In_ ULONG Flags, _In_opt_ PVOID Context)
 
_Maybe_raises_SEH_exception_ NTSTATUS NTAPI RtlRunOnceExecuteOnce (_Inout_ PRTL_RUN_ONCE RunOnce, _In_ __inner_callback PRTL_RUN_ONCE_INIT_FN InitFn, _Inout_opt_ PVOID Parameter, _Outptr_opt_result_maybenull_ PVOID *Context)
 

Function Documentation

◆ RtlRunOnceBeginInitialize()

_Must_inspect_result_ NTSTATUS NTAPI RtlRunOnceBeginInitialize ( _Inout_ PRTL_RUN_ONCE  RunOnce,
_In_ ULONG  Flags,
_Outptr_opt_result_maybenull_ PVOID Context 
)

Definition at line 22 of file runonce.c.

26{
28 {
29 ULONG_PTR val = (ULONG_PTR)RunOnce->Ptr;
30
32 if ((val & 3) != 2) return STATUS_UNSUCCESSFUL;
33 if (Context) *Context = (void *)(val & ~3);
34 return STATUS_SUCCESS;
35 }
36
37 for (;;)
38 {
39 ULONG_PTR next, val = (ULONG_PTR)RunOnce->Ptr;
40
41 switch (val & 3)
42 {
43 case 0: /* first time */
44 if (!interlocked_cmpxchg_ptr( &RunOnce->Ptr,
45 (Flags & RTL_RUN_ONCE_ASYNC) ? (void *)3 : (void *)1, 0))
46 return STATUS_PENDING;
47 break;
48
49 case 1: /* in progress, wait */
51 next = val & ~3;
52 if (interlocked_cmpxchg_ptr( &RunOnce->Ptr, (void *)((ULONG_PTR)&next | 1),
53 (void *)val ) == (void *)val)
55 break;
56
57 case 2: /* done */
58 if (Context) *Context = (void *)(val & ~3);
59 return STATUS_SUCCESS;
60
61 case 3: /* in progress, async */
63 return STATUS_PENDING;
64 }
65 }
66}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
switch(r->id)
Definition: btrfs.c:3046
#define ULONG_PTR
Definition: config.h:101
GLuint GLfloat * val
Definition: glext.h:7180
NTSYSAPI NTSTATUS WINAPI NtWaitForKeyedEvent(HANDLE, const void *, BOOLEAN, const LARGE_INTEGER *)
if(dx< 0)
Definition: linetemp.h:194
#define STATUS_PENDING
Definition: ntstatus.h:82
static unsigned __int64 next
Definition: rand_nt.c:6
#define interlocked_cmpxchg_ptr
Definition: port.h:344
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define RTL_RUN_ONCE_CHECK_ONLY
#define RTL_RUN_ONCE_ASYNC

Referenced by InitOnceBeginInitialize(), and RtlRunOnceExecuteOnce().

◆ RtlRunOnceComplete()

NTSTATUS NTAPI RtlRunOnceComplete ( _Inout_ PRTL_RUN_ONCE  RunOnce,
_In_ ULONG  Flags,
_In_opt_ PVOID  Context 
)

Definition at line 73 of file runonce.c.

77{
79
81 {
84 }
85 else Context = (void *)((ULONG_PTR)Context | 2);
86
87 for (;;)
88 {
89 ULONG_PTR val = (ULONG_PTR)RunOnce->Ptr;
90
91 switch (val & 3)
92 {
93 case 1: /* in progress */
94 if (interlocked_cmpxchg_ptr( &RunOnce->Ptr, Context, (void *)val ) != (void *)val) break;
95 val &= ~3;
96 while (val)
97 {
99 NtReleaseKeyedEvent( 0, (void *)val, FALSE, NULL );
100 val = next;
101 }
102 return STATUS_SUCCESS;
103
104 case 3: /* in progress, async */
106 if (interlocked_cmpxchg_ptr( &RunOnce->Ptr, Context, (void *)val) != (void *)val) break;
107 return STATUS_SUCCESS;
108
109 default:
110 return STATUS_UNSUCCESSFUL;
111 }
112 }
113}
NTSYSAPI NTSTATUS WINAPI NtReleaseKeyedEvent(HANDLE, const void *, BOOLEAN, const LARGE_INTEGER *)
#define RTL_RUN_ONCE_INIT_FAILED

Referenced by InitOnceComplete(), and RtlRunOnceExecuteOnce().

◆ RtlRunOnceExecuteOnce()

Definition at line 121 of file runonce.c.

126{
128
129 if (ret != STATUS_PENDING) return ret;
130
131 if (!InitFn( RunOnce, Parameter, Context ))
132 {
134 return STATUS_UNSUCCESSFUL;
135 }
136
137 return RtlRunOnceComplete( RunOnce, 0, Context ? *Context : NULL );
138}
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSTATUS NTAPI RtlRunOnceComplete(_Inout_ PRTL_RUN_ONCE RunOnce, _In_ ULONG Flags, _In_opt_ PVOID Context)
Definition: runonce.c:73
_Must_inspect_result_ NTSTATUS NTAPI RtlRunOnceBeginInitialize(_Inout_ PRTL_RUN_ONCE RunOnce, _In_ ULONG Flags, _Outptr_opt_result_maybenull_ PVOID *Context)
Definition: runonce.c:22
int ret
_In_ __inner_callback PRTL_RUN_ONCE_INIT_FN InitFn
Definition: rtlfuncs.h:2533
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

Referenced by InitOnceExecuteOnce().

◆ RtlRunOnceInitialize()

VOID NTAPI RtlRunOnceInitialize ( _Out_ PRTL_RUN_ONCE  RunOnce)

Definition at line 11 of file runonce.c.

12{
13 RunOnce->Ptr = NULL;
14}