Coverage Report

Created: 2024-05-20 06:11

/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(LPINIT_ONCE lpInitOnce, DWORD dwFlags, PBOOL fPending,
33
                                   LPVOID* lpContext)
34
0
{
35
0
  WLog_ERR(TAG, "not implemented");
36
0
  return FALSE;
37
0
}
38
39
BOOL winpr_InitOnceComplete(LPINIT_ONCE lpInitOnce, DWORD dwFlags, LPVOID lpContext)
40
0
{
41
0
  WLog_ERR(TAG, "not implemented");
42
0
  return FALSE;
43
0
}
44
45
VOID winpr_InitOnceInitialize(PINIT_ONCE InitOnce)
46
0
{
47
0
  WLog_ERR(TAG, "not implemented");
48
0
}
49
50
BOOL winpr_InitOnceExecuteOnce(PINIT_ONCE InitOnce, PINIT_ONCE_FN InitFn, PVOID Parameter,
51
                               LPVOID* Context)
52
696k
{
53
696k
  for (;;)
54
696k
  {
55
696k
    switch ((ULONG_PTR)InitOnce->Ptr & 3)
56
696k
    {
57
696k
      case 2:
58
        /* already completed successfully */
59
696k
        return TRUE;
60
61
10
      case 0:
62
63
        /* first time */
64
10
        if (InterlockedCompareExchangePointer(&InitOnce->Ptr, (PVOID)1, (PVOID)0) !=
65
10
            (PVOID)0)
66
0
        {
67
          /* some other thread was faster */
68
0
          break;
69
0
        }
70
71
        /* it's our job to call the init function */
72
10
        if (InitFn(InitOnce, Parameter, Context))
73
10
        {
74
          /* success */
75
10
          InitOnce->Ptr = (PVOID)2;
76
10
          return TRUE;
77
10
        }
78
79
        /* the init function returned an error,  reset the status */
80
0
        InitOnce->Ptr = (PVOID)0;
81
0
        return FALSE;
82
83
0
      case 1:
84
        /* in progress */
85
0
        break;
86
87
0
      default:
88
0
        WLog_ERR(TAG, "internal error");
89
0
        return FALSE;
90
696k
    }
91
92
0
    Sleep(5);
93
0
  }
94
696k
}
95
96
#endif