edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializer.Generated.cs;C440068 File: Initializer.Generated.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializer.Generated.cs;C440068 (server) 5/15/2008 5:46 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializer.Generated.cs;ThreadLib @@ -47,7 +47,7 @@ Ruby.Builtins.RubyModule def33 = DefineModule("System::Collections::Generic::IDictionary", typeof(System.Collections.Generic.IDictionary), new System.Action(LoadSystem__Collections__Generic__IDictionary_Instance), null, new Ruby.Builtins.RubyModule[] {def28, }); DefineModule("System::Collections::IEnumerable", typeof(System.Collections.IEnumerable), new System.Action(LoadSystem__Collections__IEnumerable_Instance), null, new Ruby.Builtins.RubyModule[] {def28, }); Ruby.Builtins.RubyModule def40 = DefineModule("System::Collections::IList", typeof(System.Collections.IList), new System.Action(LoadSystem__Collections__IList_Instance), null, new Ruby.Builtins.RubyModule[] {def28, }); - Ruby.Builtins.RubyModule def47 = DefineModule("System::IComparable", typeof(System.IComparable), new System.Action(LoadSystem__IComparable_Instance), null, new Ruby.Builtins.RubyModule[] {def38, }); + DefineModule("System::IComparable", typeof(System.IComparable), new System.Action(LoadSystem__IComparable_Instance), null, new Ruby.Builtins.RubyModule[] {def38, }); DefineGlobalClass("Time", typeof(System.DateTime), typeof(Ruby.Builtins.TimeOps), new System.Action(LoadTime_Instance), new System.Action(LoadTime_Class), classRef1, new Ruby.Builtins.RubyModule[] {def38, }, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.TimeOps.Create), }); @@ -61,7 +61,8 @@ new Microsoft.Scripting.Utils.Function(Ruby.Builtins.ArrayOps.CreateArray), }); DefineGlobalClass("Binding", typeof(Ruby.Builtins.Binding), typeof(Ruby.Builtins.BindingOps), null, null, Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, null); - DefineGlobalClass("ClrString", typeof(System.String), typeof(Ruby.Builtins.StringOps), new System.Action(LoadClrString_Instance), null, Context.ObjectClass, new Ruby.Builtins.RubyModule[] {def47, }, null); + DefineGlobalClass("ClrString", typeof(System.String), typeof(Ruby.Builtins.StringOps), new System.Action(LoadClrString_Instance), null, Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, null); + DefineGlobalClass("ConditionVariable", typeof(Ruby.StandardLibrary.RubyConditionVariable), null, new System.Action(LoadConditionVariable_Instance), null, Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, null); Ruby.Builtins.RubyClass def13 = DefineClass("Digest::Class", typeof(Ruby.StandardLibrary.Digest.Class), null, null, new System.Action(LoadDigest__Class_Class), Context.ObjectClass, new Ruby.Builtins.RubyModule[] {def14, }, null); DefineGlobalClass("Dir", typeof(Ruby.Builtins.RubyDir), null, new System.Action(LoadDir_Instance), new System.Action(LoadDir_Class), Context.ObjectClass, new Ruby.Builtins.RubyModule[] {def28, }, null); Ruby.Builtins.RubyClass def39 = Context.ExceptionClass = DefineGlobalClass("Exception", typeof(System.Exception), typeof(Ruby.Builtins.ExceptionOps), new System.Action(LoadException_Instance), new System.Action(LoadException_Class), Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { @@ -80,6 +81,7 @@ DefineGlobalClass("MatchData", typeof(Ruby.Builtins.MatchData), typeof(Ruby.Builtins.MatchDataOps), new System.Action(LoadMatchData_Instance), null, Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, null); DefineGlobalClass("Method", typeof(Ruby.Builtins.RubyMethod), typeof(Ruby.Builtins.MethodOps), new System.Action(LoadMethod_Instance), null, Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, null); // Skipped primitive: Module + DefineGlobalClass("Mutex", typeof(Ruby.StandardLibrary.RubyMutex), null, new System.Action(LoadMutex_Instance), null, Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, null); Context.NilClass = DefineGlobalClass("NilClass", typeof(Microsoft.Scripting.None), typeof(Ruby.Builtins.NilClassOps), new System.Action(LoadNilClass_Instance), null, Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, null); Ruby.Builtins.RubyClass def34 = DefineGlobalClass("Numeric", typeof(Ruby.Builtins.Numeric), null, new System.Action(LoadNumeric_Instance), null, Context.ObjectClass, new Ruby.Builtins.RubyModule[] {def38, }, null); Ruby.Builtins.RubyClass def18 = DefineClass("OpenSSL::Digest::Digest", typeof(Ruby.StandardLibrary.OpenSSL.DigestFactory.Digest), null, new System.Action(LoadOpenSSL__Digest__Digest_Instance), null, Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, null); @@ -88,6 +90,7 @@ new Microsoft.Scripting.Utils.Function(Ruby.Builtins.ProcOps.CreateProc), new Microsoft.Scripting.Utils.Function(Ruby.Builtins.ProcOps.CreateProc), }); + Ruby.Builtins.RubyClass def43 = DefineGlobalClass("Queue", typeof(Ruby.StandardLibrary.RubyQueue), null, new System.Action(LoadQueue_Instance), null, Context.ObjectClass, Ruby.Builtins.RubyModule.EmptyArray, null); DefineGlobalClass("Range", typeof(Ruby.Builtins.Range), typeof(Ruby.Builtins.RangeOps), new System.Action(LoadRange_Instance), null, Context.ObjectClass, new Ruby.Builtins.RubyModule[] {def28, }, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.RangeOps.CreateRange), }); @@ -130,6 +133,7 @@ Ruby.Builtins.RubyClass def36 = DefineGlobalClass("ScriptError", typeof(Ruby.Builtins.ScriptError), typeof(Ruby.Builtins.ScriptErrorOps), null, null, def39, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.ScriptErrorOps.Factory), }); + DefineGlobalClass("SizedQueue", typeof(Ruby.StandardLibrary.SizedQueue), null, new System.Action(LoadSizedQueue_Instance), null, def43, Ruby.Builtins.RubyModule.EmptyArray, null); Ruby.Builtins.RubyClass def37 = Context.StandardErrorClass = DefineGlobalClass("StandardError", typeof(System.SystemException), typeof(Ruby.Builtins.SystemExceptionOps), null, null, def39, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.SystemExceptionOps.Factory), }); @@ -164,7 +168,7 @@ new Microsoft.Scripting.Utils.Function(Ruby.Builtins.IOErrorOps.Factory), }); #if !SILVERLIGHT - Ruby.Builtins.RubyClass def44 = DefineGlobalClass("IPSocket", typeof(Ruby.StandardLibrary.IPSocket), null, new System.Action(LoadIPSocket_Instance), new System.Action(LoadIPSocket_Class), def42, Ruby.Builtins.RubyModule.EmptyArray, null); + Ruby.Builtins.RubyClass def45 = DefineGlobalClass("IPSocket", typeof(Ruby.StandardLibrary.IPSocket), null, new System.Action(LoadIPSocket_Instance), new System.Action(LoadIPSocket_Class), def42, Ruby.Builtins.RubyModule.EmptyArray, null); #endif DefineGlobalClass("LoadError", typeof(Ruby.Builtins.LoadError), typeof(Ruby.Builtins.LoadErrorOps), null, null, def36, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.LoadErrorOps.Factory), @@ -172,7 +176,7 @@ DefineGlobalClass("LocalJumpError", typeof(Ruby.Builtins.LocalJumpError), typeof(Ruby.Builtins.LocalJumpErrorOps), null, null, def37, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.LocalJumpErrorOps.Factory), }); - Ruby.Builtins.RubyClass def46 = DefineGlobalClass("NameError", typeof(System.MemberAccessException), typeof(Ruby.Builtins.NameErrorOps), null, null, def37, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { + Ruby.Builtins.RubyClass def47 = DefineGlobalClass("NameError", typeof(System.MemberAccessException), typeof(Ruby.Builtins.NameErrorOps), null, null, def37, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.NameErrorOps.Factory), }); DefineGlobalClass("NotImplementedError", typeof(Ruby.Builtins.NotImplementedError), typeof(Ruby.Builtins.NotImplementedErrorOps), null, null, def36, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { @@ -184,7 +188,7 @@ DefineGlobalClass("RegexpError", typeof(Ruby.Builtins.RegexpError), typeof(Ruby.Builtins.RegexpErrorOps), null, null, def37, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.RegexpErrorOps.Factory), }); - Ruby.Builtins.RubyClass def45 = DefineGlobalClass("RuntimeError", typeof(Ruby.Builtins.RuntimeError), null, null, null, def37, Ruby.Builtins.RubyModule.EmptyArray, null); + Ruby.Builtins.RubyClass def46 = DefineGlobalClass("RuntimeError", typeof(Ruby.Builtins.RuntimeError), null, null, null, def37, Ruby.Builtins.RubyModule.EmptyArray, null); DefineGlobalClass("SecurityError", typeof(System.Security.SecurityException), typeof(Ruby.Builtins.SecurityErrorOps), null, null, def37, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.SecurityErrorOps.Factory), }); @@ -218,24 +222,24 @@ Ruby.Builtins.RubyClass def9 = DefineClass("Errno::ENOENT", typeof(Ruby.Builtins.Errno.NoEntryError), null, null, null, def31, Ruby.Builtins.RubyModule.EmptyArray, null); Ruby.Builtins.RubyClass def10 = DefineClass("Errno::ENOTDIR", typeof(Ruby.Builtins.Errno.NotDirectoryError), null, null, null, def31, Ruby.Builtins.RubyModule.EmptyArray, null); DefineGlobalClass("FloatDomainError", typeof(Ruby.Builtins.FloatDomainError), null, null, null, def32, Ruby.Builtins.RubyModule.EmptyArray, null); - DefineGlobalClass("NoMethodError", typeof(System.MissingMethodException), typeof(Ruby.Builtins.NoMethodErrorOps), new System.Action(LoadNoMethodError_Instance), null, def46, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { + DefineGlobalClass("NoMethodError", typeof(System.MissingMethodException), typeof(Ruby.Builtins.NoMethodErrorOps), new System.Action(LoadNoMethodError_Instance), null, def47, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.Builtins.NoMethodErrorOps.Factory), }); #if !SILVERLIGHT - Ruby.Builtins.RubyClass def43 = DefineGlobalClass("TCPSocket", typeof(Ruby.StandardLibrary.TCPSocket), null, null, new System.Action(LoadTCPSocket_Class), def44, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { + Ruby.Builtins.RubyClass def44 = DefineGlobalClass("TCPSocket", typeof(Ruby.StandardLibrary.TCPSocket), null, null, new System.Action(LoadTCPSocket_Class), def45, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.TCPSocket.CreateTCPSocket), }); #endif #if !SILVERLIGHT - DefineGlobalClass("UDPSocket", typeof(Ruby.StandardLibrary.UDPSocket), null, new System.Action(LoadUDPSocket_Instance), null, def44, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { + DefineGlobalClass("UDPSocket", typeof(Ruby.StandardLibrary.UDPSocket), null, new System.Action(LoadUDPSocket_Instance), null, def45, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.UDPSocket.CreateUDPSocket), new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.UDPSocket.CreateUDPSocket), }); #endif - Ruby.Builtins.RubyClass def21 = DefineClass("Zlib::DataError", typeof(Ruby.StandardLibrary.Zlib.DataError), null, null, null, def45, Ruby.Builtins.RubyModule.EmptyArray, null); - Ruby.Builtins.RubyClass def23 = DefineClass("Zlib::GzipFile::Error", typeof(Ruby.StandardLibrary.Zlib.GZipFile.Error), null, null, null, def45, Ruby.Builtins.RubyModule.EmptyArray, null); + Ruby.Builtins.RubyClass def21 = DefineClass("Zlib::DataError", typeof(Ruby.StandardLibrary.Zlib.DataError), null, null, null, def46, Ruby.Builtins.RubyModule.EmptyArray, null); + Ruby.Builtins.RubyClass def23 = DefineClass("Zlib::GzipFile::Error", typeof(Ruby.StandardLibrary.Zlib.GZipFile.Error), null, null, null, def46, Ruby.Builtins.RubyModule.EmptyArray, null); #if !SILVERLIGHT - DefineGlobalClass("TCPServer", typeof(Ruby.StandardLibrary.TCPServer), null, new System.Action(LoadTCPServer_Instance), null, def43, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { + DefineGlobalClass("TCPServer", typeof(Ruby.StandardLibrary.TCPServer), null, new System.Action(LoadTCPServer_Instance), null, def44, Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] { new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.TCPServer.CreateTCPServer), }); #endif @@ -725,6 +729,22 @@ } + private void LoadConditionVariable_Instance(Ruby.Builtins.RubyModule/*!*/ module) { + + module.DefineMethod("broadcast", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyConditionVariable.Broadcast), + }); + + module.DefineMethod("signal", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyConditionVariable.Signal), + }); + + module.DefineMethod("wait", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyConditionVariable.Wait), + }); + + } + private void LoadDigest_Class(Ruby.Builtins.RubyModule/*!*/ module) { module.DefineMethod("const_missing", 0x11, new System.Delegate[] { @@ -2817,6 +2837,34 @@ } + private void LoadMutex_Instance(Ruby.Builtins.RubyModule/*!*/ module) { + + module.DefineMethod("exclusive_unlock", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyMutex.ExclusiveUnlock), + }); + + module.DefineMethod("lock", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyMutex.Lock), + }); + + module.DefineMethod("locked?", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyMutex.IsLocked), + }); + + module.DefineMethod("synchronize", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyMutex.Synchronize), + }); + + module.DefineMethod("try_lock", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyMutex.TryLock), + }); + + module.DefineMethod("unlock", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyMutex.Unlock), + }); + + } + private void LoadNilClass_Instance(Ruby.Builtins.RubyModule/*!*/ module) { module.DefineMethod("&", 0x9, new System.Delegate[] { @@ -3008,6 +3056,54 @@ } + private void LoadQueue_Instance(Ruby.Builtins.RubyModule/*!*/ module) { + + module.DefineMethod("<<", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.Enqueue), + }); + + module.DefineMethod("clear", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.Clear), + }); + + module.DefineMethod("deq", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.Dequeue), + }); + + module.DefineMethod("empty?", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.IsEmpty), + }); + + module.DefineMethod("enq", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.Enqueue), + }); + + module.DefineMethod("length", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.GetCount), + }); + + module.DefineMethod("num_waiting", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.GetNumberOfWaitingThreads), + }); + + module.DefineMethod("pop", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.Dequeue), + }); + + module.DefineMethod("push", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.Enqueue), + }); + + module.DefineMethod("shift", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.Dequeue), + }); + + module.DefineMethod("size", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.RubyQueue.GetCount), + }); + + } + private void LoadRange_Instance(Ruby.Builtins.RubyModule/*!*/ module) { module.DefineMethod("==", 0x9, new System.Delegate[] { @@ -3158,6 +3254,51 @@ } + private void LoadSizedQueue_Instance(Ruby.Builtins.RubyModule/*!*/ module) { + + module.DefineMethod("<<", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.SizedQueue.Enqueue), + }); + + module.DefineMethod("deq", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.SizedQueue.Dequeue), + }); + + module.DefineMethod("enq", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.SizedQueue.Enqueue), + }); + + module.DefineMethod("initialize", 0xa, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.SizedQueue.Reinitialize), + }); + + module.DefineMethod("max", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.SizedQueue.GetLimit), + }); + + module.DefineMethod("max=", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Action(Ruby.StandardLibrary.SizedQueue.SetLimit), + new Microsoft.Scripting.Utils.Action(Ruby.StandardLibrary.SizedQueue.SetLimit), + }); + + module.DefineMethod("num_waiting", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.SizedQueue.GetNumberOfWaitingThreads), + }); + + module.DefineMethod("pop", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.SizedQueue.Dequeue), + }); + + module.DefineMethod("push", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.SizedQueue.Enqueue), + }); + + module.DefineMethod("shift", 0x9, new System.Delegate[] { + new Microsoft.Scripting.Utils.Function(Ruby.StandardLibrary.SizedQueue.Dequeue), + }); + + } + #if !SILVERLIGHT private void LoadSocket_Instance(Ruby.Builtins.RubyModule/*!*/ module) { module.SetConstant("AF_APPLETALK", Ruby.StandardLibrary.RubySocket.AF_APPLETALK); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj;C440068 File: IronRuby.Libraries.csproj =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj;C440068 (server) 5/15/2008 3:42 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/IronRuby.Libraries.csproj;ThreadLib @@ -137,6 +137,10 @@ + + + + =================================================================== add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Thread/RubyConditionVariable.cs File: RubyConditionVariable.cs =================================================================== --- [no source file] +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Thread/RubyConditionVariable.cs;ThreadLib @@ -1,0 +1,65 @@ +?/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Microsoft Public License. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Microsoft Public License, please send an email to + * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Microsoft Public License. + * + * You must not remove this notice, or any other, from this software. + * + * + * ***************************************************************************/ + +using System; +using System.Threading; +using System.Collections.Generic; +using System.Text; + +using Microsoft.Scripting.Actions; + +using Ruby; +using Ruby.Runtime; +using Ruby.Runtime.Calls; +using Microsoft.Scripting.Runtime; + +namespace Ruby.StandardLibrary { + [RubyClass("ConditionVariable")] + public class RubyConditionVariable { + private RubyMutex _mutex; + + public RubyConditionVariable() { + } + + [RubyMethod("signal")] + public static RubyConditionVariable/*!*/ Signal(RubyConditionVariable/*!*/ self) { + RubyMutex m = self._mutex; + if (m != null) { + Monitor.Pulse(m); + } + return self; + } + + [RubyMethod("broadcast")] + public static RubyConditionVariable/*!*/ Broadcast(RubyConditionVariable/*!*/ self) { + RubyMutex m = self._mutex; + if (m != null) { + Monitor.PulseAll(m); + } + return self; + } + + [RubyMethod("wait")] + public static RubyConditionVariable/*!*/ Wait(RubyConditionVariable/*!*/ self, [NotNull]RubyMutex/*!*/ mutex) { + self._mutex = mutex; + Monitor.Wait(mutex.Mutex); + return self; + } + + // TODO: + // "marshal_load" + // "marshal_dump" + } +} =================================================================== add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Thread/RubyMutex.cs File: RubyMutex.cs =================================================================== --- [no source file] +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Thread/RubyMutex.cs;ThreadLib @@ -1,0 +1,96 @@ +?/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Microsoft Public License. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Microsoft Public License, please send an email to + * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Microsoft Public License. + * + * You must not remove this notice, or any other, from this software. + * + * + * ***************************************************************************/ + +using System; +using System.Threading; +using System.Collections.Generic; +using System.Text; + +using Microsoft.Scripting.Actions; + +using Ruby; +using Ruby.Runtime; +using Ruby.Runtime.Calls; +using Microsoft.Scripting.Runtime; + +namespace Ruby.StandardLibrary { + // TODO: + // Ruby mutex is not recursive. + // It can be unlocked from non-owning thread. + [RubyClass("Mutex")] + public class RubyMutex { + private readonly object/*!*/ _mutex; + private bool _isLocked; + + internal object Mutex { get { return _mutex; } } + + public RubyMutex() { + _mutex = new object(); + } + + [RubyMethod("locked?")] + public static bool IsLocked(RubyMutex/*!*/ self) { + return self._isLocked; + } + + [RubyMethod("try_lock")] + public static bool TryLock(RubyMutex/*!*/ self) { + return Monitor.TryEnter(self._mutex); + } + + [RubyMethod("lock")] + public static RubyMutex/*!*/ Lock(RubyMutex/*!*/ self) { + Monitor.Enter(self._mutex); + return self; + } + + [RubyMethod("unlock")] + public static RubyMutex/*!*/ Unlock(RubyMutex/*!*/ self) { + Monitor.Exit(self._mutex); + return self; + } + + private static DynamicSite _CriticalSectionYieldSite; + + [RubyMethod("synchronize")] + public static object Synchronize(CodeContext/*!*/ context, RubyMutex/*!*/ self, BlockParam criticalSection) { + if (!_CriticalSectionYieldSite.IsInitialized) { + _CriticalSectionYieldSite.EnsureInitialized(YieldAction.Make(RubyContext.RubyBinder, 1)); + } + + lock (self._mutex) { + self._isLocked = true; + try { + return _CriticalSectionYieldSite.Invoke(context, + criticalSection, // block param + criticalSection.Self // self object captured by the block + ); + } finally { + self._isLocked = false; + } + } + } + + [RubyMethod("exclusive_unlock")] + public static bool ExclusiveUnlock(RubyMutex/*!*/ self, BlockParam criticalSection) { + // TODO: + throw new NotImplementedException(); + } + + // TODO: + // "marshal_load" + // "marshal_dump" + } +} =================================================================== add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Thread/RubyQueue.cs File: RubyQueue.cs =================================================================== --- [no source file] +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Thread/RubyQueue.cs;ThreadLib @@ -1,0 +1,113 @@ +?/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Microsoft Public License. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Microsoft Public License, please send an email to + * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Microsoft Public License. + * + * You must not remove this notice, or any other, from this software. + * + * + * ***************************************************************************/ + +using System; +using System.Threading; +using System.Collections.Generic; +using System.Text; + +using Ruby; +using Ruby.Runtime; +using Ruby.Runtime.Calls; +using Microsoft.Scripting.Runtime; +using System.Runtime.InteropServices; +using Ruby.Builtins; + +namespace Ruby.StandardLibrary { + // Synchronized queue. + [RubyClass("Queue")] + public class RubyQueue { + protected readonly Queue/*!*/ _queue; + + public RubyQueue() { + _queue = new Queue(); + } + + protected RubyQueue(int capacity) { + _queue = new Queue(capacity); + } + + private void Enqueue(object value) { + lock (_queue) { + _queue.Enqueue(value); + Monitor.PulseAll(_queue); + } + } + + protected object Dequeue() { + object value; + lock (_queue) { + while (_queue.Count == 0) { + Monitor.Wait(_queue); + } + + value = _queue.Dequeue(); + Monitor.PulseAll(_queue); + } + return value; + } + + [RubyMethod("enq")] + [RubyMethod("push")] + [RubyMethod("<<")] + public static RubyQueue/*!*/ Enqueue(RubyQueue/*!*/ self, object value) { + self.Enqueue(value); + return self; + } + + [RubyMethod("deq")] + [RubyMethod("pop")] + [RubyMethod("shift")] + public static object Dequeue(RubyQueue/*!*/ self, [Optional]bool bonBlocking) { + if (bonBlocking) { + lock (self._queue) { + if (self._queue.Count == 0) { + throw new ThreadError("queue empty"); + } + return self._queue.Dequeue(); + } + } + return self.Dequeue(); + } + + [RubyMethod("size")] + [RubyMethod("length")] + public static int GetCount(RubyQueue/*!*/ self) { + return self._queue.Count; + } + + [RubyMethod("clear")] + public static RubyQueue/*!*/ Clear(RubyQueue/*!*/ self) { + lock (self._queue) { + self._queue.Clear(); + } + return self; + } + + [RubyMethod("empty?")] + public static bool IsEmpty(RubyQueue/*!*/ self) { + return self._queue.Count == 0; + } + + [RubyMethod("num_waiting")] + public static int GetNumberOfWaitingThreads(RubyQueue/*!*/ self) { + return 0; + } + + // TODO: + // "marshal_load" + // "marshal_dump" + } +} =================================================================== add: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Thread/SizedQueue.cs File: SizedQueue.cs =================================================================== --- [no source file] +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Thread/SizedQueue.cs;ThreadLib @@ -1,0 +1,104 @@ +?/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Microsoft Public License. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Microsoft Public License, please send an email to + * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Microsoft Public License. + * + * You must not remove this notice, or any other, from this software. + * + * + * ***************************************************************************/ + +using System; +using System.Threading; +using System.Collections.Generic; +using System.Text; + +using Ruby; +using Ruby.Runtime; +using Ruby.Runtime.Calls; +using Microsoft.Scripting.Runtime; +using System.Diagnostics; + +namespace Ruby.StandardLibrary { + // Synchronized queue. + [RubyClass] + public class SizedQueue : RubyQueue { + private int _limit; + + public SizedQueue(int limit) + : base(limit) { + _limit = limit; + } + + public SizedQueue(CodeContext/*!*/ context, object limit) + : this(Protocols.CastToFixnum(context, limit)) { + } + + public SizedQueue() { + } + + private void Enqueue(object value) { + lock (_queue) { + while (_queue.Count == _limit) { + Monitor.Wait(_queue); + } + + _queue.Enqueue(value); + Debug.Assert(_queue.Count <= _limit); + + Monitor.PulseAll(_queue); + } + } + + [RubyMethod("initialize", RubyMethodAttributes.PrivateInstance)] + public static SizedQueue/*!*/ Reinitialize(CodeContext/*!*/ context, SizedQueue/*!*/ self, object limit) { + SetLimit(context, self, limit); + return self; + } + + [RubyMethod("max")] + public static int GetLimit(SizedQueue/*!*/ self) { + return self._limit; + } + + [RubyMethod("max=")] + public static void SetLimit(SizedQueue/*!*/ self, int limit) { + self._limit = limit; + } + + [RubyMethod("max=")] + public static void SetLimit(CodeContext/*!*/ context, SizedQueue/*!*/ self, object limit) { + self._limit = Protocols.CastToFixnum(context, limit); + } + + [RubyMethod("enq")] + [RubyMethod("push")] + [RubyMethod("<<")] + public static SizedQueue/*!*/ Enqueue(SizedQueue/*!*/ self, object value) { + self.Enqueue(value); + return self; + } + + [RubyMethod("deq")] + [RubyMethod("pop")] + [RubyMethod("shift")] + public static object Dequeue(SizedQueue/*!*/ self, [NotNull]params object[]/*!*/ values) { + // TODO: + if (values.Length != 0) { + throw new NotImplementedException(); + } + return self.Dequeue(); + } + + [RubyMethod("num_waiting")] + public static bool GetNumberOfWaitingThreads(SizedQueue/*!*/ self) { + // TODO: + throw new NotImplementedException(); + } + } +} ===================================================================