##// END OF EJS Templates
improved tracing...
cin -
r93:dc4942d09e74 v2
parent child
Show More
@@ -0,0 +1,8
1 using System;
2
3 namespace Implab {
4 public interface IComponentContainer {
5 void Add(IDisposable component);
6 }
7 }
8
@@ -0,0 +1,48
1 using System;
2 using Implab.Parallels;
3 using System.Threading;
4
5 namespace Implab {
6 public class MTComponentContainer : IComponentContainer, IDisposable {
7 static readonly MTComponentContainer _appContainer;
8
9 static MTComponentContainer() {
10 _appContainer = new MTComponentContainer();
11 AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
12 }
13
14 public static MTComponentContainer AppContainer {
15 get {
16 return _appContainer;
17 }
18 }
19
20 bool m_disposed;
21 readonly MTQueue<IDisposable> m_components = new MTQueue<IDisposable>();
22
23 public void Add(IDisposable item) {
24 Safe.ArgumentNotNull(item, "item");
25 Thread.MemoryBarrier();
26 if (m_disposed) {
27 item.Dispose();
28 } else {
29 m_components.Enqueue(item);
30 if (m_disposed && m_components.TryDequeue(out item))
31 item.Dispose();
32 }
33 }
34
35 public void Dispose() {
36 m_disposed = true;
37 IDisposable item;
38 while (m_components.TryDequeue(out item))
39 item.Dispose();
40 }
41
42 static void HandleProcessExit (object sender, EventArgs e)
43 {
44 _appContainer.Dispose();
45 }
46 }
47 }
48
@@ -0,0 +1,46
1 <?xml version="1.0" encoding="utf-8"?>
2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <PropertyGroup>
4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6 <ProductVersion>8.0.30703</ProductVersion>
7 <SchemaVersion>2.0</SchemaVersion>
8 <ProjectGuid>{15DD7123-D504-4627-8B4F-D00C7F04D033}</ProjectGuid>
9 <OutputType>Exe</OutputType>
10 <RootNamespace>MonoPlay</RootNamespace>
11 <AssemblyName>MonoPlay</AssemblyName>
12 <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13 </PropertyGroup>
14 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15 <DebugSymbols>true</DebugSymbols>
16 <DebugType>full</DebugType>
17 <Optimize>false</Optimize>
18 <OutputPath>bin\Debug</OutputPath>
19 <DefineConstants>DEBUG;TRACE;</DefineConstants>
20 <ErrorReport>prompt</ErrorReport>
21 <WarningLevel>4</WarningLevel>
22 <ConsolePause>false</ConsolePause>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25 <DebugType>full</DebugType>
26 <Optimize>true</Optimize>
27 <OutputPath>bin\Release</OutputPath>
28 <ErrorReport>prompt</ErrorReport>
29 <WarningLevel>4</WarningLevel>
30 <Externalconsole>true</Externalconsole>
31 </PropertyGroup>
32 <ItemGroup>
33 <Reference Include="System" />
34 </ItemGroup>
35 <ItemGroup>
36 <Compile Include="Program.cs" />
37 <Compile Include="Properties\AssemblyInfo.cs" />
38 </ItemGroup>
39 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
40 <ItemGroup>
41 <ProjectReference Include="..\Implab\Implab.csproj">
42 <Project>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</Project>
43 <Name>Implab</Name>
44 </ProjectReference>
45 </ItemGroup>
46 </Project> No newline at end of file
@@ -0,0 +1,31
1 using System;
2 using Implab.Diagnostics;
3 using Implab.Parallels;
4 using Implab;
5
6 namespace MonoPlay {
7 class MainClass {
8 public static void Main(string[] args) {
9 var listener = new ConsoleTraceListener(true);
10 listener.Subscribe<TraceEvent>();
11
12 MTComponentContainer.AppContainer.Add(listener);
13
14 TraceLog.StartLogicalOperation("program");
15
16 Console.WriteLine("Hello World!");
17
18 TraceLog.StartLogicalOperation("async");
19 AsyncPool.Invoke(() => {
20 TraceLog.TraceInformation("Hello async");
21 TraceLog.StartLogicalOperation();
22 return 0;
23 })
24 .EndLogicalOperation()
25 .Join();
26
27 TraceLog.EndLogicalOperation();
28
29 }
30 }
31 }
@@ -0,0 +1,27
1 using System.Reflection;
2 using System.Runtime.CompilerServices;
3
4 // Information about this assembly is defined by the following attributes.
5 // Change them to the values specific to your project.
6
7 [assembly: AssemblyTitle("MonoPlay")]
8 [assembly: AssemblyDescription("")]
9 [assembly: AssemblyConfiguration("")]
10 [assembly: AssemblyCompany("")]
11 [assembly: AssemblyProduct("")]
12 [assembly: AssemblyCopyright("sergey")]
13 [assembly: AssemblyTrademark("")]
14 [assembly: AssemblyCulture("")]
15
16 // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17 // The form "{Major}.{Minor}.*" will automatically update the build and revision,
18 // and "{Major}.{Minor}.{Build}.*" will update just the revision.
19
20 [assembly: AssemblyVersion("1.0.*")]
21
22 // The following attributes are used to specify the signing key for the assembly,
23 // if desired. See the Mono documentation for more information about signing.
24
25 //[assembly: AssemblyDelaySign(false)]
26 //[assembly: AssemblyKeyFile("")]
27
@@ -1,15 +1,16
1 syntax: glob
1 syntax: glob
2 Implab.Test/bin/
2 Implab.Test/bin/
3 *.user
3 *.user
4 Implab.Test/obj/
4 Implab.Test/obj/
5 *.userprefs
5 *.userprefs
6 Implab/bin/
6 Implab/bin/
7 Implab/obj/
7 Implab/obj/
8 TestResults/
8 TestResults/
9 Implab.Fx/obj/
9 Implab.Fx/obj/
10 Implab.Fx/bin/
10 Implab.Fx/bin/
11 Implab.Fx.Test/bin/
11 Implab.Fx.Test/bin/
12 Implab.Fx.Test/obj/
12 Implab.Fx.Test/obj/
13 _ReSharper.Implab/
13 _ReSharper.Implab/
14 Implab.Diagnostics.Interactive/bin/
14 Implab.Diagnostics.Interactive/bin/
15 Implab.Diagnostics.Interactive/obj/
15 Implab.Diagnostics.Interactive/obj/
16 MonoPlay/bin/
@@ -1,287 +1,289
1 ο»Ώ
1 ο»Ώ
2 Microsoft Visual Studio Solution File, Format Version 11.00
2 Microsoft Visual Studio Solution File, Format Version 11.00
3 # Visual Studio 2010
3 # Visual Studio 2010
4 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab", "Implab\Implab.csproj", "{F550F1F8-8746-4AD0-9614-855F4C4B7F05}"
4 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab", "Implab\Implab.csproj", "{F550F1F8-8746-4AD0-9614-855F4C4B7F05}"
5 EndProject
5 EndProject
6 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CE8D8D18-437A-445C-B662-4C2CE79A76F6}"
6 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CE8D8D18-437A-445C-B662-4C2CE79A76F6}"
7 ProjectSection(SolutionItems) = preProject
7 ProjectSection(SolutionItems) = preProject
8 Implab.vsmdi = Implab.vsmdi
8 Implab.vsmdi = Implab.vsmdi
9 Local.testsettings = Local.testsettings
9 Local.testsettings = Local.testsettings
10 TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
10 TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
11 EndProjectSection
11 EndProjectSection
12 EndProject
12 EndProject
13 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Fx", "Implab.Fx\Implab.Fx.csproj", "{06E706F8-6881-43EB-927E-FFC503AF6ABC}"
13 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Fx", "Implab.Fx\Implab.Fx.csproj", "{06E706F8-6881-43EB-927E-FFC503AF6ABC}"
14 EndProject
14 EndProject
15 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{BCA337C3-BFDC-4825-BBDB-E6D467E4E452}"
15 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{BCA337C3-BFDC-4825-BBDB-E6D467E4E452}"
16 EndProject
16 EndProject
17 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Test.mono", "Implab.Test\Implab.Test.mono.csproj", "{2BD05F84-E067-4B87-9477-FDC2676A21C6}"
17 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Test.mono", "Implab.Test\Implab.Test.mono.csproj", "{2BD05F84-E067-4B87-9477-FDC2676A21C6}"
18 EndProject
18 EndProject
19 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoPlay", "MonoPlay\MonoPlay.csproj", "{15DD7123-D504-4627-8B4F-D00C7F04D033}"
20 EndProject
19 Global
21 Global
20 GlobalSection(SolutionConfigurationPlatforms) = preSolution
22 GlobalSection(SolutionConfigurationPlatforms) = preSolution
21 Debug|Any CPU = Debug|Any CPU
23 Debug|Any CPU = Debug|Any CPU
22 Release|Any CPU = Release|Any CPU
24 Release|Any CPU = Release|Any CPU
23 Debug 4.5|Any CPU = Debug 4.5|Any CPU
25 Debug 4.5|Any CPU = Debug 4.5|Any CPU
24 Release 4.5|Any CPU = Release 4.5|Any CPU
26 Release 4.5|Any CPU = Release 4.5|Any CPU
25 EndGlobalSection
27 EndGlobalSection
26 GlobalSection(ProjectConfigurationPlatforms) = postSolution
28 GlobalSection(ProjectConfigurationPlatforms) = postSolution
27 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
29 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
28 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
30 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
29 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
33 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
32 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
34 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
33 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release|Any CPU.ActiveCfg = Release|Any CPU
34 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release|Any CPU.Build.0 = Release|Any CPU
36 {06E706F8-6881-43EB-927E-FFC503AF6ABC}.Release|Any CPU.Build.0 = Release|Any CPU
35 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
37 {15DD7123-D504-4627-8B4F-D00C7F04D033}.Debug 4.5|Any CPU.ActiveCfg = Debug|Any CPU
38 {15DD7123-D504-4627-8B4F-D00C7F04D033}.Debug 4.5|Any CPU.Build.0 = Debug|Any CPU
39 {15DD7123-D504-4627-8B4F-D00C7F04D033}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40 {15DD7123-D504-4627-8B4F-D00C7F04D033}.Debug|Any CPU.Build.0 = Debug|Any CPU
41 {15DD7123-D504-4627-8B4F-D00C7F04D033}.Release 4.5|Any CPU.ActiveCfg = Release|Any CPU
42 {15DD7123-D504-4627-8B4F-D00C7F04D033}.Release 4.5|Any CPU.Build.0 = Release|Any CPU
43 {15DD7123-D504-4627-8B4F-D00C7F04D033}.Release|Any CPU.ActiveCfg = Release|Any CPU
44 {15DD7123-D504-4627-8B4F-D00C7F04D033}.Release|Any CPU.Build.0 = Release|Any CPU
36 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
45 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
37 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
46 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
38 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
39 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
48 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
43 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
44 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
49 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
45 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
50 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
46 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
47 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
48 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
49 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.Build.0 = Release|Any CPU
52 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.Build.0 = Release|Any CPU
50 {2BD05F84-E067-4B87-9477-FDC2676A21C6}.Release|Any CPU.Build.0 = Release|Any CPU
53 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
54 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
55 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug|Any CPU.Build.0 = Debug|Any CPU
57 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
58 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
59 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release|Any CPU.ActiveCfg = Release|Any CPU
60 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release|Any CPU.Build.0 = Release|Any CPU
51 {2F31E405-E267-4195-A05D-574093C21209}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
61 {2F31E405-E267-4195-A05D-574093C21209}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
52 {2F31E405-E267-4195-A05D-574093C21209}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
62 {2F31E405-E267-4195-A05D-574093C21209}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
53 {2F31E405-E267-4195-A05D-574093C21209}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63 {2F31E405-E267-4195-A05D-574093C21209}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54 {2F31E405-E267-4195-A05D-574093C21209}.Debug|Any CPU.Build.0 = Debug|Any CPU
64 {2F31E405-E267-4195-A05D-574093C21209}.Debug|Any CPU.Build.0 = Debug|Any CPU
55 {2F31E405-E267-4195-A05D-574093C21209}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
65 {2F31E405-E267-4195-A05D-574093C21209}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
56 {2F31E405-E267-4195-A05D-574093C21209}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
66 {2F31E405-E267-4195-A05D-574093C21209}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
57 {2F31E405-E267-4195-A05D-574093C21209}.Release|Any CPU.ActiveCfg = Release|Any CPU
67 {2F31E405-E267-4195-A05D-574093C21209}.Release|Any CPU.ActiveCfg = Release|Any CPU
58 {2F31E405-E267-4195-A05D-574093C21209}.Release|Any CPU.Build.0 = Release|Any CPU
68 {2F31E405-E267-4195-A05D-574093C21209}.Release|Any CPU.Build.0 = Release|Any CPU
59 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
69 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
60 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
70 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
61 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
71 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
72 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
63 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
73 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
64 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
74 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
65 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
75 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
66 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release|Any CPU.Build.0 = Release|Any CPU
76 {63F92C0C-61BF-48C0-A377-8D67C3C661D0}.Release|Any CPU.Build.0 = Release|Any CPU
67 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug 4.5|Any CPU.ActiveCfg = Debug 4.5|Any CPU
68 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug 4.5|Any CPU.Build.0 = Debug 4.5|Any CPU
69 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
70 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Debug|Any CPU.Build.0 = Debug|Any CPU
71 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release 4.5|Any CPU.ActiveCfg = Release 4.5|Any CPU
72 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release 4.5|Any CPU.Build.0 = Release 4.5|Any CPU
73 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release|Any CPU.ActiveCfg = Release|Any CPU
74 {F550F1F8-8746-4AD0-9614-855F4C4B7F05}.Release|Any CPU.Build.0 = Release|Any CPU
75 EndGlobalSection
77 EndGlobalSection
76 GlobalSection(NestedProjects) = preSolution
78 GlobalSection(NestedProjects) = preSolution
77 {2BD05F84-E067-4B87-9477-FDC2676A21C6} = {BCA337C3-BFDC-4825-BBDB-E6D467E4E452}
79 {2BD05F84-E067-4B87-9477-FDC2676A21C6} = {BCA337C3-BFDC-4825-BBDB-E6D467E4E452}
78 EndGlobalSection
80 EndGlobalSection
79 GlobalSection(MonoDevelopProperties) = preSolution
81 GlobalSection(MonoDevelopProperties) = preSolution
80 StartupItem = Implab\Implab.csproj
82 StartupItem = MonoPlay\MonoPlay.csproj
81 Policies = $0
83 Policies = $0
82 $0.CSharpFormattingPolicy = $1
84 $0.CSharpFormattingPolicy = $1
83 $1.IndentSwitchBody = True
85 $1.IndentSwitchBody = True
84 $1.NamespaceBraceStyle = EndOfLine
86 $1.NamespaceBraceStyle = EndOfLine
85 $1.ClassBraceStyle = EndOfLine
87 $1.ClassBraceStyle = EndOfLine
86 $1.InterfaceBraceStyle = EndOfLine
88 $1.InterfaceBraceStyle = EndOfLine
87 $1.StructBraceStyle = EndOfLine
89 $1.StructBraceStyle = EndOfLine
88 $1.EnumBraceStyle = EndOfLine
90 $1.EnumBraceStyle = EndOfLine
89 $1.MethodBraceStyle = EndOfLine
91 $1.MethodBraceStyle = EndOfLine
90 $1.ConstructorBraceStyle = EndOfLine
92 $1.ConstructorBraceStyle = EndOfLine
91 $1.DestructorBraceStyle = EndOfLine
93 $1.DestructorBraceStyle = EndOfLine
92 $1.BeforeMethodDeclarationParentheses = False
94 $1.BeforeMethodDeclarationParentheses = False
93 $1.BeforeMethodCallParentheses = False
95 $1.BeforeMethodCallParentheses = False
94 $1.BeforeConstructorDeclarationParentheses = False
96 $1.BeforeConstructorDeclarationParentheses = False
95 $1.NewLineBeforeConstructorInitializerColon = NewLine
97 $1.NewLineBeforeConstructorInitializerColon = NewLine
96 $1.NewLineAfterConstructorInitializerColon = SameLine
98 $1.NewLineAfterConstructorInitializerColon = SameLine
97 $1.BeforeIndexerDeclarationBracket = False
99 $1.BeforeIndexerDeclarationBracket = False
98 $1.BeforeDelegateDeclarationParentheses = False
100 $1.BeforeDelegateDeclarationParentheses = False
99 $1.NewParentheses = False
101 $1.NewParentheses = False
100 $1.SpacesBeforeBrackets = False
102 $1.SpacesBeforeBrackets = False
101 $1.inheritsSet = Mono
103 $1.inheritsSet = Mono
102 $1.inheritsScope = text/x-csharp
104 $1.inheritsScope = text/x-csharp
103 $1.scope = text/x-csharp
105 $1.scope = text/x-csharp
104 $0.TextStylePolicy = $2
106 $0.TextStylePolicy = $2
105 $2.FileWidth = 120
107 $2.FileWidth = 120
106 $2.EolMarker = Unix
108 $2.EolMarker = Unix
107 $2.inheritsSet = VisualStudio
109 $2.inheritsSet = VisualStudio
108 $2.inheritsScope = text/plain
110 $2.inheritsScope = text/plain
109 $2.scope = text/x-csharp
111 $2.scope = text/x-csharp
110 $0.DotNetNamingPolicy = $3
112 $0.DotNetNamingPolicy = $3
111 $3.DirectoryNamespaceAssociation = PrefixedHierarchical
113 $3.DirectoryNamespaceAssociation = PrefixedHierarchical
112 $3.ResourceNamePolicy = MSBuild
114 $3.ResourceNamePolicy = MSBuild
113 $0.TextStylePolicy = $4
115 $0.TextStylePolicy = $4
114 $4.FileWidth = 120
116 $4.FileWidth = 120
115 $4.TabsToSpaces = False
117 $4.TabsToSpaces = False
116 $4.inheritsSet = VisualStudio
118 $4.inheritsSet = VisualStudio
117 $4.inheritsScope = text/plain
119 $4.inheritsScope = text/plain
118 $4.scope = application/xml
120 $4.scope = application/xml
119 $0.XmlFormattingPolicy = $5
121 $0.XmlFormattingPolicy = $5
120 $5.inheritsSet = Mono
122 $5.inheritsSet = Mono
121 $5.inheritsScope = application/xml
123 $5.inheritsScope = application/xml
122 $5.scope = application/xml
124 $5.scope = application/xml
123 $0.TextStylePolicy = $6
125 $0.TextStylePolicy = $6
124 $6.FileWidth = 120
126 $6.FileWidth = 120
125 $6.TabsToSpaces = False
127 $6.TabsToSpaces = False
126 $6.inheritsSet = VisualStudio
128 $6.inheritsSet = VisualStudio
127 $6.inheritsScope = text/plain
129 $6.inheritsScope = text/plain
128 $6.scope = text/plain
130 $6.scope = text/plain
129 $0.NameConventionPolicy = $7
131 $0.NameConventionPolicy = $7
130 $7.Rules = $8
132 $7.Rules = $8
131 $8.NamingRule = $9
133 $8.NamingRule = $9
132 $9.Name = Namespaces
134 $9.Name = Namespaces
133 $9.AffectedEntity = Namespace
135 $9.AffectedEntity = Namespace
134 $9.VisibilityMask = VisibilityMask
136 $9.VisibilityMask = VisibilityMask
135 $9.NamingStyle = PascalCase
137 $9.NamingStyle = PascalCase
136 $9.IncludeInstanceMembers = True
138 $9.IncludeInstanceMembers = True
137 $9.IncludeStaticEntities = True
139 $9.IncludeStaticEntities = True
138 $8.NamingRule = $10
140 $8.NamingRule = $10
139 $10.Name = Types
141 $10.Name = Types
140 $10.AffectedEntity = Class, Struct, Enum, Delegate
142 $10.AffectedEntity = Class, Struct, Enum, Delegate
141 $10.VisibilityMask = VisibilityMask
143 $10.VisibilityMask = VisibilityMask
142 $10.NamingStyle = PascalCase
144 $10.NamingStyle = PascalCase
143 $10.IncludeInstanceMembers = True
145 $10.IncludeInstanceMembers = True
144 $10.IncludeStaticEntities = True
146 $10.IncludeStaticEntities = True
145 $8.NamingRule = $11
147 $8.NamingRule = $11
146 $11.Name = Interfaces
148 $11.Name = Interfaces
147 $11.RequiredPrefixes = $12
149 $11.RequiredPrefixes = $12
148 $12.String = I
150 $12.String = I
149 $11.AffectedEntity = Interface
151 $11.AffectedEntity = Interface
150 $11.VisibilityMask = VisibilityMask
152 $11.VisibilityMask = VisibilityMask
151 $11.NamingStyle = PascalCase
153 $11.NamingStyle = PascalCase
152 $11.IncludeInstanceMembers = True
154 $11.IncludeInstanceMembers = True
153 $11.IncludeStaticEntities = True
155 $11.IncludeStaticEntities = True
154 $8.NamingRule = $13
156 $8.NamingRule = $13
155 $13.Name = Attributes
157 $13.Name = Attributes
156 $13.RequiredSuffixes = $14
158 $13.RequiredSuffixes = $14
157 $14.String = Attribute
159 $14.String = Attribute
158 $13.AffectedEntity = CustomAttributes
160 $13.AffectedEntity = CustomAttributes
159 $13.VisibilityMask = VisibilityMask
161 $13.VisibilityMask = VisibilityMask
160 $13.NamingStyle = PascalCase
162 $13.NamingStyle = PascalCase
161 $13.IncludeInstanceMembers = True
163 $13.IncludeInstanceMembers = True
162 $13.IncludeStaticEntities = True
164 $13.IncludeStaticEntities = True
163 $8.NamingRule = $15
165 $8.NamingRule = $15
164 $15.Name = Event Arguments
166 $15.Name = Event Arguments
165 $15.RequiredSuffixes = $16
167 $15.RequiredSuffixes = $16
166 $16.String = EventArgs
168 $16.String = EventArgs
167 $15.AffectedEntity = CustomEventArgs
169 $15.AffectedEntity = CustomEventArgs
168 $15.VisibilityMask = VisibilityMask
170 $15.VisibilityMask = VisibilityMask
169 $15.NamingStyle = PascalCase
171 $15.NamingStyle = PascalCase
170 $15.IncludeInstanceMembers = True
172 $15.IncludeInstanceMembers = True
171 $15.IncludeStaticEntities = True
173 $15.IncludeStaticEntities = True
172 $8.NamingRule = $17
174 $8.NamingRule = $17
173 $17.Name = Exceptions
175 $17.Name = Exceptions
174 $17.RequiredSuffixes = $18
176 $17.RequiredSuffixes = $18
175 $18.String = Exception
177 $18.String = Exception
176 $17.AffectedEntity = CustomExceptions
178 $17.AffectedEntity = CustomExceptions
177 $17.VisibilityMask = VisibilityMask
179 $17.VisibilityMask = VisibilityMask
178 $17.NamingStyle = PascalCase
180 $17.NamingStyle = PascalCase
179 $17.IncludeInstanceMembers = True
181 $17.IncludeInstanceMembers = True
180 $17.IncludeStaticEntities = True
182 $17.IncludeStaticEntities = True
181 $8.NamingRule = $19
183 $8.NamingRule = $19
182 $19.Name = Methods
184 $19.Name = Methods
183 $19.AffectedEntity = Methods
185 $19.AffectedEntity = Methods
184 $19.VisibilityMask = VisibilityMask
186 $19.VisibilityMask = VisibilityMask
185 $19.NamingStyle = PascalCase
187 $19.NamingStyle = PascalCase
186 $19.IncludeInstanceMembers = True
188 $19.IncludeInstanceMembers = True
187 $19.IncludeStaticEntities = True
189 $19.IncludeStaticEntities = True
188 $8.NamingRule = $20
190 $8.NamingRule = $20
189 $20.Name = Static Readonly Fields
191 $20.Name = Static Readonly Fields
190 $20.AffectedEntity = ReadonlyField
192 $20.AffectedEntity = ReadonlyField
191 $20.VisibilityMask = Internal, Protected, Public
193 $20.VisibilityMask = Internal, Protected, Public
192 $20.NamingStyle = PascalCase
194 $20.NamingStyle = PascalCase
193 $20.IncludeInstanceMembers = False
195 $20.IncludeInstanceMembers = False
194 $20.IncludeStaticEntities = True
196 $20.IncludeStaticEntities = True
195 $8.NamingRule = $21
197 $8.NamingRule = $21
196 $21.Name = Fields (Non Private)
198 $21.Name = Fields (Non Private)
197 $21.AffectedEntity = Field
199 $21.AffectedEntity = Field
198 $21.VisibilityMask = Internal, Public
200 $21.VisibilityMask = Internal, Public
199 $21.NamingStyle = CamelCase
201 $21.NamingStyle = CamelCase
200 $21.IncludeInstanceMembers = True
202 $21.IncludeInstanceMembers = True
201 $21.IncludeStaticEntities = True
203 $21.IncludeStaticEntities = True
202 $8.NamingRule = $22
204 $8.NamingRule = $22
203 $22.Name = ReadOnly Fields (Non Private)
205 $22.Name = ReadOnly Fields (Non Private)
204 $22.AffectedEntity = ReadonlyField
206 $22.AffectedEntity = ReadonlyField
205 $22.VisibilityMask = Internal, Public
207 $22.VisibilityMask = Internal, Public
206 $22.NamingStyle = CamelCase
208 $22.NamingStyle = CamelCase
207 $22.IncludeInstanceMembers = True
209 $22.IncludeInstanceMembers = True
208 $22.IncludeStaticEntities = False
210 $22.IncludeStaticEntities = False
209 $8.NamingRule = $23
211 $8.NamingRule = $23
210 $23.Name = Fields (Private)
212 $23.Name = Fields (Private)
211 $23.RequiredPrefixes = $24
213 $23.RequiredPrefixes = $24
212 $24.String = m_
214 $24.String = m_
213 $23.AffectedEntity = Field, ReadonlyField
215 $23.AffectedEntity = Field, ReadonlyField
214 $23.VisibilityMask = Private, Protected
216 $23.VisibilityMask = Private, Protected
215 $23.NamingStyle = CamelCase
217 $23.NamingStyle = CamelCase
216 $23.IncludeInstanceMembers = True
218 $23.IncludeInstanceMembers = True
217 $23.IncludeStaticEntities = False
219 $23.IncludeStaticEntities = False
218 $8.NamingRule = $25
220 $8.NamingRule = $25
219 $25.Name = Static Fields (Private)
221 $25.Name = Static Fields (Private)
220 $25.RequiredPrefixes = $26
222 $25.RequiredPrefixes = $26
221 $26.String = _
223 $26.String = _
222 $25.AffectedEntity = Field
224 $25.AffectedEntity = Field
223 $25.VisibilityMask = Private
225 $25.VisibilityMask = Private
224 $25.NamingStyle = CamelCase
226 $25.NamingStyle = CamelCase
225 $25.IncludeInstanceMembers = False
227 $25.IncludeInstanceMembers = False
226 $25.IncludeStaticEntities = True
228 $25.IncludeStaticEntities = True
227 $8.NamingRule = $27
229 $8.NamingRule = $27
228 $27.Name = ReadOnly Fields (Private)
230 $27.Name = ReadOnly Fields (Private)
229 $27.RequiredPrefixes = $28
231 $27.RequiredPrefixes = $28
230 $28.String = m_
232 $28.String = m_
231 $27.AffectedEntity = ReadonlyField
233 $27.AffectedEntity = ReadonlyField
232 $27.VisibilityMask = Private, Protected
234 $27.VisibilityMask = Private, Protected
233 $27.NamingStyle = CamelCase
235 $27.NamingStyle = CamelCase
234 $27.IncludeInstanceMembers = True
236 $27.IncludeInstanceMembers = True
235 $27.IncludeStaticEntities = False
237 $27.IncludeStaticEntities = False
236 $8.NamingRule = $29
238 $8.NamingRule = $29
237 $29.Name = Constant Fields
239 $29.Name = Constant Fields
238 $29.AffectedEntity = ConstantField
240 $29.AffectedEntity = ConstantField
239 $29.VisibilityMask = VisibilityMask
241 $29.VisibilityMask = VisibilityMask
240 $29.NamingStyle = AllUpper
242 $29.NamingStyle = AllUpper
241 $29.IncludeInstanceMembers = True
243 $29.IncludeInstanceMembers = True
242 $29.IncludeStaticEntities = True
244 $29.IncludeStaticEntities = True
243 $8.NamingRule = $30
245 $8.NamingRule = $30
244 $30.Name = Properties
246 $30.Name = Properties
245 $30.AffectedEntity = Property
247 $30.AffectedEntity = Property
246 $30.VisibilityMask = VisibilityMask
248 $30.VisibilityMask = VisibilityMask
247 $30.NamingStyle = PascalCase
249 $30.NamingStyle = PascalCase
248 $30.IncludeInstanceMembers = True
250 $30.IncludeInstanceMembers = True
249 $30.IncludeStaticEntities = True
251 $30.IncludeStaticEntities = True
250 $8.NamingRule = $31
252 $8.NamingRule = $31
251 $31.Name = Events
253 $31.Name = Events
252 $31.AffectedEntity = Event
254 $31.AffectedEntity = Event
253 $31.VisibilityMask = VisibilityMask
255 $31.VisibilityMask = VisibilityMask
254 $31.NamingStyle = PascalCase
256 $31.NamingStyle = PascalCase
255 $31.IncludeInstanceMembers = True
257 $31.IncludeInstanceMembers = True
256 $31.IncludeStaticEntities = True
258 $31.IncludeStaticEntities = True
257 $8.NamingRule = $32
259 $8.NamingRule = $32
258 $32.Name = Enum Members
260 $32.Name = Enum Members
259 $32.AffectedEntity = EnumMember
261 $32.AffectedEntity = EnumMember
260 $32.VisibilityMask = VisibilityMask
262 $32.VisibilityMask = VisibilityMask
261 $32.NamingStyle = PascalCase
263 $32.NamingStyle = PascalCase
262 $32.IncludeInstanceMembers = True
264 $32.IncludeInstanceMembers = True
263 $32.IncludeStaticEntities = True
265 $32.IncludeStaticEntities = True
264 $8.NamingRule = $33
266 $8.NamingRule = $33
265 $33.Name = Parameters
267 $33.Name = Parameters
266 $33.AffectedEntity = Parameter, LocalVariable
268 $33.AffectedEntity = Parameter, LocalVariable
267 $33.VisibilityMask = VisibilityMask
269 $33.VisibilityMask = VisibilityMask
268 $33.NamingStyle = CamelCase
270 $33.NamingStyle = CamelCase
269 $33.IncludeInstanceMembers = True
271 $33.IncludeInstanceMembers = True
270 $33.IncludeStaticEntities = True
272 $33.IncludeStaticEntities = True
271 $8.NamingRule = $34
273 $8.NamingRule = $34
272 $34.Name = Type Parameters
274 $34.Name = Type Parameters
273 $34.RequiredPrefixes = $35
275 $34.RequiredPrefixes = $35
274 $35.String = T
276 $35.String = T
275 $34.AffectedEntity = TypeParameter
277 $34.AffectedEntity = TypeParameter
276 $34.VisibilityMask = VisibilityMask
278 $34.VisibilityMask = VisibilityMask
277 $34.NamingStyle = PascalCase
279 $34.NamingStyle = PascalCase
278 $34.IncludeInstanceMembers = True
280 $34.IncludeInstanceMembers = True
279 $34.IncludeStaticEntities = True
281 $34.IncludeStaticEntities = True
280 EndGlobalSection
282 EndGlobalSection
281 GlobalSection(TestCaseManagementSettings) = postSolution
283 GlobalSection(TestCaseManagementSettings) = postSolution
282 CategoryFile = Implab.vsmdi
284 CategoryFile = Implab.vsmdi
283 EndGlobalSection
285 EndGlobalSection
284 GlobalSection(SolutionProperties) = preSolution
286 GlobalSection(SolutionProperties) = preSolution
285 HideSolutionNode = FALSE
287 HideSolutionNode = FALSE
286 EndGlobalSection
288 EndGlobalSection
287 EndGlobal
289 EndGlobal
@@ -1,49 +1,59
1 namespace Implab.Diagnostics {
1 namespace Implab.Diagnostics {
2 struct OperationContext {
2 struct OperationContext {
3 readonly LogicalOperation m_initial;
3 readonly LogicalOperation m_initial;
4 public readonly static OperationContext EMPTY = new OperationContext(LogicalOperation.EMPTY, false);
4 public readonly static OperationContext EMPTY = new OperationContext(LogicalOperation.EMPTY, false);
5 LogicalOperation m_current;
5 LogicalOperation m_current;
6 readonly bool m_ownership;
6 readonly bool m_ownership;
7
7
8 public OperationContext(LogicalOperation operation, bool ownership) {
8 public OperationContext(LogicalOperation operation, bool ownership) {
9 Safe.ArgumentNotNull(operation, "operation");
9 Safe.ArgumentNotNull(operation, "operation");
10
10
11 m_initial = operation;
11 m_initial = operation;
12 m_current = operation;
12 m_current = operation;
13 m_ownership = ownership;
13 m_ownership = ownership;
14 }
14 }
15
15
16 public LogicalOperation CurrentOperation {
16 public LogicalOperation CurrentOperation {
17 get { return m_current; }
17 get { return m_current; }
18 }
18 }
19
19
20 public void BeginLogicalOperation(string name) {
20 public void BeginLogicalOperation(string name) {
21 m_current = new LogicalOperation(name, m_current);
21 m_current = new LogicalOperation(name, m_current);
22 }
22 }
23
23
24 public LogicalOperation DetachLogicalOperation() {
24 public LogicalOperation DetachLogicalOperation() {
25 var detached = m_current;
25 var detached = m_current;
26 if (m_current != LogicalOperation.EMPTY) {
26 if (m_current != LogicalOperation.EMPTY) {
27 if (m_current != m_initial)
27 if (m_current != m_initial)
28 m_current = m_current.Parent;
28 m_current = m_current.Parent;
29 else if (m_ownership)
29 else if (m_ownership)
30 m_current = LogicalOperation.EMPTY;
30 m_current = LogicalOperation.EMPTY;
31 else
31 else {
32 TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context");
32 detached = LogicalOperation.EMPTY;
33 detached = LogicalOperation.EMPTY;
34 }
35 } else {
36 TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context");
33 }
37 }
34 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
38
35 return detached;
39 return detached;
36 }
40 }
37
41
38 public void EndLogicalOperation() {
42 public void EndLogicalOperation() {
39 if (m_current != m_initial) {
43 if (m_current != m_initial) {
40 m_current = m_current.Parent;
44 m_current = m_current.Parent;
41 } else if (m_current != null && m_ownership) {
45 } else if (m_current != LogicalOperation.EMPTY && m_ownership) {
42 m_current = null;
46 m_current = LogicalOperation.EMPTY;
43 } else {
47 } else {
44 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
48 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
45 }
49 }
46 }
50 }
51
52 public void Leave() {
53
54 if ((m_ownership && m_current != LogicalOperation.EMPTY) || (!m_ownership && m_current != m_initial) )
55 TraceLog.TraceWarning("Trying to leave unfinished logical operation {0}", m_current.Name);
56 }
47 }
57 }
48 }
58 }
49
59
@@ -1,79 +1,80
1 using System;
1 using System;
2 using System.Collections.Generic;
2 using System.Collections.Generic;
3 using System.Threading;
3 using System.Threading;
4
4
5 namespace Implab.Diagnostics {
5 namespace Implab.Diagnostics {
6 /// <summary>
6 /// <summary>
7 /// Trace context is bound to the specific thread, each thread has it's own ThreadContext.
7 /// Trace context is bound to the specific thread, each thread has it's own ThreadContext.
8 /// </summary>
8 /// </summary>
9 /// <remarks>
9 /// <remarks>
10 /// ThreadContext manages relations between logical operations and threads.
10 /// ThreadContext manages relations between logical operations and threads.
11 /// </remarks>
11 /// </remarks>
12 public class TraceContext {
12 public class TraceContext {
13
13
14 [ThreadStatic]
14 [ThreadStatic]
15 static TraceContext _instance;
15 static TraceContext _instance;
16
16
17 OperationContext m_current = OperationContext.EMPTY;
17 OperationContext m_current = OperationContext.EMPTY;
18 readonly Stack<OperationContext> m_stack = new Stack<OperationContext>();
18 readonly Stack<OperationContext> m_stack = new Stack<OperationContext>();
19 readonly int m_threadId;
19 readonly int m_threadId;
20
20
21 public static TraceContext Instance {
21 public static TraceContext Instance {
22 get {
22 get {
23 if (_instance == null)
23 if (_instance == null)
24 _instance = new TraceContext();
24 _instance = new TraceContext();
25 return _instance;
25 return _instance;
26 }
26 }
27 }
27 }
28
28
29 public TraceContext() {
29 public TraceContext() {
30 m_threadId = Thread.CurrentThread.ManagedThreadId;
30 m_threadId = Thread.CurrentThread.ManagedThreadId;
31 }
31 }
32
32
33 public int ThreadId {
33 public int ThreadId {
34 get { return m_threadId; }
34 get { return m_threadId; }
35 }
35 }
36
36
37 public LogicalOperation CurrentOperation {
37 public LogicalOperation CurrentOperation {
38 get {
38 get {
39 return m_current.CurrentOperation;
39 return m_current.CurrentOperation;
40 }
40 }
41 }
41 }
42
42
43 public void EnterLogicalOperation(LogicalOperation operation, bool takeOwnership) {
43 public void EnterLogicalOperation(LogicalOperation operation, bool takeOwnership) {
44 // TODO Emit event
44 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Attach, String.Format("{0} -> [{1}]", operation.Name, m_threadId)));
45 m_stack.Push(m_current);
45 m_stack.Push(m_current);
46 m_current = new OperationContext(operation, takeOwnership);
46 m_current = new OperationContext(operation, takeOwnership);
47 }
47 }
48
48
49 public void StartLogicalOperation(string name) {
49 public void StartLogicalOperation(string name) {
50 m_current.BeginLogicalOperation(name);
50 m_current.BeginLogicalOperation(name);
51 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.OperationStarted, String.Format("+{0}",CurrentOperation.Name)));
51 }
52 }
52
53
53 public void StartLogicalOperation() {
54 public void StartLogicalOperation() {
54 // TODO Emit Event
55 StartLogicalOperation(String.Empty);
55 m_current.BeginLogicalOperation(String.Empty);
56 }
56 }
57
57
58 public void EndLogicalOperation() {
58 public void EndLogicalOperation() {
59 // TODO Emit event
59 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.OperationCompleted, String.Format("-{0} : {1}ms",CurrentOperation.Name, CurrentOperation.Duration)));
60 m_current.EndLogicalOperation();
60 m_current.EndLogicalOperation();
61 }
61 }
62
62
63 public LogicalOperation DetachLogicalOperation() {
63 public LogicalOperation DetachLogicalOperation() {
64 // TODO Emit event
64 var op = m_current.DetachLogicalOperation();
65 return m_current.DetachLogicalOperation();
65 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format("[{0}] -> {1}", m_threadId, op.Name)));
66 return op;
66 }
67 }
67
68
68 public void Leave() {
69 public void Leave() {
69 // TODO Emit event
70 if (m_stack.Count > 0) {
70 if (m_stack.Count > 0)
71 m_current.Leave();
71 m_current = m_stack.Pop();
72 m_current = m_stack.Pop();
72 else {
73 } else {
73 TraceLog.TraceWarning("Attemtp to leave the last operation context");
74 TraceLog.TraceWarning("Attemtp to leave the last operation context");
74 m_current = OperationContext.EMPTY;
75 m_current = OperationContext.EMPTY;
75 }
76 }
76 }
77 }
77 }
78 }
78 }
79 }
79
80
@@ -1,34 +1,28
1 using System;
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
2
6 namespace Implab.Diagnostics {
3 namespace Implab.Diagnostics {
7 public class TraceEvent {
4 public class TraceEvent {
8 public string Message {
5 public string Message {
9 get;
6 get;
10 private set;
7 private set;
11 }
8 }
12
9
13 public TraceEventType EventType {
10 public TraceEventType EventType {
14 get;
11 get;
15 private set;
12 private set;
16 }
13 }
17
14
18 public TraceEvent(TraceEventType type, string message) {
15 public TraceEvent(TraceEventType type, string message) {
19 EventType = type;
16 EventType = type;
20 Message = message;
17 Message = message;
21 }
18 }
22
19
23 public override string ToString() {
20 public override string ToString() {
24 if (EventType == TraceEventType.Information)
21 return EventType == TraceEventType.Information ? Message : String.Format("{0}: {1}", EventType, Message);
25 return Message;
26 else
27 return String.Format("{0}: {1}", EventType, Message);
28 }
22 }
29
23
30 public static TraceEvent Create(TraceEventType type, string format, params object[] args) {
24 public static TraceEvent Create(TraceEventType type, string format, params object[] args) {
31 return new TraceEvent(type, format == null ? String.Empty : String.Format(format, args));
25 return new TraceEvent(type, format == null ? String.Empty : String.Format(format, args));
32 }
26 }
33 }
27 }
34 }
28 }
@@ -1,19 +1,17
1 using System;
1 using System;
2 using System.Collections.Generic;
2 using System.Collections.Generic;
3 using System.Linq;
3 using System.Linq;
4 using System.Text;
4 using System.Text;
5 using System.Threading.Tasks;
5 using System.Threading.Tasks;
6
6
7 namespace Implab.Diagnostics {
7 namespace Implab.Diagnostics {
8 public enum TraceEventType {
8 public enum TraceEventType {
9 Information = 1,
9 Information = 1,
10 Warning,
10 Warning,
11 Error,
11 Error,
12 OperationStarted,
12 OperationStarted,
13 OperationCompleted,
13 OperationCompleted,
14 Fork,
15 Attach,
14 Attach,
16 Detach,
15 Detach,
17 Created
18 }
16 }
19 }
17 }
@@ -1,220 +1,224
1 ο»Ώ<?xml version="1.0" encoding="utf-8"?>
1 ο»Ώ<?xml version="1.0" encoding="utf-8"?>
2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <PropertyGroup>
3 <PropertyGroup>
4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
5 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6 <ProjectGuid>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</ProjectGuid>
6 <ProjectGuid>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</ProjectGuid>
7 <OutputType>Library</OutputType>
7 <OutputType>Library</OutputType>
8 <RootNamespace>Implab</RootNamespace>
8 <RootNamespace>Implab</RootNamespace>
9 <AssemblyName>Implab</AssemblyName>
9 <AssemblyName>Implab</AssemblyName>
10 <ProductVersion>8.0.30703</ProductVersion>
11 <SchemaVersion>2.0</SchemaVersion>
10 </PropertyGroup>
12 </PropertyGroup>
11 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
13 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
12 <DebugSymbols>true</DebugSymbols>
14 <DebugSymbols>true</DebugSymbols>
13 <DebugType>full</DebugType>
15 <DebugType>full</DebugType>
14 <Optimize>false</Optimize>
16 <Optimize>false</Optimize>
15 <OutputPath>bin\Debug</OutputPath>
17 <OutputPath>bin\Debug</OutputPath>
16 <DefineConstants>TRACE;DEBUG;</DefineConstants>
18 <DefineConstants>TRACE;DEBUG;</DefineConstants>
17 <ErrorReport>prompt</ErrorReport>
19 <ErrorReport>prompt</ErrorReport>
18 <WarningLevel>4</WarningLevel>
20 <WarningLevel>4</WarningLevel>
19 <ConsolePause>false</ConsolePause>
21 <ConsolePause>false</ConsolePause>
20 <RunCodeAnalysis>true</RunCodeAnalysis>
22 <RunCodeAnalysis>true</RunCodeAnalysis>
21 </PropertyGroup>
23 </PropertyGroup>
22 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23 <DebugType>full</DebugType>
25 <DebugType>full</DebugType>
24 <Optimize>true</Optimize>
26 <Optimize>true</Optimize>
25 <OutputPath>bin\Release</OutputPath>
27 <OutputPath>bin\Release</OutputPath>
26 <ErrorReport>prompt</ErrorReport>
28 <ErrorReport>prompt</ErrorReport>
27 <WarningLevel>4</WarningLevel>
29 <WarningLevel>4</WarningLevel>
28 <ConsolePause>false</ConsolePause>
30 <ConsolePause>false</ConsolePause>
29 </PropertyGroup>
31 </PropertyGroup>
30 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' ">
32 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' ">
31 <DebugSymbols>true</DebugSymbols>
33 <DebugSymbols>true</DebugSymbols>
32 <DebugType>full</DebugType>
34 <DebugType>full</DebugType>
33 <Optimize>false</Optimize>
35 <Optimize>false</Optimize>
34 <OutputPath>bin\Debug</OutputPath>
36 <OutputPath>bin\Debug</OutputPath>
35 <DefineConstants>TRACE;DEBUG;NET_4_5</DefineConstants>
37 <DefineConstants>TRACE;DEBUG;NET_4_5</DefineConstants>
36 <ErrorReport>prompt</ErrorReport>
38 <ErrorReport>prompt</ErrorReport>
37 <WarningLevel>4</WarningLevel>
39 <WarningLevel>4</WarningLevel>
38 <RunCodeAnalysis>true</RunCodeAnalysis>
40 <RunCodeAnalysis>true</RunCodeAnalysis>
39 <ConsolePause>false</ConsolePause>
41 <ConsolePause>false</ConsolePause>
40 </PropertyGroup>
42 </PropertyGroup>
41 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' ">
43 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' ">
42 <Optimize>true</Optimize>
44 <Optimize>true</Optimize>
43 <OutputPath>bin\Release</OutputPath>
45 <OutputPath>bin\Release</OutputPath>
44 <ErrorReport>prompt</ErrorReport>
46 <ErrorReport>prompt</ErrorReport>
45 <WarningLevel>4</WarningLevel>
47 <WarningLevel>4</WarningLevel>
46 <ConsolePause>false</ConsolePause>
48 <ConsolePause>false</ConsolePause>
47 <DefineConstants>NET_4_5</DefineConstants>
49 <DefineConstants>NET_4_5</DefineConstants>
48 </PropertyGroup>
50 </PropertyGroup>
49 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|AnyCPU' ">
51 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugMono|AnyCPU' ">
50 <DebugSymbols>true</DebugSymbols>
52 <DebugSymbols>true</DebugSymbols>
51 <DebugType>full</DebugType>
53 <DebugType>full</DebugType>
52 <Optimize>false</Optimize>
54 <Optimize>false</Optimize>
53 <OutputPath>bin\Debug</OutputPath>
55 <OutputPath>bin\Debug</OutputPath>
54 <DefineConstants>TRACE;DEBUG;NET_4_5;MONO</DefineConstants>
56 <DefineConstants>TRACE;DEBUG;NET_4_5;MONO</DefineConstants>
55 <ErrorReport>prompt</ErrorReport>
57 <ErrorReport>prompt</ErrorReport>
56 <WarningLevel>4</WarningLevel>
58 <WarningLevel>4</WarningLevel>
57 <RunCodeAnalysis>true</RunCodeAnalysis>
59 <RunCodeAnalysis>true</RunCodeAnalysis>
58 <ConsolePause>false</ConsolePause>
60 <ConsolePause>false</ConsolePause>
59 </PropertyGroup>
61 </PropertyGroup>
60 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|AnyCPU' ">
62 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseMono|AnyCPU' ">
61 <Optimize>true</Optimize>
63 <Optimize>true</Optimize>
62 <OutputPath>bin\Release</OutputPath>
64 <OutputPath>bin\Release</OutputPath>
63 <DefineConstants>NET_4_5;MONO;</DefineConstants>
65 <DefineConstants>NET_4_5;MONO;</DefineConstants>
64 <ErrorReport>prompt</ErrorReport>
66 <ErrorReport>prompt</ErrorReport>
65 <WarningLevel>4</WarningLevel>
67 <WarningLevel>4</WarningLevel>
66 <ConsolePause>false</ConsolePause>
68 <ConsolePause>false</ConsolePause>
67 </PropertyGroup>
69 </PropertyGroup>
68 <ItemGroup>
70 <ItemGroup>
69 <Reference Include="System" />
71 <Reference Include="System" />
70 <Reference Include="System.Xml" />
72 <Reference Include="System.Xml" />
71 </ItemGroup>
73 </ItemGroup>
72 <ItemGroup>
74 <ItemGroup>
73 <Compile Include="Component.cs" />
75 <Compile Include="Component.cs" />
74 <Compile Include="CustomEqualityComparer.cs" />
76 <Compile Include="CustomEqualityComparer.cs" />
75 <Compile Include="Diagnostics\ConsoleTraceListener.cs" />
77 <Compile Include="Diagnostics\ConsoleTraceListener.cs" />
76 <Compile Include="Diagnostics\EventText.cs" />
78 <Compile Include="Diagnostics\EventText.cs" />
77 <Compile Include="Diagnostics\IEventTextFormatter.cs" />
79 <Compile Include="Diagnostics\IEventTextFormatter.cs" />
78 <Compile Include="Diagnostics\LogChannel.cs" />
80 <Compile Include="Diagnostics\LogChannel.cs" />
79 <Compile Include="Diagnostics\LogicalOperation.cs" />
81 <Compile Include="Diagnostics\LogicalOperation.cs" />
80 <Compile Include="Diagnostics\TextFileListener.cs" />
82 <Compile Include="Diagnostics\TextFileListener.cs" />
81 <Compile Include="Diagnostics\TextListenerBase.cs" />
83 <Compile Include="Diagnostics\TextListenerBase.cs" />
82 <Compile Include="Diagnostics\TraceLog.cs" />
84 <Compile Include="Diagnostics\TraceLog.cs" />
83 <Compile Include="Diagnostics\TraceEvent.cs" />
85 <Compile Include="Diagnostics\TraceEvent.cs" />
84 <Compile Include="Diagnostics\TraceEventType.cs" />
86 <Compile Include="Diagnostics\TraceEventType.cs" />
85 <Compile Include="Disposable.cs" />
87 <Compile Include="Disposable.cs" />
86 <Compile Include="ICancellable.cs" />
88 <Compile Include="ICancellable.cs" />
87 <Compile Include="IProgressHandler.cs" />
89 <Compile Include="IProgressHandler.cs" />
88 <Compile Include="IProgressNotifier.cs" />
90 <Compile Include="IProgressNotifier.cs" />
89 <Compile Include="IPromiseT.cs" />
91 <Compile Include="IPromiseT.cs" />
90 <Compile Include="IPromise.cs" />
92 <Compile Include="IPromise.cs" />
91 <Compile Include="IServiceLocator.cs" />
93 <Compile Include="IServiceLocator.cs" />
92 <Compile Include="ITaskController.cs" />
94 <Compile Include="ITaskController.cs" />
93 <Compile Include="JSON\JSONElementContext.cs" />
95 <Compile Include="JSON\JSONElementContext.cs" />
94 <Compile Include="JSON\JSONElementType.cs" />
96 <Compile Include="JSON\JSONElementType.cs" />
95 <Compile Include="JSON\JSONGrammar.cs" />
97 <Compile Include="JSON\JSONGrammar.cs" />
96 <Compile Include="JSON\JSONParser.cs" />
98 <Compile Include="JSON\JSONParser.cs" />
97 <Compile Include="JSON\JSONScanner.cs" />
99 <Compile Include="JSON\JSONScanner.cs" />
98 <Compile Include="JSON\JsonTokenType.cs" />
100 <Compile Include="JSON\JsonTokenType.cs" />
99 <Compile Include="JSON\JSONWriter.cs" />
101 <Compile Include="JSON\JSONWriter.cs" />
100 <Compile Include="JSON\JSONXmlReader.cs" />
102 <Compile Include="JSON\JSONXmlReader.cs" />
101 <Compile Include="JSON\JSONXmlReaderOptions.cs" />
103 <Compile Include="JSON\JSONXmlReaderOptions.cs" />
102 <Compile Include="JSON\StringTranslator.cs" />
104 <Compile Include="JSON\StringTranslator.cs" />
103 <Compile Include="Parallels\DispatchPool.cs" />
105 <Compile Include="Parallels\DispatchPool.cs" />
104 <Compile Include="Parallels\ArrayTraits.cs" />
106 <Compile Include="Parallels\ArrayTraits.cs" />
105 <Compile Include="Parallels\MTQueue.cs" />
107 <Compile Include="Parallels\MTQueue.cs" />
106 <Compile Include="Parallels\WorkerPool.cs" />
108 <Compile Include="Parallels\WorkerPool.cs" />
107 <Compile Include="Parsing\Alphabet.cs" />
109 <Compile Include="Parsing\Alphabet.cs" />
108 <Compile Include="Parsing\AlphabetBase.cs" />
110 <Compile Include="Parsing\AlphabetBase.cs" />
109 <Compile Include="Parsing\AltToken.cs" />
111 <Compile Include="Parsing\AltToken.cs" />
110 <Compile Include="Parsing\BinaryToken.cs" />
112 <Compile Include="Parsing\BinaryToken.cs" />
111 <Compile Include="Parsing\CatToken.cs" />
113 <Compile Include="Parsing\CatToken.cs" />
112 <Compile Include="Parsing\CDFADefinition.cs" />
114 <Compile Include="Parsing\CDFADefinition.cs" />
113 <Compile Include="Parsing\DFABuilder.cs" />
115 <Compile Include="Parsing\DFABuilder.cs" />
114 <Compile Include="Parsing\DFADefinitionBase.cs" />
116 <Compile Include="Parsing\DFADefinitionBase.cs" />
115 <Compile Include="Parsing\DFAStateDescriptor.cs" />
117 <Compile Include="Parsing\DFAStateDescriptor.cs" />
116 <Compile Include="Parsing\DFAutomaton.cs" />
118 <Compile Include="Parsing\DFAutomaton.cs" />
117 <Compile Include="Parsing\EDFADefinition.cs" />
119 <Compile Include="Parsing\EDFADefinition.cs" />
118 <Compile Include="Parsing\EmptyToken.cs" />
120 <Compile Include="Parsing\EmptyToken.cs" />
119 <Compile Include="Parsing\EndToken.cs" />
121 <Compile Include="Parsing\EndToken.cs" />
120 <Compile Include="Parsing\EnumAlphabet.cs" />
122 <Compile Include="Parsing\EnumAlphabet.cs" />
121 <Compile Include="Parsing\Grammar.cs" />
123 <Compile Include="Parsing\Grammar.cs" />
122 <Compile Include="Parsing\IAlphabet.cs" />
124 <Compile Include="Parsing\IAlphabet.cs" />
123 <Compile Include="Parsing\IDFADefinition.cs" />
125 <Compile Include="Parsing\IDFADefinition.cs" />
124 <Compile Include="Parsing\IVisitor.cs" />
126 <Compile Include="Parsing\IVisitor.cs" />
125 <Compile Include="Parsing\ParserException.cs" />
127 <Compile Include="Parsing\ParserException.cs" />
126 <Compile Include="Parsing\Scanner.cs" />
128 <Compile Include="Parsing\Scanner.cs" />
127 <Compile Include="Parsing\StarToken.cs" />
129 <Compile Include="Parsing\StarToken.cs" />
128 <Compile Include="Parsing\SymbolToken.cs" />
130 <Compile Include="Parsing\SymbolToken.cs" />
129 <Compile Include="Parsing\Token.cs" />
131 <Compile Include="Parsing\Token.cs" />
130 <Compile Include="SafePool.cs" />
132 <Compile Include="SafePool.cs" />
131 <Compile Include="ServiceLocator.cs" />
133 <Compile Include="ServiceLocator.cs" />
132 <Compile Include="TaskController.cs" />
134 <Compile Include="TaskController.cs" />
133 <Compile Include="ProgressInitEventArgs.cs" />
135 <Compile Include="ProgressInitEventArgs.cs" />
134 <Compile Include="Properties\AssemblyInfo.cs" />
136 <Compile Include="Properties\AssemblyInfo.cs" />
135 <Compile Include="Promise.cs" />
137 <Compile Include="Promise.cs" />
136 <Compile Include="Parallels\AsyncPool.cs" />
138 <Compile Include="Parallels\AsyncPool.cs" />
137 <Compile Include="Safe.cs" />
139 <Compile Include="Safe.cs" />
138 <Compile Include="ValueEventArgs.cs" />
140 <Compile Include="ValueEventArgs.cs" />
139 <Compile Include="PromiseExtensions.cs" />
141 <Compile Include="PromiseExtensions.cs" />
140 <Compile Include="TransientPromiseException.cs" />
142 <Compile Include="TransientPromiseException.cs" />
141 <Compile Include="SyncContextPromise.cs" />
143 <Compile Include="SyncContextPromise.cs" />
142 <Compile Include="ObjectPool.cs" />
144 <Compile Include="ObjectPool.cs" />
143 <Compile Include="Diagnostics\OperationContext.cs" />
145 <Compile Include="Diagnostics\OperationContext.cs" />
144 <Compile Include="Diagnostics\TraceContext.cs" />
146 <Compile Include="Diagnostics\TraceContext.cs" />
145 <Compile Include="Diagnostics\LogEventArgs.cs" />
147 <Compile Include="Diagnostics\LogEventArgs.cs" />
146 <Compile Include="Diagnostics\LogEventArgsT.cs" />
148 <Compile Include="Diagnostics\LogEventArgsT.cs" />
147 <Compile Include="Diagnostics\Extensions.cs" />
149 <Compile Include="Diagnostics\Extensions.cs" />
150 <Compile Include="IComponentContainer.cs" />
151 <Compile Include="MTComponentContainer.cs" />
148 </ItemGroup>
152 </ItemGroup>
149 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
153 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
150 <ItemGroup />
154 <ItemGroup />
151 <ProjectExtensions>
155 <ProjectExtensions>
152 <MonoDevelop>
156 <MonoDevelop>
153 <Properties>
157 <Properties>
154 <Policies>
158 <Policies>
155 <CSharpFormattingPolicy IndentSwitchBody="True" NamespaceBraceStyle="EndOfLine" ClassBraceStyle="EndOfLine" InterfaceBraceStyle="EndOfLine" StructBraceStyle="EndOfLine" EnumBraceStyle="EndOfLine" MethodBraceStyle="EndOfLine" ConstructorBraceStyle="EndOfLine" DestructorBraceStyle="EndOfLine" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" NewLineBeforeConstructorInitializerColon="NewLine" NewLineAfterConstructorInitializerColon="SameLine" BeforeIndexerDeclarationBracket="False" BeforeDelegateDeclarationParentheses="False" NewParentheses="False" SpacesBeforeBrackets="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
159 <CSharpFormattingPolicy IndentSwitchBody="True" NamespaceBraceStyle="EndOfLine" ClassBraceStyle="EndOfLine" InterfaceBraceStyle="EndOfLine" StructBraceStyle="EndOfLine" EnumBraceStyle="EndOfLine" MethodBraceStyle="EndOfLine" ConstructorBraceStyle="EndOfLine" DestructorBraceStyle="EndOfLine" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" NewLineBeforeConstructorInitializerColon="NewLine" NewLineAfterConstructorInitializerColon="SameLine" BeforeIndexerDeclarationBracket="False" BeforeDelegateDeclarationParentheses="False" NewParentheses="False" SpacesBeforeBrackets="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
156 <TextStylePolicy FileWidth="120" EolMarker="Unix" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />
160 <TextStylePolicy FileWidth="120" EolMarker="Unix" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />
157 <DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="MSBuild" />
161 <DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="MSBuild" />
158 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="application/xml" />
162 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="application/xml" />
159 <XmlFormattingPolicy inheritsSet="Mono" inheritsScope="application/xml" scope="application/xml" />
163 <XmlFormattingPolicy inheritsSet="Mono" inheritsScope="application/xml" scope="application/xml" />
160 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/plain" />
164 <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/plain" />
161 <NameConventionPolicy>
165 <NameConventionPolicy>
162 <Rules>
166 <Rules>
163 <NamingRule Name="Namespaces" AffectedEntity="Namespace" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
167 <NamingRule Name="Namespaces" AffectedEntity="Namespace" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
164 <NamingRule Name="Types" AffectedEntity="Class, Struct, Enum, Delegate" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
168 <NamingRule Name="Types" AffectedEntity="Class, Struct, Enum, Delegate" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
165 <NamingRule Name="Interfaces" AffectedEntity="Interface" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
169 <NamingRule Name="Interfaces" AffectedEntity="Interface" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
166 <RequiredPrefixes>
170 <RequiredPrefixes>
167 <String>I</String>
171 <String>I</String>
168 </RequiredPrefixes>
172 </RequiredPrefixes>
169 </NamingRule>
173 </NamingRule>
170 <NamingRule Name="Attributes" AffectedEntity="CustomAttributes" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
174 <NamingRule Name="Attributes" AffectedEntity="CustomAttributes" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
171 <RequiredSuffixes>
175 <RequiredSuffixes>
172 <String>Attribute</String>
176 <String>Attribute</String>
173 </RequiredSuffixes>
177 </RequiredSuffixes>
174 </NamingRule>
178 </NamingRule>
175 <NamingRule Name="Event Arguments" AffectedEntity="CustomEventArgs" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
179 <NamingRule Name="Event Arguments" AffectedEntity="CustomEventArgs" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
176 <RequiredSuffixes>
180 <RequiredSuffixes>
177 <String>EventArgs</String>
181 <String>EventArgs</String>
178 </RequiredSuffixes>
182 </RequiredSuffixes>
179 </NamingRule>
183 </NamingRule>
180 <NamingRule Name="Exceptions" AffectedEntity="CustomExceptions" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
184 <NamingRule Name="Exceptions" AffectedEntity="CustomExceptions" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
181 <RequiredSuffixes>
185 <RequiredSuffixes>
182 <String>Exception</String>
186 <String>Exception</String>
183 </RequiredSuffixes>
187 </RequiredSuffixes>
184 </NamingRule>
188 </NamingRule>
185 <NamingRule Name="Methods" AffectedEntity="Methods" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
189 <NamingRule Name="Methods" AffectedEntity="Methods" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
186 <NamingRule Name="Static Readonly Fields" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Protected, Public" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True" />
190 <NamingRule Name="Static Readonly Fields" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Protected, Public" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True" />
187 <NamingRule Name="Fields (Non Private)" AffectedEntity="Field" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
191 <NamingRule Name="Fields (Non Private)" AffectedEntity="Field" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
188 <NamingRule Name="ReadOnly Fields (Non Private)" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False" />
192 <NamingRule Name="ReadOnly Fields (Non Private)" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False" />
189 <NamingRule Name="Fields (Private)" AffectedEntity="Field, ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
193 <NamingRule Name="Fields (Private)" AffectedEntity="Field, ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
190 <RequiredPrefixes>
194 <RequiredPrefixes>
191 <String>m_</String>
195 <String>m_</String>
192 </RequiredPrefixes>
196 </RequiredPrefixes>
193 </NamingRule>
197 </NamingRule>
194 <NamingRule Name="Static Fields (Private)" AffectedEntity="Field" VisibilityMask="Private" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True">
198 <NamingRule Name="Static Fields (Private)" AffectedEntity="Field" VisibilityMask="Private" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True">
195 <RequiredPrefixes>
199 <RequiredPrefixes>
196 <String>_</String>
200 <String>_</String>
197 </RequiredPrefixes>
201 </RequiredPrefixes>
198 </NamingRule>
202 </NamingRule>
199 <NamingRule Name="ReadOnly Fields (Private)" AffectedEntity="ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
203 <NamingRule Name="ReadOnly Fields (Private)" AffectedEntity="ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False">
200 <RequiredPrefixes>
204 <RequiredPrefixes>
201 <String>m_</String>
205 <String>m_</String>
202 </RequiredPrefixes>
206 </RequiredPrefixes>
203 </NamingRule>
207 </NamingRule>
204 <NamingRule Name="Constant Fields" AffectedEntity="ConstantField" VisibilityMask="VisibilityMask" NamingStyle="AllUpper" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
208 <NamingRule Name="Constant Fields" AffectedEntity="ConstantField" VisibilityMask="VisibilityMask" NamingStyle="AllUpper" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
205 <NamingRule Name="Properties" AffectedEntity="Property" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
209 <NamingRule Name="Properties" AffectedEntity="Property" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
206 <NamingRule Name="Events" AffectedEntity="Event" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
210 <NamingRule Name="Events" AffectedEntity="Event" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
207 <NamingRule Name="Enum Members" AffectedEntity="EnumMember" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
211 <NamingRule Name="Enum Members" AffectedEntity="EnumMember" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
208 <NamingRule Name="Parameters" AffectedEntity="Parameter, LocalVariable" VisibilityMask="VisibilityMask" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
212 <NamingRule Name="Parameters" AffectedEntity="Parameter, LocalVariable" VisibilityMask="VisibilityMask" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" />
209 <NamingRule Name="Type Parameters" AffectedEntity="TypeParameter" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
213 <NamingRule Name="Type Parameters" AffectedEntity="TypeParameter" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True">
210 <RequiredPrefixes>
214 <RequiredPrefixes>
211 <String>T</String>
215 <String>T</String>
212 </RequiredPrefixes>
216 </RequiredPrefixes>
213 </NamingRule>
217 </NamingRule>
214 </Rules>
218 </Rules>
215 </NameConventionPolicy>
219 </NameConventionPolicy>
216 </Policies>
220 </Policies>
217 </Properties>
221 </Properties>
218 </MonoDevelop>
222 </MonoDevelop>
219 </ProjectExtensions>
223 </ProjectExtensions>
220 </Project> No newline at end of file
224 </Project>
@@ -1,199 +1,199
1 using System;
1 using System;
2 using System.Threading;
2 using System.Threading;
3
3
4 namespace Implab.Parallels {
4 namespace Implab.Parallels {
5 public abstract class DispatchPool<TUnit> : IDisposable {
5 public abstract class DispatchPool<TUnit> : IDisposable {
6 readonly int m_minThreadsLimit;
6 readonly int m_minThreadsLimit;
7 readonly int m_maxThreadsLimit;
7 readonly int m_maxThreadsLimit;
8 readonly int m_releaseTimeout = 1000; // the timeout while the working thread will wait for the new tasks before exit
8 readonly int m_releaseTimeout = 1000; // the timeout while the working thread will wait for the new tasks before exit
9
9
10 int m_threads = 0; // the current size of the pool
10 int m_threads; // the current size of the pool
11 int m_maxRunningThreads = 0; // the meximum reached size of the pool
11 int m_maxRunningThreads; // the meximum reached size of the pool
12 int m_exit = 0; // the pool is going to shutdown, all unused workers are released
12 int m_exit; // the pool is going to shutdown, all unused workers are released
13
13
14 readonly object m_signal = new object(); // used to pulse waiting threads
14 readonly object m_signal = new object(); // used to pulse waiting threads
15
15
16 protected DispatchPool(int min, int max) {
16 protected DispatchPool(int min, int max) {
17 if (min < 0)
17 if (min < 0)
18 throw new ArgumentOutOfRangeException("min");
18 throw new ArgumentOutOfRangeException("min");
19 if (max <= 0)
19 if (max <= 0)
20 throw new ArgumentOutOfRangeException("max");
20 throw new ArgumentOutOfRangeException("max");
21
21
22 if (min > max)
22 if (min > max)
23 min = max;
23 min = max;
24 m_minThreadsLimit = min;
24 m_minThreadsLimit = min;
25 m_maxThreadsLimit = max;
25 m_maxThreadsLimit = max;
26 }
26 }
27
27
28 protected DispatchPool(int threads)
28 protected DispatchPool(int threads)
29 : this(threads, threads) {
29 : this(threads, threads) {
30 }
30 }
31
31
32 protected DispatchPool() {
32 protected DispatchPool() {
33 int maxThreads, maxCP;
33 int maxThreads, maxCP;
34 ThreadPool.GetMaxThreads(out maxThreads, out maxCP);
34 ThreadPool.GetMaxThreads(out maxThreads, out maxCP);
35
35
36 m_minThreadsLimit = 0;
36 m_minThreadsLimit = 0;
37 m_maxThreadsLimit = maxThreads;
37 m_maxThreadsLimit = maxThreads;
38 }
38 }
39
39
40 protected void InitPool() {
40 protected void InitPool() {
41 for (int i = 0; i < m_minThreadsLimit; i++)
41 for (int i = 0; i < m_minThreadsLimit; i++)
42 StartWorker();
42 StartWorker();
43 }
43 }
44
44
45 public int PoolSize {
45 public int PoolSize {
46 get {
46 get {
47 Thread.MemoryBarrier();
47 Thread.MemoryBarrier();
48 return m_threads;
48 return m_threads;
49 }
49 }
50 }
50 }
51
51
52 public int MaxRunningThreads {
52 public int MaxRunningThreads {
53 get {
53 get {
54 Thread.MemoryBarrier();
54 Thread.MemoryBarrier();
55 return m_maxRunningThreads;
55 return m_maxRunningThreads;
56 }
56 }
57 }
57 }
58
58
59 protected bool IsDisposed {
59 protected bool IsDisposed {
60 get {
60 get {
61 Thread.MemoryBarrier();
61 Thread.MemoryBarrier();
62 return m_exit == 1;
62 return m_exit == 1;
63 }
63 }
64 }
64 }
65
65
66 protected abstract bool TryDequeue(out TUnit unit);
66 protected abstract bool TryDequeue(out TUnit unit);
67
67
68 bool Dequeue(out TUnit unit, int timeout) {
68 bool Dequeue(out TUnit unit, int timeout) {
69 int ts = Environment.TickCount;
69 int ts = Environment.TickCount;
70 if (TryDequeue(out unit))
70 if (TryDequeue(out unit))
71 return true;
71 return true;
72 lock (m_signal) {
72 lock (m_signal) {
73 while (!TryDequeue(out unit) && m_exit == 0)
73 while (!TryDequeue(out unit) && m_exit == 0)
74 if(!Monitor.Wait(m_signal, Math.Max(0, ts + timeout - Environment.TickCount))) {
74 if(!Monitor.Wait(m_signal, Math.Max(0, ts + timeout - Environment.TickCount))) {
75 // timeout
75 // timeout
76 return false;
76 return false;
77 }
77 }
78 // queue item or terminate
78 // queue item or terminate
79 Monitor.Pulse(m_signal);
79 Monitor.Pulse(m_signal);
80 if (m_exit == 1)
80 if (m_exit == 1)
81 return false;
81 return false;
82 }
82 }
83 return true;
83 return true;
84 }
84 }
85
85
86 protected void SignalThread() {
86 protected void SignalThread() {
87 lock (m_signal) {
87 lock (m_signal) {
88 Monitor.Pulse(m_signal);
88 Monitor.Pulse(m_signal);
89 }
89 }
90 }
90 }
91
91
92 #region thread slots traits
92 #region thread slots traits
93
93
94 bool AllocateThreadSlot() {
94 bool AllocateThreadSlot() {
95 int current;
95 int current;
96 // use spins to allocate slot for the new thread
96 // use spins to allocate slot for the new thread
97 do {
97 do {
98 current = m_threads;
98 current = m_threads;
99 if (current >= m_maxThreadsLimit || m_exit == 1)
99 if (current >= m_maxThreadsLimit || m_exit == 1)
100 // no more slots left or the pool has been disposed
100 // no more slots left or the pool has been disposed
101 return false;
101 return false;
102 } while (current != Interlocked.CompareExchange(ref m_threads, current + 1, current));
102 } while (current != Interlocked.CompareExchange(ref m_threads, current + 1, current));
103
103
104 UpdateMaxThreads(current + 1);
104 UpdateMaxThreads(current + 1);
105
105
106 return true;
106 return true;
107 }
107 }
108
108
109 bool AllocateThreadSlot(int desired) {
109 bool AllocateThreadSlot(int desired) {
110 if (desired - 1 != Interlocked.CompareExchange(ref m_threads, desired, desired - 1))
110 if (desired - 1 != Interlocked.CompareExchange(ref m_threads, desired, desired - 1))
111 return false;
111 return false;
112
112
113 UpdateMaxThreads(desired);
113 UpdateMaxThreads(desired);
114
114
115 return true;
115 return true;
116 }
116 }
117
117
118 bool ReleaseThreadSlot(out bool last) {
118 bool ReleaseThreadSlot(out bool last) {
119 last = false;
119 last = false;
120 int current;
120 int current;
121 // use spins to release slot for the new thread
121 // use spins to release slot for the new thread
122 Thread.MemoryBarrier();
122 Thread.MemoryBarrier();
123 do {
123 do {
124 current = m_threads;
124 current = m_threads;
125 if (current <= m_minThreadsLimit && m_exit == 0)
125 if (current <= m_minThreadsLimit && m_exit == 0)
126 // the thread is reserved
126 // the thread is reserved
127 return false;
127 return false;
128 } while (current != Interlocked.CompareExchange(ref m_threads, current - 1, current));
128 } while (current != Interlocked.CompareExchange(ref m_threads, current - 1, current));
129
129
130 last = (current == 1);
130 last = (current == 1);
131
131
132 return true;
132 return true;
133 }
133 }
134
134
135 void UpdateMaxThreads(int count) {
135 void UpdateMaxThreads(int count) {
136 int max;
136 int max;
137 do {
137 do {
138 max = m_maxRunningThreads;
138 max = m_maxRunningThreads;
139 if (max >= count)
139 if (max >= count)
140 break;
140 break;
141 } while(max != Interlocked.CompareExchange(ref m_maxRunningThreads, count, max));
141 } while(max != Interlocked.CompareExchange(ref m_maxRunningThreads, count, max));
142 }
142 }
143
143
144 #endregion
144 #endregion
145
145
146 protected bool StartWorker() {
146 protected bool StartWorker() {
147 if (AllocateThreadSlot()) {
147 if (AllocateThreadSlot()) {
148 // slot successfully allocated
148 // slot successfully allocated
149 var worker = new Thread(Worker);
149 var worker = new Thread(Worker);
150 worker.IsBackground = true;
150 worker.IsBackground = true;
151 worker.Start();
151 worker.Start();
152
152
153 return true;
153 return true;
154 }
154 }
155 return false;
155 return false;
156 }
156 }
157
157
158 protected abstract void InvokeUnit(TUnit unit);
158 protected abstract void InvokeUnit(TUnit unit);
159
159
160 protected virtual void Worker() {
160 protected virtual void Worker() {
161 TUnit unit;
161 TUnit unit;
162 bool last;
162 bool last;
163 do {
163 do {
164 while (Dequeue(out unit, m_releaseTimeout)) {
164 while (Dequeue(out unit, m_releaseTimeout)) {
165 InvokeUnit(unit);
165 InvokeUnit(unit);
166 }
166 }
167 if(!ReleaseThreadSlot(out last))
167 if(!ReleaseThreadSlot(out last))
168 continue;
168 continue;
169 // queue may be not empty
169 // queue may be not empty
170 if (last && TryDequeue(out unit)) {
170 if (last && TryDequeue(out unit)) {
171 InvokeUnit(unit);
171 InvokeUnit(unit);
172 if (AllocateThreadSlot(1))
172 if (AllocateThreadSlot(1))
173 continue;
173 continue;
174 // we can safely exit since pool is alive
174 // we can safely exit since pool is alive
175 }
175 }
176 break;
176 break;
177 } while(true);
177 } while(true);
178 }
178 }
179
179
180
180
181 protected virtual void Dispose(bool disposing) {
181 protected virtual void Dispose(bool disposing) {
182 if (disposing) {
182 if (disposing) {
183 if (0 == Interlocked.CompareExchange(ref m_exit, 1, 0)) { // implies memory barrier
183 if (0 == Interlocked.CompareExchange(ref m_exit, 1, 0)) { // implies memory barrier
184 // wake sleeping threads
184 // wake sleeping threads
185 SignalThread();
185 SignalThread();
186 GC.SuppressFinalize(this);
186 GC.SuppressFinalize(this);
187 }
187 }
188 }
188 }
189 }
189 }
190
190
191 public void Dispose() {
191 public void Dispose() {
192 Dispose(true);
192 Dispose(true);
193 }
193 }
194
194
195 ~DispatchPool() {
195 ~DispatchPool() {
196 Dispose(false);
196 Dispose(false);
197 }
197 }
198 }
198 }
199 }
199 }
@@ -1,78 +1,73
1 using System;
1 using System.Threading;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading;
6
2
7 namespace Implab.Parallels {
3 namespace Implab.Parallels {
8 public class MTQueue<T> {
4 public class MTQueue<T> {
9 class Node {
5 class Node {
10 public Node(T value) {
6 public Node(T value) {
11 this.value = value;
7 this.value = value;
12 }
8 }
13 public readonly T value;
9 public readonly T value;
14 public Node next;
10 public Node next;
15 }
11 }
16
12
17 Node m_first;
13 Node m_first;
18 Node m_last;
14 Node m_last;
19
15
20 public void Enqueue(T value) {
16 public void Enqueue(T value) {
21 Thread.MemoryBarrier();
17 Thread.MemoryBarrier();
22
18
23 var last = m_last;
19 var last = m_last;
24 var next = new Node(value);
20 var next = new Node(value);
25
21
26 while (last != Interlocked.CompareExchange(ref m_last, next, last))
22 while (last != Interlocked.CompareExchange(ref m_last, next, last))
27 last = m_last;
23 last = m_last;
28
24
29 if (last != null)
25 if (last != null)
30 last.next = next;
26 last.next = next;
31 else
27 else
32 m_first = next;
28 m_first = next;
33 }
29 }
34
30
35 public bool TryDequeue(out T value) {
31 public bool TryDequeue(out T value) {
36 Node first;
32 Node first;
37 Node next = null;
33 Node next;
38 value = default(T);
34 value = default(T);
39
35
40 Thread.MemoryBarrier();
36 Thread.MemoryBarrier();
41 do {
37 do {
42 first = m_first;
38 first = m_first;
43 if (first == null)
39 if (first == null)
44 return false;
40 return false;
45 next = first.next;
41 next = first.next;
46 if (next == null) {
42 if (next == null) {
47 // this is the last element,
43 // this is the last element,
48 // then try to update the tail
44 // then try to update the tail
49 if (first != Interlocked.CompareExchange(ref m_last, null, first)) {
45 if (first != Interlocked.CompareExchange(ref m_last, null, first)) {
50 // this is the race condition
46 // this is the race condition
51 if (m_last == null)
47 if (m_last == null)
52 // the queue is empty
48 // the queue is empty
53 return false;
49 return false;
54 // tail has been changed, we need to restart
50 // tail has been changed, we need to restart
55 continue;
51 continue;
56 }
52 }
57
53
58 // tail succesfully updated and first.next will never be changed
54 // tail succesfully updated and first.next will never be changed
59 // other readers will fail due to inconsistency m_last != m_fist && m_first.next == null
55 // other readers will fail due to inconsistency m_last != m_fist && m_first.next == null
60 // however the parallel writer may update the m_first since the m_last is null
56 // however the parallel writer may update the m_first since the m_last is null
61
57
62 // so we need to fix inconsistency by setting m_first to null or if it has been
58 // so we need to fix inconsistency by setting m_first to null or if it has been
63 // updated by the writer already then we should just to give up
59 // updated by the writer already then we should just to give up
64 Interlocked.CompareExchange(ref m_first, null, first);
60 Interlocked.CompareExchange(ref m_first, null, first);
65 break;
61 break;
66
62
67 } else {
68 if (first == Interlocked.CompareExchange(ref m_first, next, first))
69 // head succesfully updated
70 break;
71 }
63 }
64 if (first == Interlocked.CompareExchange(ref m_first, next, first))
65 // head succesfully updated
66 break;
72 } while (true);
67 } while (true);
73
68
74 value = first.value;
69 value = first.value;
75 return true;
70 return true;
76 }
71 }
77 }
72 }
78 }
73 }
General Comments 0
You need to be logged in to leave comments. Login now