-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInitializer.cs
More file actions
31 lines (25 loc) · 763 Bytes
/
Initializer.cs
File metadata and controls
31 lines (25 loc) · 763 Bytes
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
using System.Runtime.CompilerServices;
using System.Threading;
namespace PythonNETExtensions.Core
{
public struct Initializer
{
public const int INITIALIZED = -1, UNINITIALIZED = 0;
private int State;
public Initializer(int initialState = INITIALIZED)
{
State = initialState;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryInitialize()
{
var success = Interlocked.CompareExchange(ref State, INITIALIZED, UNINITIALIZED);
return success == UNINITIALIZED;
}
public bool IsInitialized
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => State == INITIALIZED;
}
}
}