@@ -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 |
@@ -13,3 +13,4 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/ |
@@ -16,6 +16,8 Project("{2150E333-8FDC-42A3-9474-1A3956 | |||||
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 | |
@@ -32,22 +34,30 Global | |||||
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 |
{ |
|
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 | |
@@ -64,20 +74,12 Global | |||||
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 = |
|
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 |
@@ -28,22 +28,32 | |||||
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 != |
|
45 | } else if (m_current != LogicalOperation.EMPTY && m_ownership) { | |
42 |
m_current = |
|
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 |
@@ -41,35 +41,36 namespace Implab.Diagnostics { | |||||
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 | } |
@@ -1,7 +1,4 | |||||
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 { | |
@@ -21,10 +18,7 namespace Implab.Diagnostics { | |||||
21 | } |
|
18 | } | |
22 |
|
19 | |||
23 | public override string ToString() { |
|
20 | public override string ToString() { | |
24 |
|
|
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) { |
@@ -11,9 +11,7 namespace Implab.Diagnostics { | |||||
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 | } |
@@ -7,6 +7,8 | |||||
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> | |
@@ -145,6 +147,8 | |||||
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 /> |
@@ -7,9 +7,9 namespace Implab.Parallels { | |||||
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 |
|
10 | int m_threads; // the current size of the pool | |
11 |
int m_maxRunningThreads |
|
11 | int m_maxRunningThreads; // the meximum reached size of the pool | |
12 |
int m_exit |
|
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 |
@@ -1,8 +1,4 | |||||
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> { | |
@@ -34,7 +30,7 namespace Implab.Parallels { | |||||
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 |
|
33 | Node next; | |
38 | value = default(T); |
|
34 | value = default(T); | |
39 |
|
35 | |||
40 | Thread.MemoryBarrier(); |
|
36 | Thread.MemoryBarrier(); | |
@@ -64,11 +60,10 namespace Implab.Parallels { | |||||
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; |
General Comments 0
You need to be logged in to leave comments.
Login now