Skip to content

Commit

Permalink
overhauled TaskGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed May 11, 2017
1 parent 3ffcd1a commit 069ed4b
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 179 deletions.
4 changes: 2 additions & 2 deletions Plugin/fccore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<ClCompile Include="fccore\Encoder\Windows\fcMP4_WMF.cpp" />
<ClCompile Include="fccore\fccore.cpp" />
<ClCompile Include="fccore\Foundation\Buffer.cpp" />
<ClCompile Include="fccore\Foundation\TaskGroup.cpp" />
<ClCompile Include="fccore\GraphicsDevice\fcGraphicsDevice.cpp" />
<ClCompile Include="fccore\GraphicsDevice\fcGraphicsDeviceD3D11.cpp" />
<ClCompile Include="fccore\GraphicsDevice\fcGraphicsDeviceD3D9.cpp" />
Expand All @@ -51,7 +52,6 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Master|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Master|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="fccore\Foundation\fcThreadPool.cpp" />
<ClCompile Include="fccore\Foundation\Misc.cpp" />
<ClCompile Include="fccore\Foundation\PixelFormat.cpp" />
<ClCompile Include="fccore\Foundation\TaskQueue.cpp" />
Expand All @@ -74,11 +74,11 @@
<ClInclude Include="fccore\Encoder\fcWebMWriter.h" />
<ClInclude Include="fccore\fccore.h" />
<ClInclude Include="fccore\fcInternal.h" />
<ClInclude Include="fccore\Foundation\TaskGroup.h" />
<ClInclude Include="fccore\GraphicsDevice\fcGraphicsDevice.h" />
<ClInclude Include="fccore\pch.h" />
<ClInclude Include="fccore\Foundation\Buffer.h" />
<ClInclude Include="fccore\Foundation\fcFoundation.h" />
<ClInclude Include="fccore\Foundation\fcThreadPool.h" />
<ClInclude Include="fccore\Foundation\LazyInstance.h" />
<ClInclude Include="fccore\Foundation\Misc.h" />
<ClInclude Include="fccore\Foundation\PixelFormat.h" />
Expand Down
12 changes: 6 additions & 6 deletions Plugin/fccore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
<ClCompile Include="fccore\pch.cpp">
<Filter>fccore</Filter>
</ClCompile>
<ClCompile Include="fccore\Foundation\fcThreadPool.cpp">
<Filter>fccore\Foundation</Filter>
</ClCompile>
<ClCompile Include="fccore\Foundation\Misc.cpp">
<Filter>fccore\Foundation</Filter>
</ClCompile>
Expand All @@ -97,6 +94,9 @@
<ClCompile Include="fccore\Encoder\fcWaveContext.cpp">
<Filter>fccore\Encoder</Filter>
</ClCompile>
<ClCompile Include="fccore\Foundation\TaskGroup.cpp">
<Filter>fccore\Foundation</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="fccore\GraphicsDevice\fcGraphicsDevice.h">
Expand Down Expand Up @@ -156,9 +156,6 @@
<ClInclude Include="fccore\Foundation\fcFoundation.h">
<Filter>fccore\Foundation</Filter>
</ClInclude>
<ClInclude Include="fccore\Foundation\fcThreadPool.h">
<Filter>fccore\Foundation</Filter>
</ClInclude>
<ClInclude Include="fccore\Foundation\LazyInstance.h">
<Filter>fccore\Foundation</Filter>
</ClInclude>
Expand All @@ -177,6 +174,9 @@
<ClInclude Include="fccore\Encoder\fcFlacContext.h">
<Filter>fccore\Encoder</Filter>
</ClInclude>
<ClInclude Include="fccore\Foundation\TaskGroup.h">
<Filter>fccore\Foundation</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="fccore">
Expand Down
2 changes: 1 addition & 1 deletion Plugin/fccore/Encoder/fcExrContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class fcExrContext : public fcIExrContext
fcExrConfig m_conf;
fcIGraphicsDevice *m_dev = nullptr;
fcExrTaskData *m_task = nullptr;
fcTaskGroup m_tasks;
TaskGroup m_tasks;
std::atomic_int m_active_task_count = { 0 };

const void *m_frame_prev = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Plugin/fccore/Encoder/fcGifContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class fcGifContext : public fcIGifContext
std::vector<fcGifTaskData*> m_buffers_unused;
std::list<fcGifFrame> m_gif_frames;
jo_gif_t m_gif;
fcTaskGroup m_tasks;
TaskGroup m_tasks;
std::mutex m_mutex;
int m_frame = 0;
bool m_force_keyframe = false;
Expand Down
4 changes: 2 additions & 2 deletions Plugin/fccore/Encoder/fcMP4Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Box
public:
Box(BinaryStream& stream) : m_stream(stream) {}

template<class F>
void operator()(u32 name, const F &f)
template<class Body>
void operator()(u32 name, const Body &f)
{
size_t offset = m_stream.tellp();
m_stream << u32(0) << name; // reserve
Expand Down
2 changes: 1 addition & 1 deletion Plugin/fccore/Encoder/fcPngContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class fcPngContext : public fcIPngContext
private:
fcPngConfig m_conf;
fcIGraphicsDevice *m_dev = nullptr;
fcTaskGroup m_tasks;
TaskGroup m_tasks;
std::atomic_int m_active_task_count = { 0 };
};

Expand Down
20 changes: 20 additions & 0 deletions Plugin/fccore/Foundation/TaskGroup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "pch.h"
#include "fcInternal.h"
#include "TaskGroup.h"

TaskGroup::TaskGroup()
{
}

TaskGroup::~TaskGroup()
{
wait();
}

void TaskGroup::wait()
{
for (auto& f : m_futures) {
f.get();
}
m_futures.clear();
}
32 changes: 32 additions & 0 deletions Plugin/fccore/Foundation/TaskGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
#include <vector>
#include <deque>
#include <future>
#include <atomic>

class TaskGroup
{
public:
TaskGroup();
~TaskGroup();

int getMaxTasks() const { return m_max_tasks; }
void setMaxTasks(int v) { m_max_tasks = v; }

void wait();

template<class Body>
void run(const Body &body)
{
while (m_futures.size() >= m_max_tasks) {
m_futures.front().get();
m_futures.pop_front();
}

m_futures.push_back(std::async(std::launch::async, body));
}

private:
std::deque<std::future<void>> m_futures;
int m_max_tasks = 8;
};
2 changes: 1 addition & 1 deletion Plugin/fccore/Foundation/fcFoundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
#include "PixelFormat.h"
#include "YUV.h"
#include "LazyInstance.h"
#include "fcThreadPool.h"
#include "TaskGroup.h"
#include "TaskQueue.h"
96 changes: 0 additions & 96 deletions Plugin/fccore/Foundation/fcThreadPool.cpp

This file was deleted.

69 changes: 0 additions & 69 deletions Plugin/fccore/Foundation/fcThreadPool.h

This file was deleted.

0 comments on commit 069ed4b

Please sign in to comment.