ReactOS  0.4.14-dev-323-g6fe6a88
InitOnceExecuteOnce.c File Reference
#include "k32_vista.h"
#include <ndk/exfuncs.h>
#include <wine/config.h>
#include <wine/port.h>
Include dependency graph for InitOnceExecuteOnce.c:

Go to the source code of this file.

Functions

static DWORD WINAPI RtlRunOnceBeginInitialize (RTL_RUN_ONCE *once, ULONG flags, void **context)
 
static DWORD WINAPI RtlpRunOnceComplete (RTL_RUN_ONCE *once, ULONG flags, void *context)
 
static DWORD WINAPI RtlpRunOnceExecuteOnce (RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN func, void *param, void **context)
 
BOOL NTAPI InitOnceExecuteOnce (INIT_ONCE *once, PINIT_ONCE_FN func, void *param, void **context)
 

Variables

HANDLE keyed_event = NULL
 

Function Documentation

◆ InitOnceExecuteOnce()

BOOL NTAPI InitOnceExecuteOnce ( INIT_ONCE once,
PINIT_ONCE_FN  func,
void param,
void **  context 
)

Definition at line 115 of file InitOnceExecuteOnce.c.

116 {
118 }
GLenum func
Definition: glext.h:6028
Definition: http.c:6587
static DWORD WINAPI RtlpRunOnceExecuteOnce(RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN func, void *param, void **context)
GLfloat param
Definition: glext.h:5796
RTL_RUN_ONCE_INIT_FN * PRTL_RUN_ONCE_INIT_FN
Definition: winnt_old.h:2537

Referenced by apartment_createwindowifneeded(), DllGetClassObject(), get_notif_hwnd(), and init_winsock().

◆ RtlpRunOnceComplete()

static DWORD WINAPI RtlpRunOnceComplete ( RTL_RUN_ONCE once,
ULONG  flags,
void context 
)
static

Definition at line 55 of file InitOnceExecuteOnce.c.

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 }
Definition: http.c:6587
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
void * interlocked_cmpxchg_ptr(void **dest, void *xchg, void *compare)
HANDLE keyed_event
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define RTL_RUN_ONCE_INIT_FAILED
smooth NULL
Definition: ftsmooth.c:416
switch(r->id)
Definition: btrfs.c:2904
GLuint GLfloat * val
Definition: glext.h:7180
GLbitfield flags
Definition: glext.h:7161
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static unsigned __int64 next
Definition: rand_nt.c:6
NTSYSAPI NTSTATUS WINAPI NtReleaseKeyedEvent(HANDLE, const void *, BOOLEAN, const LARGE_INTEGER *)
#define ULONG_PTR
Definition: config.h:101
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RTL_RUN_ONCE_ASYNC

Referenced by RtlpRunOnceExecuteOnce().

◆ RtlpRunOnceExecuteOnce()

static DWORD WINAPI RtlpRunOnceExecuteOnce ( RTL_RUN_ONCE once,
PRTL_RUN_ONCE_INIT_FN  func,
void param,
void **  context 
)
static

Definition at line 94 of file InitOnceExecuteOnce.c.

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 }
GLenum func
Definition: glext.h:6028
Definition: http.c:6587
static DWORD WINAPI RtlpRunOnceComplete(RTL_RUN_ONCE *once, ULONG flags, void *context)
#define RTL_RUN_ONCE_INIT_FAILED
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
GLfloat param
Definition: glext.h:5796
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
int ret
static DWORD WINAPI RtlRunOnceBeginInitialize(RTL_RUN_ONCE *once, ULONG flags, void **context)

Referenced by InitOnceExecuteOnce().

◆ RtlRunOnceBeginInitialize()

static DWORD WINAPI RtlRunOnceBeginInitialize ( RTL_RUN_ONCE once,
ULONG  flags,
void **  context 
)
static

Definition at line 12 of file InitOnceExecuteOnce.c.

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 }
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
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
switch(r->id)
Definition: btrfs.c:2904
GLuint GLfloat * val
Definition: glext.h:7180
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define STATUS_PENDING
Definition: ntstatus.h:82
GLbitfield flags
Definition: glext.h:7161
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static unsigned __int64 next
Definition: rand_nt.c:6
#define ULONG_PTR
Definition: config.h:101
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RTL_RUN_ONCE_ASYNC

Referenced by RtlpRunOnceExecuteOnce().

Variable Documentation

◆ keyed_event

HANDLE keyed_event = NULL

Definition at line 10 of file InitOnceExecuteOnce.c.

Referenced by RtlpRunOnceComplete(), and RtlRunOnceBeginInitialize().