##// END OF EJS Templates
Added SafePool
cin -
r61:90069a2ec20a default
parent child
Show More
@@ -0,0 +1,40
1 using Implab.Parallels;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Threading;
7
8 namespace Implab {
9 public class SafePool<T> where T : new() {
10 readonly MTQueue<T> m_queue = new MTQueue<T>();
11 readonly int m_size;
12 int m_count = 0;
13
14 public SafePool() : this(10) {
15
16 }
17
18 public SafePool(int size) {
19 Safe.ArgumentInRange(size,1,size,"size");
20
21 m_size = size;
22 }
23
24 public T Allocate() {
25 T instance;
26 if (m_queue.TryDequeue(out instance)) {
27 Interlocked.Decrement(ref m_count);
28 return instance;
29 }
30 return new T();
31 }
32
33 public void Release(T instance) {
34 if (m_count < m_size) {
35 Interlocked.Increment(ref m_count);
36 m_queue.Enqueue(instance);
37 }
38 }
39 }
40 }
@@ -1,106 +1,107
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 <ProductVersion>10.0.0</ProductVersion>
6 <ProductVersion>10.0.0</ProductVersion>
7 <SchemaVersion>2.0</SchemaVersion>
7 <SchemaVersion>2.0</SchemaVersion>
8 <ProjectGuid>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</ProjectGuid>
8 <ProjectGuid>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</ProjectGuid>
9 <OutputType>Library</OutputType>
9 <OutputType>Library</OutputType>
10 <RootNamespace>Implab</RootNamespace>
10 <RootNamespace>Implab</RootNamespace>
11 <AssemblyName>Implab</AssemblyName>
11 <AssemblyName>Implab</AssemblyName>
12 </PropertyGroup>
12 </PropertyGroup>
13 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
13 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14 <DebugSymbols>true</DebugSymbols>
14 <DebugSymbols>true</DebugSymbols>
15 <DebugType>full</DebugType>
15 <DebugType>full</DebugType>
16 <Optimize>false</Optimize>
16 <Optimize>false</Optimize>
17 <OutputPath>bin\Debug</OutputPath>
17 <OutputPath>bin\Debug</OutputPath>
18 <DefineConstants>TRACE;DEBUG;</DefineConstants>
18 <DefineConstants>TRACE;DEBUG;</DefineConstants>
19 <ErrorReport>prompt</ErrorReport>
19 <ErrorReport>prompt</ErrorReport>
20 <WarningLevel>4</WarningLevel>
20 <WarningLevel>4</WarningLevel>
21 <ConsolePause>false</ConsolePause>
21 <ConsolePause>false</ConsolePause>
22 <RunCodeAnalysis>true</RunCodeAnalysis>
22 <RunCodeAnalysis>true</RunCodeAnalysis>
23 </PropertyGroup>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25 <DebugType>full</DebugType>
25 <DebugType>full</DebugType>
26 <Optimize>true</Optimize>
26 <Optimize>true</Optimize>
27 <OutputPath>bin\Release</OutputPath>
27 <OutputPath>bin\Release</OutputPath>
28 <ErrorReport>prompt</ErrorReport>
28 <ErrorReport>prompt</ErrorReport>
29 <WarningLevel>4</WarningLevel>
29 <WarningLevel>4</WarningLevel>
30 <ConsolePause>false</ConsolePause>
30 <ConsolePause>false</ConsolePause>
31 </PropertyGroup>
31 </PropertyGroup>
32 <ItemGroup>
32 <ItemGroup>
33 <Reference Include="System" />
33 <Reference Include="System" />
34 <Reference Include="System.XML" />
34 <Reference Include="System.XML" />
35 </ItemGroup>
35 </ItemGroup>
36 <ItemGroup>
36 <ItemGroup>
37 <Compile Include="Component.cs" />
37 <Compile Include="Component.cs" />
38 <Compile Include="CustomEqualityComparer.cs" />
38 <Compile Include="CustomEqualityComparer.cs" />
39 <Compile Include="Diagnostics\ConsoleTraceListener.cs" />
39 <Compile Include="Diagnostics\ConsoleTraceListener.cs" />
40 <Compile Include="Diagnostics\EventText.cs" />
40 <Compile Include="Diagnostics\EventText.cs" />
41 <Compile Include="Diagnostics\IEventTextFormatter.cs" />
41 <Compile Include="Diagnostics\IEventTextFormatter.cs" />
42 <Compile Include="Diagnostics\LogChannel.cs" />
42 <Compile Include="Diagnostics\LogChannel.cs" />
43 <Compile Include="Diagnostics\LogicalOperation.cs" />
43 <Compile Include="Diagnostics\LogicalOperation.cs" />
44 <Compile Include="Diagnostics\TextFileListener.cs" />
44 <Compile Include="Diagnostics\TextFileListener.cs" />
45 <Compile Include="Diagnostics\TextListenerBase.cs" />
45 <Compile Include="Diagnostics\TextListenerBase.cs" />
46 <Compile Include="Diagnostics\TraceLog.cs" />
46 <Compile Include="Diagnostics\TraceLog.cs" />
47 <Compile Include="Diagnostics\TraceContext.cs" />
47 <Compile Include="Diagnostics\TraceContext.cs" />
48 <Compile Include="Diagnostics\TraceEvent.cs" />
48 <Compile Include="Diagnostics\TraceEvent.cs" />
49 <Compile Include="Diagnostics\TraceEventType.cs" />
49 <Compile Include="Diagnostics\TraceEventType.cs" />
50 <Compile Include="Disposable.cs" />
50 <Compile Include="Disposable.cs" />
51 <Compile Include="ICancellable.cs" />
51 <Compile Include="ICancellable.cs" />
52 <Compile Include="IProgressHandler.cs" />
52 <Compile Include="IProgressHandler.cs" />
53 <Compile Include="IProgressNotifier.cs" />
53 <Compile Include="IProgressNotifier.cs" />
54 <Compile Include="IPromise.cs" />
54 <Compile Include="IPromise.cs" />
55 <Compile Include="IPromiseBase.cs" />
55 <Compile Include="IPromiseBase.cs" />
56 <Compile Include="IServiceLocator.cs" />
56 <Compile Include="IServiceLocator.cs" />
57 <Compile Include="ITaskController.cs" />
57 <Compile Include="ITaskController.cs" />
58 <Compile Include="JSON\JSONElementContext.cs" />
58 <Compile Include="JSON\JSONElementContext.cs" />
59 <Compile Include="JSON\JSONElementType.cs" />
59 <Compile Include="JSON\JSONElementType.cs" />
60 <Compile Include="JSON\JSONGrammar.cs" />
60 <Compile Include="JSON\JSONGrammar.cs" />
61 <Compile Include="JSON\JSONParser.cs" />
61 <Compile Include="JSON\JSONParser.cs" />
62 <Compile Include="JSON\JSONScanner.cs" />
62 <Compile Include="JSON\JSONScanner.cs" />
63 <Compile Include="JSON\JsonTokenType.cs" />
63 <Compile Include="JSON\JsonTokenType.cs" />
64 <Compile Include="JSON\JSONWriter.cs" />
64 <Compile Include="JSON\JSONWriter.cs" />
65 <Compile Include="JSON\JSONXmlReader.cs" />
65 <Compile Include="JSON\JSONXmlReader.cs" />
66 <Compile Include="JSON\JSONXmlReaderOptions.cs" />
66 <Compile Include="JSON\JSONXmlReaderOptions.cs" />
67 <Compile Include="JSON\StringTranslator.cs" />
67 <Compile Include="JSON\StringTranslator.cs" />
68 <Compile Include="Parallels\DispatchPool.cs" />
68 <Compile Include="Parallels\DispatchPool.cs" />
69 <Compile Include="Parallels\ArrayTraits.cs" />
69 <Compile Include="Parallels\ArrayTraits.cs" />
70 <Compile Include="Parallels\MTQueue.cs" />
70 <Compile Include="Parallels\MTQueue.cs" />
71 <Compile Include="Parallels\WorkerPool.cs" />
71 <Compile Include="Parallels\WorkerPool.cs" />
72 <Compile Include="Parsing\Alphabet.cs" />
72 <Compile Include="Parsing\Alphabet.cs" />
73 <Compile Include="Parsing\AlphabetBase.cs" />
73 <Compile Include="Parsing\AlphabetBase.cs" />
74 <Compile Include="Parsing\AltToken.cs" />
74 <Compile Include="Parsing\AltToken.cs" />
75 <Compile Include="Parsing\BinaryToken.cs" />
75 <Compile Include="Parsing\BinaryToken.cs" />
76 <Compile Include="Parsing\CatToken.cs" />
76 <Compile Include="Parsing\CatToken.cs" />
77 <Compile Include="Parsing\CDFADefinition.cs" />
77 <Compile Include="Parsing\CDFADefinition.cs" />
78 <Compile Include="Parsing\DFABuilder.cs" />
78 <Compile Include="Parsing\DFABuilder.cs" />
79 <Compile Include="Parsing\DFADefinitionBase.cs" />
79 <Compile Include="Parsing\DFADefinitionBase.cs" />
80 <Compile Include="Parsing\DFAStateDescriptor.cs" />
80 <Compile Include="Parsing\DFAStateDescriptor.cs" />
81 <Compile Include="Parsing\DFAutomaton.cs" />
81 <Compile Include="Parsing\DFAutomaton.cs" />
82 <Compile Include="Parsing\EDFADefinition.cs" />
82 <Compile Include="Parsing\EDFADefinition.cs" />
83 <Compile Include="Parsing\EmptyToken.cs" />
83 <Compile Include="Parsing\EmptyToken.cs" />
84 <Compile Include="Parsing\EndToken.cs" />
84 <Compile Include="Parsing\EndToken.cs" />
85 <Compile Include="Parsing\EnumAlphabet.cs" />
85 <Compile Include="Parsing\EnumAlphabet.cs" />
86 <Compile Include="Parsing\Grammar.cs" />
86 <Compile Include="Parsing\Grammar.cs" />
87 <Compile Include="Parsing\IAlphabet.cs" />
87 <Compile Include="Parsing\IAlphabet.cs" />
88 <Compile Include="Parsing\IDFADefinition.cs" />
88 <Compile Include="Parsing\IDFADefinition.cs" />
89 <Compile Include="Parsing\IVisitor.cs" />
89 <Compile Include="Parsing\IVisitor.cs" />
90 <Compile Include="Parsing\ParserException.cs" />
90 <Compile Include="Parsing\ParserException.cs" />
91 <Compile Include="Parsing\Scanner.cs" />
91 <Compile Include="Parsing\Scanner.cs" />
92 <Compile Include="Parsing\StarToken.cs" />
92 <Compile Include="Parsing\StarToken.cs" />
93 <Compile Include="Parsing\SymbolToken.cs" />
93 <Compile Include="Parsing\SymbolToken.cs" />
94 <Compile Include="Parsing\Token.cs" />
94 <Compile Include="Parsing\Token.cs" />
95 <Compile Include="SafePool.cs" />
95 <Compile Include="ServiceLocator.cs" />
96 <Compile Include="ServiceLocator.cs" />
96 <Compile Include="TaskController.cs" />
97 <Compile Include="TaskController.cs" />
97 <Compile Include="ProgressInitEventArgs.cs" />
98 <Compile Include="ProgressInitEventArgs.cs" />
98 <Compile Include="Properties\AssemblyInfo.cs" />
99 <Compile Include="Properties\AssemblyInfo.cs" />
99 <Compile Include="Promise.cs" />
100 <Compile Include="Promise.cs" />
100 <Compile Include="Parallels\AsyncPool.cs" />
101 <Compile Include="Parallels\AsyncPool.cs" />
101 <Compile Include="Safe.cs" />
102 <Compile Include="Safe.cs" />
102 <Compile Include="ValueEventArgs.cs" />
103 <Compile Include="ValueEventArgs.cs" />
103 </ItemGroup>
104 </ItemGroup>
104 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
105 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
105 <ItemGroup />
106 <ItemGroup />
106 </Project> No newline at end of file
107 </Project>
General Comments 0
You need to be logged in to leave comments. Login now