Author: atsushi
Date: 2007-09-05 13:17:49 -0400 (Wed, 05 Sep 2007)
New Revision: 85371
Added:
trunk/mcs/class/System/System.Runtime.InteropServices/HandleCollector.cs
Modified:
trunk/mcs/class/System/ChangeLog
trunk/mcs/class/System/System.Runtime.InteropServices/ChangeLog
trunk/mcs/class/System/System.dll.sources
Log:
2007-09-05 Atsushi Enomoto <[EMAIL PROTECTED]>
* HandleCollector.cs : new file.
* System.dll.sources : added HandleCollector.cs.
Modified: trunk/mcs/class/System/ChangeLog
===================================================================
--- trunk/mcs/class/System/ChangeLog 2007-09-05 16:23:28 UTC (rev 85370)
+++ trunk/mcs/class/System/ChangeLog 2007-09-05 17:17:49 UTC (rev 85371)
@@ -1,3 +1,7 @@
+2007-09-05 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * System.dll.sources : added HandleCollector.cs.
+
2007-09-05 Gert Driesen <[EMAIL PROTECTED]>
* System_test.dll.sources: Added EnumConverterTest.cs.
Modified: trunk/mcs/class/System/System.Runtime.InteropServices/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Runtime.InteropServices/ChangeLog
2007-09-05 16:23:28 UTC (rev 85370)
+++ trunk/mcs/class/System/System.Runtime.InteropServices/ChangeLog
2007-09-05 17:17:49 UTC (rev 85371)
@@ -1,3 +1,7 @@
+2007-09-05 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * HandleCollector.cs : new file.
+
2007-03-12 Raja R Harinath <[EMAIL PROTECTED]>
* StandardOleMarshalObject.cs: New .net2.0 class.
Added: trunk/mcs/class/System/System.Runtime.InteropServices/HandleCollector.cs
===================================================================
--- trunk/mcs/class/System/System.Runtime.InteropServices/HandleCollector.cs
2007-09-05 16:23:28 UTC (rev 85370)
+++ trunk/mcs/class/System/System.Runtime.InteropServices/HandleCollector.cs
2007-09-05 17:17:49 UTC (rev 85371)
@@ -0,0 +1,101 @@
+//
+// HandleCollector.cs
+//
+// Author: Atsushi Enomoto <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+
+namespace System.Runtime.InteropServices
+{
+ public sealed class HandleCollector
+ {
+ int count;
+ readonly int init, max;
+ readonly string name;
+ DateTime previous_collection = DateTime.MinValue;
+
+ public HandleCollector (string name, int initialThreshold)
+ : this (name, initialThreshold, int.MaxValue)
+ {
+ }
+
+ public HandleCollector (string name, int initialThreshold, int
maximumThreshold)
+ {
+ if (initialThreshold < 0)
+ throw new ArgumentOutOfRangeException
("initialThreshold", "initialThreshold must not be less than zero");
+ if (maximumThreshold < 0)
+ throw new ArgumentOutOfRangeException
("maximumThreshold", "maximumThreshold must not be less than zero");
+ if (maximumThreshold < initialThreshold)
+ throw new ArgumentException ("maximumThreshold
must not be less than initialThreshold");
+
+ this.name = name;
+ init = initialThreshold;
+ max = maximumThreshold;
+ }
+
+ public int Count {
+ get { return count; }
+ }
+
+ public int InitialThreshold {
+ get { return init; }
+ }
+
+ public int MaximumThreshold {
+ get { return max; }
+ }
+
+ public string Name {
+ get { return name; }
+ }
+
+ public void Add ()
+ {
+/* NET_3_5
+ if (++count >= max)
+ GC.Collect (GC.MaxGeneration,
GCCollectionMode.Forced);
+ else if (count >= init)
+ GC.Collect (GC.MaxGeneration,
GCCollectionMode.Optimized);
+*/
+ if (++count >= max)
+ GC.Collect (GC.MaxGeneration);
+ else if (count >= init && DateTime.Now -
previous_collection > TimeSpan.FromSeconds (5)) { // some arbitrary criteria
+ GC.Collect (GC.MaxGeneration);
+ previous_collection = DateTime.Now;
+ }
+ }
+
+ public void Remove ()
+ {
+ if (count == 0)
+ throw new InvalidOperationException ("Cannot
call Remove method when Count is 0");
+ count--;
+ }
+ }
+}
+
+#endif
Property changes on:
trunk/mcs/class/System/System.Runtime.InteropServices/HandleCollector.cs
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/mcs/class/System/System.dll.sources
===================================================================
--- trunk/mcs/class/System/System.dll.sources 2007-09-05 16:23:28 UTC (rev
85370)
+++ trunk/mcs/class/System/System.dll.sources 2007-09-05 17:17:49 UTC (rev
85371)
@@ -965,4 +965,5 @@
System.Net/UploadStringCompletedEventHandler.cs
System.Net/DownloadStringCompletedEventHandler.cs
System.Runtime.InteropServices/DefaultParameterValueAttribute.cs
+System.Runtime.InteropServices/HandleCollector.cs
System.Runtime.InteropServices/StandardOleMarshalObject.cs
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches