[Android] Enable access to up-to-date tzdata on Android 10+ (#20350)
[mono-project.git] / mcs / class / corlib / System.Threading / Monitor.cs
blob3113ce05ba715bd69a76bb1b8993c705099d010b
1 //
2 // System.Threading.Monitor.cs
3 //
4 // Author:
5 // Dick Porter (dick@ximian.com)
6 //
7 // (C) Ximian, Inc. http://www.ximian.com
8 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Runtime.CompilerServices;
34 #if FEATURE_REMOTING
35 using System.Runtime.Remoting.Contexts;
36 #endif
37 using System.Runtime.ConstrainedExecution;
38 using System.Runtime.InteropServices;
40 namespace System.Threading
42 public static partial class Monitor
44 [MethodImplAttribute(MethodImplOptions.InternalCall)]
45 extern static bool Monitor_test_synchronised(object obj);
47 [MethodImplAttribute(MethodImplOptions.InternalCall)]
48 extern static void Monitor_pulse(object obj);
50 static void ObjPulse(Object obj)
52 if (!Monitor_test_synchronised (obj))
53 throw new SynchronizationLockException("Object is not synchronized");
55 Monitor_pulse (obj);
58 [MethodImplAttribute(MethodImplOptions.InternalCall)]
59 extern static void Monitor_pulse_all(object obj);
61 static void ObjPulseAll(Object obj)
63 if (!Monitor_test_synchronised (obj))
64 throw new SynchronizationLockException("Object is not synchronized");
66 Monitor_pulse_all (obj);
69 [MethodImplAttribute(MethodImplOptions.InternalCall)]
70 extern static bool Monitor_wait(object obj, int ms);
72 static bool ObjWait(bool exitContext, int millisecondsTimeout, Object obj)
74 if (millisecondsTimeout < 0 && millisecondsTimeout != (int) Timeout.Infinite)
75 throw new ArgumentOutOfRangeException ("millisecondsTimeout");
76 if (!Monitor_test_synchronised (obj))
77 throw new SynchronizationLockException ("Object is not synchronized");
79 try {
80 #if FEATURE_REMOTING
81 if (exitContext)
82 SynchronizationAttribute.ExitContext ();
83 #endif
85 return Monitor_wait (obj, millisecondsTimeout);
86 } finally {
87 #if FEATURE_REMOTING
88 if (exitContext)
89 SynchronizationAttribute.EnterContext ();
90 #endif
94 [MethodImplAttribute(MethodImplOptions.InternalCall)]
95 extern static void try_enter_with_atomic_var (object obj, int millisecondsTimeout, ref bool lockTaken);
97 static void ReliableEnterTimeout(Object obj, int timeout, ref bool lockTaken)
99 if (obj == null)
100 throw new ArgumentNullException ("obj");
101 if (timeout < 0 && timeout != (int) Timeout.Infinite)
102 throw new ArgumentOutOfRangeException ("millisecondsTimeout");
104 try_enter_with_atomic_var (obj, timeout, ref lockTaken);
107 static void ReliableEnter(Object obj, ref bool lockTaken)
109 ReliableEnterTimeout (obj, (int) Timeout.Infinite, ref lockTaken);
112 [MethodImplAttribute(MethodImplOptions.InternalCall)]
113 extern static bool Monitor_test_owner (object obj);
115 static bool IsEnteredNative(Object obj)
117 return Monitor_test_owner (obj);
120 #if NETCORE
121 public static long LockContentionCount => throw new PlatformNotSupportedException ();
122 #endif