-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
SuppressGCTransitionNative.cpp
54 lines (44 loc) · 1.09 KB
/
SuppressGCTransitionNative.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include <xplatform.h>
#include <cstdint>
#include <atomic>
#include <string>
#include <algorithm>
namespace
{
std::atomic<uint32_t> _n{ 0 };
using IsInCooperativeMode_fn = BOOL(STDMETHODCALLTYPE*)(void);
IsInCooperativeMode_fn s_isInCooperativeMode = nullptr;
}
extern "C"
void DLL_EXPORT STDMETHODVCALLTYPE SetIsInCooperativeModeFunction(IsInCooperativeMode_fn fn)
{
s_isInCooperativeMode = fn;
}
extern "C"
BOOL DLL_EXPORT STDMETHODVCALLTYPE NextUInt(/* out */ uint32_t* n)
{
BOOL ret;
if (n == nullptr)
{
ret = FALSE;
}
else
{
*n = (++_n);
ret = TRUE;
}
if (s_isInCooperativeMode != nullptr)
ret = s_isInCooperativeMode();
return ret;
}
typedef int (STDMETHODVCALLTYPE *CALLBACKPROC)(int n);
extern "C"
BOOL DLL_EXPORT STDMETHODVCALLTYPE InvokeCallback(CALLBACKPROC cb, int* n)
{
if (cb == nullptr || n == nullptr)
return FALSE;
*n = cb((++_n));
return TRUE;
}