Coverage Report

Created: 2025-07-01 06:46

/src/FreeRDP/winpr/libwinpr/synch/init.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * WinPR: Windows Portable Runtime
3
 * Synchronization Functions
4
 *
5
 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6
 * Copyright 2014 Thincast Technologies GmbH
7
 * Copyright 2014 Norbert Federa <norbert.federa@thincast.com>
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 *     http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21
22
#include <winpr/config.h>
23
24
#include <winpr/synch.h>
25
#include <winpr/interlocked.h>
26
27
#include "../log.h"
28
#define TAG WINPR_TAG("sync")
29
30
#if (!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
31
32
BOOL winpr_InitOnceBeginInitialize(WINPR_ATTR_UNUSED LPINIT_ONCE lpInitOnce,
33
                                   WINPR_ATTR_UNUSED DWORD dwFlags,
34
                                   WINPR_ATTR_UNUSED PBOOL fPending,
35
                                   WINPR_ATTR_UNUSED LPVOID* lpContext)
36
0
{
37
0
  WLog_ERR(TAG, "not implemented");
38
0
  return FALSE;
39
0
}
40
41
BOOL winpr_InitOnceComplete(WINPR_ATTR_UNUSED LPINIT_ONCE lpInitOnce,
42
                            WINPR_ATTR_UNUSED DWORD dwFlags, WINPR_ATTR_UNUSED LPVOID lpContext)
43
0
{
44
0
  WLog_ERR(TAG, "not implemented");
45
0
  return FALSE;
46
0
}
47
48
VOID winpr_InitOnceInitialize(WINPR_ATTR_UNUSED PINIT_ONCE InitOnce)
49
0
{
50
0
  WLog_ERR(TAG, "not implemented");
51
0
}
52
53
BOOL winpr_InitOnceExecuteOnce(PINIT_ONCE InitOnce, PINIT_ONCE_FN InitFn, PVOID Parameter,
54
                               LPVOID* Context)
55
0
{
56
0
  for (;;)
57
0
  {
58
0
    switch ((ULONG_PTR)InitOnce->Ptr & 3)
59
0
    {
60
0
      case 2:
61
        /* already completed successfully */
62
0
        return TRUE;
63
64
0
      case 0:
65
66
        /* first time */
67
0
        if (InterlockedCompareExchangePointer(&InitOnce->Ptr, (PVOID)1, (PVOID)0) !=
68
0
            (PVOID)0)
69
0
        {
70
          /* some other thread was faster */
71
0
          break;
72
0
        }
73
74
        /* it's our job to call the init function */
75
0
        if (InitFn(InitOnce, Parameter, Context))
76
0
        {
77
          /* success */
78
0
          InitOnce->Ptr = (PVOID)2;
79
0
          return TRUE;
80
0
        }
81
82
        /* the init function returned an error,  reset the status */
83
0
        InitOnce->Ptr = (PVOID)0;
84
0
        return FALSE;
85
86
0
      case 1:
87
        /* in progress */
88
0
        break;
89
90
0
      default:
91
0
        WLog_ERR(TAG, "internal error");
92
0
        return FALSE;
93
0
    }
94
95
0
    Sleep(5);
96
0
  }
97
0
}
98
99
#endif