Skip to content

Commit 5012268

Browse files
author
giacomelli
committed
Merge branch 'release/2.1.0'
2 parents 8d44c4c + d71811f commit 5012268

File tree

18 files changed

+525
-60
lines changed

18 files changed

+525
-60
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

.github/CONTRIBUTING.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## How to contribute to GeneticSharp
2+
3+
### Did you find a bug?
4+
5+
* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/giacomelli/GeneticSharp/issues).
6+
* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/giacomelli/GeneticSharp/issues/new?template=bug_report.md).
7+
8+
### Did you write a fix to a bug?
9+
10+
* Open a new GitHub pull request with the fix.
11+
* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
12+
13+
14+
### Do you intend to add a new feature or change an existing one?
15+
16+
* Suggest your change in a [new feature request](https://github.com/giacomelli/GeneticSharp/issues/new?template=feature_request.md).
17+
* Do not start writing code until you have collected positive feedback about the change.
18+
19+
### Do you have questions about the source code?
20+
* Take a look on our [wiki](https://github.com/giacomelli/GeneticSharp/wiki).
21+
* Ask on GeneticSharp's [tag](https://stackoverflow.com/questions/tagged/geneticsharp) on Stack Overflow.
22+
* Open a [question](https://github.com/giacomelli/GeneticSharp/issues/new?template=question.md).
23+
24+
### Do you want to contribute to the GeneticSharp documentation?
25+
26+
* Please, contribute directly on our [wiki](https://github.com/giacomelli/GeneticSharp/wiki).
27+
28+
Thanks! :heart: :heart: :heart:
29+
30+
Diego Giacomelli

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ after_build:
4747
- cmd: >-
4848
mkdir .\src\nuget
4949
50-
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.0.0
50+
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.1.0
5151
52-
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.0.0
52+
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.1.0
5353
5454
test_script:
5555
- cmd: dotnet clean src/GeneticSharp.Domain.UnitTests

docs/logo/icon-64x64-transparent.png

2.82 KB
Loading

docs/logo/icon-transparent.xcf

45.8 KB
Binary file not shown.

src/GeneticSharp.Domain/GeneticSharp.Domain.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<Owners>g1acomell1</Owners>
2020
<PackageLicenseUrl>https://github.com/giacomelli/GeneticSharp/blob/master/LICENSE</PackageLicenseUrl>
2121
<PackageProjectUrl>https://github.com/giacomelli/GeneticSharp</PackageProjectUrl>
22+
<PackageIconUrl>https://github.com/giacomelli/GeneticSharp/raw/master/docs/logo/icon-64x64-transparent.png</PackageIconUrl>
2223
<PackageReleaseNotes>See changes at https://github.com/giacomelli/GeneticSharp.</PackageReleaseNotes>
2324
<PackageTags>genetic-algorithms geneticsharp genetic algotithms</PackageTags>
2425
</PropertyGroup>

src/GeneticSharp.Domain/Properties/SolutionInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
[assembly: AssemblyConfiguration("Release")]
1212
#endif
1313

14-
[assembly: AssemblyVersion("1.2.0")]
15-
[assembly: AssemblyFileVersion("1.2.0.0")]
14+
[assembly: AssemblyVersion("2.1.0")]
15+
[assembly: AssemblyFileVersion("2.1.0.0")]

src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<Owners>g1acomell1</Owners>
1717
<PackageLicenseUrl>https://github.com/giacomelli/GeneticSharp/blob/master/LICENSE</PackageLicenseUrl>
1818
<PackageProjectUrl>https://github.com/giacomelli/GeneticSharp</PackageProjectUrl>
19+
<PackageIconUrl>https://github.com/giacomelli/GeneticSharp/raw/master/docs/logo/icon-64x64-transparent.png</PackageIconUrl>
1920
<PackageReleaseNotes>See changes at https://github.com/giacomelli/GeneticSharp.</PackageReleaseNotes>
2021
<PackageTags>genetic-algorithms geneticsharp genetic algotithms</PackageTags>
2122
</PropertyGroup>

src/GeneticSharp.Infrastructure.Framework.UnitTests/Threading/ParallelTaskExecutorTest.cs

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,32 @@ public void Stop_ManyTasks_StopAll()
8484
{
8585
var pipeline = "";
8686
var target = new ParallelTaskExecutor();
87-
target.Timeout = TimeSpan.FromMilliseconds(1000);
88-
89-
target.Add(() =>
90-
{
91-
Thread.Sleep(5);
92-
pipeline += "1";
93-
});
94-
target.Add(() =>
95-
{
96-
Thread.Sleep(5);
97-
pipeline += "2";
98-
});
99-
target.Add(() =>
100-
{
101-
Thread.Sleep(5);
102-
pipeline += "3";
103-
});
104-
105-
Parallel.Invoke(
106-
() => Assert.IsTrue(target.Start()),
107-
() =>
108-
{
109-
Thread.Sleep(100);
110-
target.Stop();
111-
});
112-
87+
target.Timeout = TimeSpan.FromMilliseconds(1000);
88+
89+
target.Add(() =>
90+
{
91+
Thread.Sleep(5);
92+
pipeline += "1";
93+
});
94+
target.Add(() =>
95+
{
96+
Thread.Sleep(5);
97+
pipeline += "2";
98+
});
99+
target.Add(() =>
100+
{
101+
Thread.Sleep(5);
102+
pipeline += "3";
103+
});
104+
105+
Parallel.Invoke(
106+
() => Assert.IsTrue(target.Start()),
107+
() =>
108+
{
109+
Thread.Sleep(100);
110+
target.Stop();
111+
});
112+
113113
}
114114

115115
[Test()]
@@ -145,6 +145,48 @@ public void Stop_Tasks_ShutdownCalled()
145145

146146
Assert.IsFalse(target.IsRunning);
147147
}
148+
149+
[Test()]
150+
public void Start_MaxThreads1_DoNotBlockOtherThreads()
151+
{
152+
var target = new ParallelTaskExecutor
153+
{
154+
MinThreads = 1,
155+
MaxThreads = 1
156+
};
157+
158+
target.Add(() =>
159+
{
160+
});
161+
target.Add(() =>
162+
{
163+
Thread.Sleep(200);
164+
});
165+
target.Add(() =>
166+
{
167+
Thread.Sleep(10);
168+
});
169+
170+
171+
int otherThreadCount = 0;
172+
var otherThread = new System.Timers.Timer(50)
173+
{
174+
AutoReset = true
175+
};
176+
otherThread.Elapsed += (sender, arg) =>
177+
{
178+
otherThreadCount++;
179+
};
180+
otherThread.Start();
181+
182+
Task.Run(() =>
183+
{
184+
target.Start();
185+
}).Wait();
186+
187+
otherThread.Stop();
188+
Assert.GreaterOrEqual(otherThreadCount, 2);
189+
}
148190
}
149191
}
150192

src/GeneticSharp.Infrastructure.Framework/Threading/ParallelTaskExecutor.cs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ public ParallelTaskExecutor()
3939
/// <returns>If has reach the timeout false, otherwise true.</returns>
4040
public override bool Start()
4141
{
42-
// Configure the ThreadPool min and max threads number to the define on this instance properties..
43-
ThreadPool.GetMinThreads(out int minWorker, out int minIOC);
44-
ThreadPool.SetMinThreads(MinThreads, minIOC);
45-
46-
ThreadPool.GetMaxThreads(out int maxWorker, out int maxIOC);
47-
ThreadPool.SetMaxThreads(MaxThreads, maxIOC);
42+
SetThreadPoolConfig(out int minWorker, out int minIOC, out int maxWorker, out int maxIOC);
4843

4944
try
5045
{
@@ -68,22 +63,57 @@ public override bool Start()
6863
}
6964
finally
7065
{
71-
// Rollback ThreadPool previous min and max threads configuration.
72-
ThreadPool.SetMinThreads(minWorker, minIOC);
73-
ThreadPool.SetMaxThreads(maxWorker, maxIOC);
74-
66+
ResetThreadPoolConfig(minWorker, minIOC, maxWorker, maxIOC);
7567
IsRunning = false;
7668
}
77-
}
78-
69+
}
70+
7971
/// <summary>
8072
/// Stops the tasks execution.
8173
/// </summary>
82-
public override void Stop()
74+
public override void Stop()
8375
{
8476
base.Stop();
8577
m_cancellationTokenSource.Cancel();
8678
IsRunning = false;
8779
}
88-
}
80+
81+
/// <summary>
82+
/// Configure the ThreadPool min and max threads number to the define on this instance properties.
83+
/// </summary>
84+
/// <param name="minWorker">Minimum worker.</param>
85+
/// <param name="minIOC">Minimum ioc.</param>
86+
/// <param name="maxWorker">Max worker.</param>
87+
/// <param name="maxIOC">Max ioc.</param>
88+
private void SetThreadPoolConfig(out int minWorker, out int minIOC, out int maxWorker, out int maxIOC)
89+
{
90+
// Do not change values if the new values to min and max threads are lower than already configured on ThreadPool.
91+
ThreadPool.GetMinThreads(out minWorker, out minIOC);
92+
93+
if (MinThreads > minWorker)
94+
{
95+
ThreadPool.SetMinThreads(MinThreads, minIOC);
96+
}
97+
98+
ThreadPool.GetMaxThreads(out maxWorker, out maxIOC);
99+
100+
if (MaxThreads > maxWorker)
101+
{
102+
ThreadPool.SetMaxThreads(MaxThreads, maxIOC);
103+
}
104+
}
105+
106+
/// <summary>
107+
/// Rollback ThreadPool previous min and max threads configuration.
108+
/// </summary>
109+
/// <param name="minWorker">Minimum worker.</param>
110+
/// <param name="minIOC">Minimum ioc.</param>
111+
/// <param name="maxWorker">Max worker.</param>
112+
/// <param name="maxIOC">Max ioc.</param>
113+
private static void ResetThreadPoolConfig(int minWorker, int minIOC, int maxWorker, int maxIOC)
114+
{
115+
ThreadPool.SetMinThreads(minWorker, minIOC);
116+
ThreadPool.SetMaxThreads(maxWorker, maxIOC);
117+
}
118+
}
89119
}

0 commit comments

Comments
 (0)