ReactOS  0.4.14-dev-317-g96040ec
InitOnceExecuteOnce.c
Go to the documentation of this file.
1 
2 #include "k32_vista.h"
3 
4 #include <ndk/exfuncs.h>
5 #include <wine/config.h>
6 #include <wine/port.h>
7 
8 /* Taken from Wine ntdll/sync.c */
9 
11 
13 {
15  {
16  ULONG_PTR val = (ULONG_PTR)once->Ptr;
17 
19  if ((val & 3) != 2) return STATUS_UNSUCCESSFUL;
20  if (context) *context = (void *)(val & ~3);
21  return STATUS_SUCCESS;
22  }
23 
24  for (;;)
25  {
26  ULONG_PTR next, val = (ULONG_PTR)once->Ptr;
27 
28  switch (val & 3)
29  {
30  case 0: /* first time */
31  if (!interlocked_cmpxchg_ptr( &once->Ptr,
32  (flags & RTL_RUN_ONCE_ASYNC) ? (void *)3 : (void *)1, 0 ))
33  return STATUS_PENDING;
34  break;
35 
36  case 1: /* in progress, wait */
38  next = val & ~3;
39  if (interlocked_cmpxchg_ptr( &once->Ptr, (void *)((ULONG_PTR)&next | 1),
40  (void *)val ) == (void *)val)
42  break;
43 
44  case 2: /* done */
45  if (context) *context = (void *)(val & ~3);
46  return STATUS_SUCCESS;
47 
48  case 3: /* in progress, async */
50  return STATUS_PENDING;
51  }
52  }
53 }
54 
56 {
58 
60  {
63  }
64  else context = (void *)((ULONG_PTR)context | 2);
65 
66  for (;;)
67  {
68  ULONG_PTR val = (ULONG_PTR)once->Ptr;
69 
70  switch (val & 3)
71  {
72  case 1: /* in progress */
73  if (interlocked_cmpxchg_ptr( &once->Ptr, context, (void *)val ) != (void *)val) break;
74  val &= ~3;
75  while (val)
76  {
79  val = next;
80  }
81  return STATUS_SUCCESS;
82 
83  case 3: /* in progress, async */
85  if (interlocked_cmpxchg_ptr( &once->Ptr, context, (void *)val ) != (void *)val) break;
86  return STATUS_SUCCESS;
87 
88  default:
89  return STATUS_UNSUCCESSFUL;
90  }
91  }
92 }
93 
95  void *param, void **context )
96 {
98 
99  if (ret != STATUS_PENDING) return ret;
100 
101  if (!func( once, param, context ))
102  {
104  return STATUS_UNSUCCESSFUL;
105  }
106 
107  return RtlpRunOnceComplete( once, 0, context ? *context : NULL );
108 }
109 
110 /* Taken from Wine kernel32/sync.c */
111 
112 /*
113  * @implemented
114  */
116 {
118 }
GLenum func
Definition: glext.h:6028
NTSYSAPI NTSTATUS WINAPI NtWaitForKeyedEvent(HANDLE, const void *, BOOLEAN, const LARGE_INTEGER *)
Definition: http.c:6587
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define RTL_RUN_ONCE_CHECK_ONLY
void * interlocked_cmpxchg_ptr(void **dest, void *xchg, void *compare)
HANDLE keyed_event
static DWORD WINAPI RtlpRunOnceComplete(RTL_RUN_ONCE *once, ULONG flags, void *context)
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define RTL_RUN_ONCE_INIT_FAILED
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static DWORD WINAPI RtlpRunOnceExecuteOnce(RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN func, void *param, void **context)
smooth NULL
Definition: ftsmooth.c:416
switch(r->id)
Definition: btrfs.c:2904
GLuint GLfloat * val
Definition: glext.h:7180
BOOL NTAPI InitOnceExecuteOnce(INIT_ONCE *once, PINIT_ONCE_FN func, void *param, void **context)
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define STATUS_PENDING
Definition: ntstatus.h:82
GLfloat param
Definition: glext.h:5796
#define WINAPI
Definition: msvc.h:8
RTL_RUN_ONCE_INIT_FN * PRTL_RUN_ONCE_INIT_FN
Definition: winnt_old.h:2537
unsigned long DWORD
Definition: ntddk_ex.h:95
GLbitfield flags
Definition: glext.h:7161
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
int ret
static unsigned __int64 next
Definition: rand_nt.c:6
NTSYSAPI NTSTATUS WINAPI NtReleaseKeyedEvent(HANDLE, const void *, BOOLEAN, const LARGE_INTEGER *)
BOOL(WINAPI * PINIT_ONCE_FN)(_Inout_ PINIT_ONCE InitOnce, _Inout_opt_ PVOID Parameter, _Outptr_opt_result_maybenull_ PVOID *Context)
Definition: winbase.h:3764
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
return STATUS_SUCCESS
Definition: btrfs.c:2938
static DWORD WINAPI RtlRunOnceBeginInitialize(RTL_RUN_ONCE *once, ULONG flags, void **context)
#define RTL_RUN_ONCE_ASYNC