mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-10 13:06:24 +02:00
Common: Get rid of Executor.cpp/h.
There was only one implementation.
This commit is contained in:
1 parent
8c72cc119e
commit
e6aa841b78
12 files changed
+25
-79
No files matched your search
@@ -597,8 +597,6 @@ add_library(Common STATIC
|
||||
Common/Render/Text/draw_text_uwp.h
|
||||
Common/System/Display.cpp
|
||||
Common/System/Display.h
|
||||
Common/Thread/Executor.cpp
|
||||
Common/Thread/Executor.h
|
||||
Common/Thread/PrioritizedWorkQueue.cpp
|
||||
Common/Thread/PrioritizedWorkQueue.h
|
||||
Common/Thread/ThreadUtil.cpp
|
||||
|
||||
@@ -523,7 +523,6 @@
|
||||
<ClInclude Include="System\Display.h" />
|
||||
<ClInclude Include="System\NativeApp.h" />
|
||||
<ClInclude Include="System\System.h" />
|
||||
<ClInclude Include="Thread\Executor.h" />
|
||||
<ClInclude Include="Thread\PrioritizedWorkQueue.h" />
|
||||
<ClInclude Include="Thread\ThreadPool.h" />
|
||||
<ClInclude Include="Thread\ThreadUtil.h" />
|
||||
@@ -860,7 +859,6 @@
|
||||
<ClCompile Include="OSVersion.cpp" />
|
||||
<ClCompile Include="StringUtils.cpp" />
|
||||
<ClCompile Include="System\Display.cpp" />
|
||||
<ClCompile Include="Thread\Executor.cpp" />
|
||||
<ClCompile Include="Thread\PrioritizedWorkQueue.cpp" />
|
||||
<ClCompile Include="Thread\ThreadPool.cpp" />
|
||||
<ClCompile Include="Thread\ThreadUtil.cpp" />
|
||||
|
||||
@@ -102,9 +102,6 @@
|
||||
<ClInclude Include="Thread\ThreadUtil.h">
|
||||
<Filter>Thread</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Thread\Executor.h">
|
||||
<Filter>Thread</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Input\GestureDetector.h">
|
||||
<Filter>Input</Filter>
|
||||
</ClInclude>
|
||||
@@ -494,9 +491,6 @@
|
||||
<ClCompile Include="Thread\ThreadUtil.cpp">
|
||||
<Filter>Thread</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Thread\Executor.cpp">
|
||||
<Filter>Thread</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Input\GestureDetector.cpp">
|
||||
<Filter>Input</Filter>
|
||||
</ClCompile>
|
||||
|
||||
@@ -37,11 +37,21 @@
|
||||
#include "Common/Net/HTTPServer.h"
|
||||
#include "Common/Net/Sinks.h"
|
||||
#include "Common/File/FileDescriptor.h"
|
||||
#include "Common/Thread/Executor.h"
|
||||
|
||||
#include "Common/Buffer.h"
|
||||
#include "Common/Log.h"
|
||||
|
||||
void NewThreadExecutor::Run(std::function<void()> &&func) {
|
||||
threads_.push_back(std::thread(func));
|
||||
}
|
||||
|
||||
NewThreadExecutor::~NewThreadExecutor() {
|
||||
// If Run was ever called...
|
||||
for (auto &thread : threads_)
|
||||
thread.join();
|
||||
threads_.clear();
|
||||
}
|
||||
|
||||
namespace http {
|
||||
|
||||
// Note: charset here helps prevent XSS.
|
||||
@@ -126,7 +136,7 @@ void Request::Close() {
|
||||
}
|
||||
}
|
||||
|
||||
Server::Server(threading::Executor *executor)
|
||||
Server::Server(NewThreadExecutor *executor)
|
||||
: port_(0), executor_(executor) {
|
||||
RegisterHandler("/", std::bind(&Server::HandleListing, this, std::placeholders::_1));
|
||||
SetFallbackHandler(std::bind(&Server::Handle404, this, std::placeholders::_1));
|
||||
|
||||
+12
-3
@@ -2,10 +2,19 @@
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
|
||||
#include "Common/Net/HTTPHeaders.h"
|
||||
#include "Common/Net/Resolve.h"
|
||||
#include "Common/Thread/Executor.h"
|
||||
|
||||
class NewThreadExecutor {
|
||||
public:
|
||||
~NewThreadExecutor();
|
||||
void Run(std::function<void()> &&func);
|
||||
|
||||
private:
|
||||
std::vector<std::thread> threads_;
|
||||
};
|
||||
|
||||
namespace net {
|
||||
class InputSink;
|
||||
@@ -61,7 +70,7 @@ private:
|
||||
class Server {
|
||||
public:
|
||||
// Takes ownership.
|
||||
Server(threading::Executor *executor);
|
||||
Server(NewThreadExecutor *executor);
|
||||
virtual ~Server();
|
||||
|
||||
typedef std::function<void(const Request &)> UrlHandlerFunc;
|
||||
@@ -108,7 +117,7 @@ private:
|
||||
UrlHandlerMap handlers_;
|
||||
UrlHandlerFunc fallback_;
|
||||
|
||||
threading::Executor *executor_;
|
||||
NewThreadExecutor *executor_;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
@@ -1,23 +0,0 @@
|
||||
#include "Common/Thread/Executor.h"
|
||||
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
|
||||
namespace threading {
|
||||
|
||||
void SameThreadExecutor::Run(std::function<void()> func) {
|
||||
func();
|
||||
}
|
||||
|
||||
void NewThreadExecutor::Run(std::function<void()> func) {
|
||||
threads_.push_back(std::thread(func));
|
||||
}
|
||||
|
||||
NewThreadExecutor::~NewThreadExecutor() {
|
||||
// If Run was ever called...
|
||||
for (auto &thread : threads_)
|
||||
thread.join();
|
||||
threads_.clear();
|
||||
}
|
||||
|
||||
} // namespace threading
|
||||
@@ -1,30 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace threading {
|
||||
|
||||
// Stuff that can execute other stuff, like threadpools, should inherit from this.
|
||||
class Executor {
|
||||
public:
|
||||
virtual void Run(std::function<void()> func) = 0;
|
||||
virtual ~Executor() {}
|
||||
};
|
||||
|
||||
class SameThreadExecutor : public Executor {
|
||||
public:
|
||||
void Run(std::function<void()> func) override;
|
||||
};
|
||||
|
||||
class NewThreadExecutor : public Executor {
|
||||
public:
|
||||
~NewThreadExecutor() override;
|
||||
void Run(std::function<void()> func) override;
|
||||
|
||||
private:
|
||||
std::vector<std::thread> threads_;
|
||||
};
|
||||
|
||||
} // namespace threading
|
||||
+1
-1
@@ -249,7 +249,7 @@ static void ForwardDebuggerRequest(const http::Request &request) {
|
||||
static void ExecuteWebServer() {
|
||||
setCurrentThreadName("HTTPServer");
|
||||
|
||||
auto http = new http::Server(new threading::NewThreadExecutor());
|
||||
auto http = new http::Server(new NewThreadExecutor());
|
||||
http->RegisterHandler("/", &HandleListing);
|
||||
// This lists all the (current) recent ISOs.
|
||||
http->SetFallbackHandler(&HandleFallback);
|
||||
|
||||
@@ -483,7 +483,6 @@
|
||||
<ClInclude Include="..\..\Common\System\Display.h" />
|
||||
<ClInclude Include="..\..\Common\System\NativeApp.h" />
|
||||
<ClInclude Include="..\..\Common\System\System.h" />
|
||||
<ClInclude Include="..\..\Common\Thread\Executor.h" />
|
||||
<ClInclude Include="..\..\Common\Thread\PrioritizedWorkQueue.h" />
|
||||
<ClInclude Include="..\..\Common\Thread\ThreadPool.h" />
|
||||
<ClInclude Include="..\..\Common\Thread\ThreadUtil.h" />
|
||||
@@ -591,7 +590,6 @@
|
||||
<ClCompile Include="..\..\Common\OSVersion.cpp" />
|
||||
<ClCompile Include="..\..\Common\StringUtils.cpp" />
|
||||
<ClCompile Include="..\..\Common\System\Display.cpp" />
|
||||
<ClCompile Include="..\..\Common\Thread\Executor.cpp" />
|
||||
<ClCompile Include="..\..\Common\Thread\PrioritizedWorkQueue.cpp" />
|
||||
<ClCompile Include="..\..\Common\Thread\ThreadPool.cpp" />
|
||||
<ClCompile Include="..\..\Common\Thread\ThreadUtil.cpp" />
|
||||
|
||||
@@ -178,9 +178,6 @@
|
||||
<ClCompile Include="..\..\Common\Input\InputState.cpp">
|
||||
<Filter>Input</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Common\Thread\Executor.cpp">
|
||||
<Filter>Thread</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Common\Thread\PrioritizedWorkQueue.cpp">
|
||||
<Filter>Thread</Filter>
|
||||
</ClCompile>
|
||||
@@ -453,9 +450,6 @@
|
||||
<ClInclude Include="..\..\Common\Input\KeyCodes.h">
|
||||
<Filter>Input</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Common\Thread\Executor.h">
|
||||
<Filter>Thread</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Common\Thread\PrioritizedWorkQueue.h">
|
||||
<Filter>Thread</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -279,7 +279,6 @@ EXEC_AND_LIB_FILES := \
|
||||
$(SRC)/Common/Net/WebsocketServer.cpp \
|
||||
$(SRC)/Common/Profiler/Profiler.cpp \
|
||||
$(SRC)/Common/System/Display.cpp \
|
||||
$(SRC)/Common/Thread/Executor.cpp \
|
||||
$(SRC)/Common/Thread/PrioritizedWorkQueue.cpp \
|
||||
$(SRC)/Common/Thread/ThreadPool.cpp \
|
||||
$(SRC)/Common/Thread/ThreadUtil.cpp \
|
||||
|
||||
@@ -204,7 +204,6 @@ SOURCES_CXX += \
|
||||
$(COMMONDIR)/Render/DrawBuffer.cpp \
|
||||
$(COMMONDIR)/Render/TextureAtlas.cpp \
|
||||
$(COMMONDIR)/Serialize/Serializer.cpp \
|
||||
$(COMMONDIR)/Thread/Executor.cpp \
|
||||
$(COMMONDIR)/Thread/ThreadUtil.cpp \
|
||||
$(COMMONDIR)/Thread/ThreadPool.cpp \
|
||||
$(COMMONDIR)/Thread/PrioritizedWorkQueue.cpp \
|
||||
|
||||
Reference in new issue
Block a user