Basic pool settup

This commit is contained in:
Benjamin Kyd
2019-04-06 18:09:05 +01:00
parent 0a6c492fef
commit dc062bfb00
9 changed files with 99 additions and 1 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
.vscode/ .vscode/
.vs/

30
CMakeLists.txt Normal file
View File

@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.7)
Project(libpool)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} CMakeModules/)
cmake_policy(SET CMP0037 OLD)
set(CMAKE_BUILD_TYPE Release)
set(executable output)
set(SrcDIR ./test)
set(IncludeDIR ./include)
include_directories(${executable} ./libpool)
set(THREADS_PREFER_PTHREAD_FLAD ON)
find_package(Threads REQUIRED)
file(GLOB SourceFiles
${SrcDIR}/*
)
add_executable(${executable} ${SourceFiles})
set_target_properties(${executable} PROPERTIES
CXX_STANDARD 17
CXX_EXTENSIONS OFF
)
target_link_libraries(${executable}
Threads::Threads
)

17
CMakeSettings.json Normal file
View File

@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}
]
}

BIN
Stuff.lnk Normal file

Binary file not shown.

5
libpool/libpool.cpp Normal file
View File

@@ -0,0 +1,5 @@
#include "./libpool.h"
Pool::Pool(int iNumThreads) {
}

View File

@@ -0,0 +1,36 @@
#ifndef LIBPOOL_LIBPOOL_H_
#define LIBPOOL_LIBPOOL_H_
#include <iostream>
#include <vector>
#include <thread>
#include <queue>
#include <memory>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <future>
#include <functional>
class Pool {
public:
Pool(int iNumThreads = 2);
void resize(int iNumThreads);
template<class F, class... Args>
auto addToQueue(F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>;
private:
std::vector<std::thread> m_vWorkers;
std::queue<std::function<void()>> m_qTaskQueue;
std::mutex m_mQueueMutex;
std::condition_variable m_cCondition;
bool m_bStop;
int m_iThreads = 2;
};
#endif

BIN
output.exe Normal file

Binary file not shown.

1
test/build.bat Normal file
View File

@@ -0,0 +1 @@
g++ main.cpp ../libpool/*.cpp -I../libpool/ -pthread -o ../output.exe

View File

@@ -0,0 +1,9 @@
#include <iostream>
#include <libpool.h>
int main(int argc, char** argv) {
Pool threadPool { 5 };
}