# HG changeset patch # User cin # Date 1507184483 -10800 # Node ID 8dd666e6b6bf2232c63e1ba3c282bd92c13d919b # Parent d6fe09f5592cac1081fc4a0235d72198e9a56238 Added implab nuget spec diff -r d6fe09f5592c -r 8dd666e6b6bf Implab.Playground/Program.cs --- a/Implab.Playground/Program.cs Wed Oct 04 15:44:47 2017 +0300 +++ b/Implab.Playground/Program.cs Thu Oct 05 09:21:23 2017 +0300 @@ -49,7 +49,6 @@ return actual != 0; } - /* static void EnqueueRange(AsyncQueue q, T[] data, int offset, int len) { for (var i = offset; i < offset + len; i++) q.Enqueue(data[i]); @@ -66,15 +65,15 @@ } return actual != 0; } - */ + - static void EnqueueRange(AsyncQueue q, T[] data, int offset, int len) { + /*static void EnqueueRange(AsyncQueue q, T[] data, int offset, int len) { q.EnqueueRange(data, offset, len); } static bool TryDequeueRange(AsyncQueue q, T[] buffer, int offset, int len, out int actual) { return q.TryDequeueRange(buffer, offset, len, out actual); - } + }*/ static void Main(string[] args) { diff -r d6fe09f5592c -r 8dd666e6b6bf Implab/Implab.csproj --- a/Implab/Implab.csproj Wed Oct 04 15:44:47 2017 +0300 +++ b/Implab/Implab.csproj Thu Oct 05 09:21:23 2017 +0300 @@ -67,6 +67,12 @@ 4 false + + true + + + implab.snk + @@ -207,7 +213,12 @@ - + + + Designer + + + @@ -279,5 +290,7 @@ - + + + \ No newline at end of file diff -r d6fe09f5592c -r 8dd666e6b6bf Implab/Implab.nuspec --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab/Implab.nuspec Thu Oct 05 09:21:23 2017 +0300 @@ -0,0 +1,17 @@ + + + + Implab + $version$ + $title$ + Implab team + Implab team + https://implab.org/ + + false + Common components for asynchronous applications, tracing, logging, json and xml traits. + Added strong name. + Copyright 2017 + async xml json + + \ No newline at end of file diff -r d6fe09f5592c -r 8dd666e6b6bf Implab/Parallels/AsyncQueue.cs --- a/Implab/Parallels/AsyncQueue.cs Wed Oct 04 15:44:47 2017 +0300 +++ b/Implab/Parallels/AsyncQueue.cs Thu Oct 05 09:21:23 2017 +0300 @@ -3,6 +3,7 @@ using System; using System.Collections; using System.Diagnostics; +using System.Runtime.CompilerServices; namespace Implab.Parallels { public class AsyncQueue : IEnumerable { @@ -51,6 +52,16 @@ get { return m_size; } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + void AwaitWrites(int mark) { + if (m_hi != mark) { + SpinWait spin = new SpinWait(); + do { + spin.SpinOnce(); + } while (m_hi != mark); + } + } + public bool TryEnqueue(T value) { int alloc; do { @@ -61,12 +72,7 @@ m_data[alloc] = value; - SpinWait spin = new SpinWait(); - // m_hi is volatile - while (alloc != m_hi) { - // spin wait for commit - spin.SpinOnce(); - } + AwaitWrites(alloc); m_hi = alloc + 1; return true; @@ -77,10 +83,7 @@ /// public void Seal() { var actual = Math.Min(Interlocked.Exchange(ref m_alloc, m_size), m_size); - SpinWait spin = new SpinWait(); - while (m_hi != actual) { - spin.SpinOnce(); - } + AwaitWrites(actual); } public bool TryDequeue(out T value, out bool recycle) { @@ -114,11 +117,7 @@ Array.Copy(batch, offset, m_data, alloc, enqueued); - SpinWait spin = new SpinWait(); - while (alloc != m_hi) { - spin.SpinOnce(); - } - + AwaitWrites(alloc); m_hi = alloc + enqueued; return true; } @@ -361,9 +360,7 @@ } public List Drain() { - // start the new queue - var chunk = new Chunk(DEFAULT_CHUNK_SIZE); - + Chunk chunk = null; do { var first = m_first; // first.next is volatile @@ -374,6 +371,10 @@ return new List(); } + // start the new queue + if (chunk == null) + chunk = new Chunk(DEFAULT_CHUNK_SIZE); + // here we will create inconsistency which will force others to spin // and prevent from fetching. chunk.next = null if (first != Interlocked.CompareExchange(ref m_first, chunk, first)) diff -r d6fe09f5592c -r 8dd666e6b6bf Implab/Properties/AssemblyInfo.cs --- a/Implab/Properties/AssemblyInfo.cs Wed Oct 04 15:44:47 2017 +0300 +++ b/Implab/Properties/AssemblyInfo.cs Thu Oct 05 09:21:23 2017 +0300 @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Information about this assembly is defined by the following attributes. @@ -7,11 +6,9 @@ [assembly: AssemblyTitle("Implab")] [assembly: AssemblyDescription("Tools")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] +[assembly: AssemblyCompany("Implab.org")] [assembly: AssemblyCopyright("Implab")] -[assembly: AssemblyTrademark("")] +[assembly: AssemblyTrademark("Implab")] // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. diff -r d6fe09f5592c -r 8dd666e6b6bf Implab/implab.snk Binary file Implab/implab.snk has changed diff -r d6fe09f5592c -r 8dd666e6b6bf Implab/license.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab/license.txt Thu Oct 05 09:21:23 2017 +0300 @@ -0,0 +1,22 @@ +Copyright 2012 Sergey Smirnov + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file