forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneWayFlag.cs
More file actions
37 lines (30 loc) · 716 Bytes
/
OneWayFlag.cs
File metadata and controls
37 lines (30 loc) · 716 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
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.Threading;
namespace Microsoft.ClearScript.Util
{
internal sealed class OneWayFlag
{
private bool isSet;
public bool IsSet
{
get { return isSet; }
}
public bool Set()
{
return MiscHelpers.Exchange(ref isSet, true) == false;
}
}
internal sealed class InterlockedOneWayFlag
{
private int isSet;
public bool IsSet
{
get { return isSet != 0; }
}
public bool Set()
{
return Interlocked.Exchange(ref isSet, 1) == 0;
}
}
}