summaryrefslogtreecommitdiff
path: root/mcs/class/corlib/System.Threading
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/corlib/System.Threading')
-rw-r--r--mcs/class/corlib/System.Threading/CancellationTokenSource.cs2
-rw-r--r--mcs/class/corlib/System.Threading/Monitor.cs6
-rw-r--r--mcs/class/corlib/System.Threading/NamedDataSlot.cs1
-rw-r--r--mcs/class/corlib/System.Threading/SemaphoreSlim.cs8
-rw-r--r--mcs/class/corlib/System.Threading/Thread.cs19
-rw-r--r--mcs/class/corlib/System.Threading/ThreadPool.cs15
-rw-r--r--mcs/class/corlib/System.Threading/Timer.cs2
7 files changed, 36 insertions, 17 deletions
diff --git a/mcs/class/corlib/System.Threading/CancellationTokenSource.cs b/mcs/class/corlib/System.Threading/CancellationTokenSource.cs
index b82e49f59b..59637dd0a3 100644
--- a/mcs/class/corlib/System.Threading/CancellationTokenSource.cs
+++ b/mcs/class/corlib/System.Threading/CancellationTokenSource.cs
@@ -133,7 +133,7 @@ namespace System.Threading
try {
Action cb;
- for (int id = int.MinValue + 1; id <= currId; id++) {
+ for (int id = currId; id != int.MinValue; id--) {
if (!callbacks.TryRemove (new CancellationTokenRegistration (id, this), out cb))
continue;
if (cb == null)
diff --git a/mcs/class/corlib/System.Threading/Monitor.cs b/mcs/class/corlib/System.Threading/Monitor.cs
index 4a326041cb..d6a289e76b 100644
--- a/mcs/class/corlib/System.Threading/Monitor.cs
+++ b/mcs/class/corlib/System.Threading/Monitor.cs
@@ -227,10 +227,12 @@ namespace System.Threading
#endif
#if NET_4_5
- [MonoTODO]
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ extern static bool Monitor_test_owner (object obj);
+
public static bool IsEntered (object obj)
{
- throw new NotImplementedException ();
+ return Monitor_test_owner(obj);
}
#endif
}
diff --git a/mcs/class/corlib/System.Threading/NamedDataSlot.cs b/mcs/class/corlib/System.Threading/NamedDataSlot.cs
index 9997be1f5d..4c9d31624a 100644
--- a/mcs/class/corlib/System.Threading/NamedDataSlot.cs
+++ b/mcs/class/corlib/System.Threading/NamedDataSlot.cs
@@ -64,6 +64,7 @@ namespace System.Threading
LocalDataStoreSlot slot;
if (!datastorehash.TryGetValue (name, out slot)) {
slot = new LocalDataStoreSlot (true);
+ datastorehash.Add (name, slot);
}
return slot;
diff --git a/mcs/class/corlib/System.Threading/SemaphoreSlim.cs b/mcs/class/corlib/System.Threading/SemaphoreSlim.cs
index 3a75238f4d..bf5f3da002 100644
--- a/mcs/class/corlib/System.Threading/SemaphoreSlim.cs
+++ b/mcs/class/corlib/System.Threading/SemaphoreSlim.cs
@@ -171,9 +171,11 @@ namespace System.Threading
if (stopCondition ())
return false;
- if (wait.Count > spinCount)
- handle.WaitOne (Math.Min (Math.Max (millisecondsTimeout - (int)sw.ElapsedMilliseconds, 1), deepSleepTime));
- else
+ if (wait.Count > spinCount) {
+ int timeout = millisecondsTimeout < 0 ? deepSleepTime :
+ Math.Min (Math.Max (millisecondsTimeout - (int)sw.ElapsedMilliseconds, 1), deepSleepTime);
+ handle.WaitOne (timeout);
+ } else
wait.SpinOnce ();
}
} while (true);
diff --git a/mcs/class/corlib/System.Threading/Thread.cs b/mcs/class/corlib/System.Threading/Thread.cs
index 813c458f94..5af6800382 100644
--- a/mcs/class/corlib/System.Threading/Thread.cs
+++ b/mcs/class/corlib/System.Threading/Thread.cs
@@ -137,6 +137,8 @@ namespace System.Threading {
IPrincipal principal;
int principal_version;
+ bool current_culture_set;
+ bool current_ui_culture_set;
CultureInfo current_culture;
CultureInfo current_ui_culture;
@@ -156,6 +158,9 @@ namespace System.Threading {
static NamedDataSlot namedDataSlot;
+ static internal CultureInfo default_culture;
+ static internal CultureInfo default_ui_culture;
+
// can be both a ThreadStart and a ParameterizedThreadStart
private MulticastDelegate threadstart;
//private string thread_name=null;
@@ -470,11 +475,13 @@ namespace System.Threading {
public CultureInfo CurrentCulture {
get {
CultureInfo culture = current_culture;
- if (culture != null)
+ if (current_culture_set && culture != null)
return culture;
+ if (default_culture != null)
+ return default_culture;
+
current_culture = culture = CultureInfo.ConstructCurrentCulture ();
- NumberFormatter.SetThreadCurrentCulture (culture);
return culture;
}
@@ -485,16 +492,19 @@ namespace System.Threading {
value.CheckNeutral ();
current_culture = value;
- NumberFormatter.SetThreadCurrentCulture (value);
+ current_culture_set = true;
}
}
public CultureInfo CurrentUICulture {
get {
CultureInfo culture = current_ui_culture;
- if (culture != null)
+ if (current_ui_culture_set && culture != null)
return culture;
+ if (default_ui_culture != null)
+ return default_ui_culture;
+
current_ui_culture = culture = CultureInfo.ConstructCurrentUICulture ();
return culture;
}
@@ -503,6 +513,7 @@ namespace System.Threading {
if (value == null)
throw new ArgumentNullException ("value");
current_ui_culture = value;
+ current_ui_culture_set = true;
}
}
diff --git a/mcs/class/corlib/System.Threading/ThreadPool.cs b/mcs/class/corlib/System.Threading/ThreadPool.cs
index 4d3f1c086c..204386f9f7 100644
--- a/mcs/class/corlib/System.Threading/ThreadPool.cs
+++ b/mcs/class/corlib/System.Threading/ThreadPool.cs
@@ -87,9 +87,6 @@ namespace System.Threading {
if (ar == null)
return false;
} else {
- if (!callBack.HasSingleTarget)
- throw new Exception ("The delegate must have only one target");
-
AsyncResult ares = new AsyncResult (callBack, state, true);
pool_queue (ares);
}
@@ -99,6 +96,12 @@ namespace System.Threading {
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern void pool_queue (AsyncResult ares);
+ // TODO: It should be interface interface only to avoid extra allocation
+ internal static void QueueWorkItem (WaitCallback callBack, object state)
+ {
+ pool_queue (new AsyncResult (callBack, state, false));
+ }
+
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
@@ -168,11 +171,11 @@ namespace System.Threading {
[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
public static bool UnsafeQueueUserWorkItem (WaitCallback callBack, object state)
{
+ if (callBack == null)
+ throw new ArgumentNullException ("callBack");
+
// no stack propagation here (that's why it's unsafe and requires extra security permissions)
if (!callBack.IsTransparentProxy ()) {
- if (!callBack.HasSingleTarget)
- throw new Exception ("The delegate must have only one target");
-
AsyncResult ares = new AsyncResult (callBack, state, false);
pool_queue (ares);
return true;
diff --git a/mcs/class/corlib/System.Threading/Timer.cs b/mcs/class/corlib/System.Threading/Timer.cs
index 6335877605..dd32032436 100644
--- a/mcs/class/corlib/System.Threading/Timer.cs
+++ b/mcs/class/corlib/System.Threading/Timer.cs
@@ -337,7 +337,7 @@ namespace System.Threading
list.RemoveAt (i);
count--;
i--;
- ThreadPool.UnsafeQueueUserWorkItem (TimerCB, timer);
+ ThreadPool.QueueWorkItem (TimerCB, timer);
long period = timer.period_ms;
long due_time = timer.due_time_ms;
bool no_more = (period == -1 || ((period == 0 || period == Timeout.Infinite) && due_time != Timeout.Infinite));