forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVolatile.cs
More file actions
31 lines (29 loc) · 1.08 KB
/
Volatile.cs
File metadata and controls
31 lines (29 loc) · 1.08 KB
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
#if NET40
using System.Threading;
namespace JavaScriptEngineSwitcher.ChakraCore.Polyfills.System.Threading
{
/// <summary>
/// Contains methods for performing volatile memory operations
/// </summary>
internal static class Volatile
{
/// <summary>
/// Reads the object reference from the specified field. On systems that require it, inserts
/// a memory barrier that prevents the processor from reordering memory operations as follows:
/// If a read or write appears after this method in the code, the processor cannot move it
/// before this method.
/// </summary>
/// <typeparam name="T">The type of field to read. This must be a reference type, not a value type.</typeparam>
/// <param name="location">The field to read</param>
/// <returns>The reference to T that was read. This reference is the latest written by any
/// processor in the computer, regardless of the number of processors or the state of processor
/// cache.</returns>
public static T Read<T>(ref T location) where T : class
{
T obj = location;
Thread.MemoryBarrier();
return obj;
}
}
}
#endif