Skip to content

Commit fb2965e

Browse files
author
Dan Liebault
committed
Ajout d'un pool de threads au projet
Implémentation de `thread_pool` avec les fichiers `thread_pool.cpp` et `thread_pool.hpp`. Mise à jour des fichiers de projet pour inclure ces nouveaux fichiers dans les groupes de compilation et d'inclusion. Les fichiers sont organisés sous le filtre `utils` pour une meilleure structure du projet.
1 parent 916078b commit fb2965e

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

R3DVoxel/R3DVoxel.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<ClCompile Include="Application.cpp" />
150150
<ClCompile Include="main.cpp" />
151151
<ClCompile Include="utils\perlin.cpp" />
152+
<ClCompile Include="utils\thread_pool.cpp" />
152153
<ClCompile Include="VoxelEngine\Chunk.cpp" />
153154
<ClCompile Include="VoxelEngine\ChunkManager.cpp" />
154155
<ClCompile Include="VoxelEngine\TerrainGenerator.cpp" />
@@ -157,6 +158,7 @@
157158
<ItemGroup>
158159
<ClInclude Include="Application.h" />
159160
<ClInclude Include="utils\perlin.h" />
161+
<ClInclude Include="utils\thread_pool.hpp" />
160162
<ClInclude Include="VoxelEngine\Chunk.h" />
161163
<ClInclude Include="VoxelEngine\ChunkManager.h" />
162164
<ClInclude Include="VoxelEngine\Cube.h" />

R3DVoxel/R3DVoxel.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<ClCompile Include="WorldMenu.cpp">
4141
<Filter>Core\UI</Filter>
4242
</ClCompile>
43+
<ClCompile Include="utils\thread_pool.cpp">
44+
<Filter>utils</Filter>
45+
</ClCompile>
4346
</ItemGroup>
4447
<ItemGroup>
4548
<ClInclude Include="Application.h">
@@ -66,5 +69,8 @@
6669
<ClInclude Include="WorldMenu.h">
6770
<Filter>Core\UI</Filter>
6871
</ClInclude>
72+
<ClInclude Include="utils\thread_pool.hpp">
73+
<Filter>utils</Filter>
74+
</ClInclude>
6975
</ItemGroup>
7076
</Project>

R3DVoxel/utils/thread_pool.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "thread_pool.hpp"
2+
3+
void thread_pool_t::init(size_t n)
4+
{
5+
workers.reserve(n);
6+
for (size_t i = 0; i < n; ++i)
7+
{
8+
workers.emplace_back(&thread_pool_t::worker, this);
9+
}
10+
}
11+
12+
void thread_pool_t::worker()
13+
{
14+
}

R3DVoxel/utils/thread_pool.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef R3DVOXEL_THREAD_POOL_HPP
2+
#define R3DVOXEL_THREAD_POOL_HPP
3+
4+
#include <mutex>
5+
#include <vector>
6+
#include <thread>
7+
8+
struct thread_pool_t
9+
{
10+
std::vector<std::thread> workers;
11+
std::mutex mutex;
12+
13+
void init(size_t n = std::thread::hardware_concurrency());
14+
void worker();
15+
};
16+
17+
#endif // R3D_THREAD_POOL_HPP

0 commit comments

Comments
 (0)