mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 01:45:15 +00:00
일단 저장
This commit is contained in:
18
include/Audio/MusicPlayerThreadManager.hpp
Normal file
18
include/Audio/MusicPlayerThreadManager.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <dpp/dpp.h>
|
||||
#include <Queue/MusicQueueElement.hpp>
|
||||
#include "Utils/ThreadPool.hpp"
|
||||
|
||||
namespace bumbleBee {
|
||||
class ThreadManager : public ThreadPool<dpp::snowflake, int, int> {
|
||||
public:
|
||||
bool addMusic(std::shared_ptr<bumbleBee::MusicQueueElement> music, dpp::discord_voice_client* client);
|
||||
void stopSending(dpp::snowflake gid);
|
||||
private:
|
||||
// GID, 쓰레드
|
||||
std::unordered_map<dpp::snowflake, std::thread> threadPool;
|
||||
// GID, 쓰레드 종료
|
||||
std::unordered_map<dpp::snowflake, bool> terminating;
|
||||
};
|
||||
}
|
||||
25
include/Utils/ThreadPool.hpp
Normal file
25
include/Utils/ThreadPool.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <queue>
|
||||
|
||||
namespace bumbleBee {
|
||||
template <typename FuncRet, typename FuncParam>
|
||||
class ThreadPool {
|
||||
public:
|
||||
ThreadPool() = delete;
|
||||
ThreadPool(std::int32_t threadCount);
|
||||
|
||||
std::thread::id execute(std::function<FuncRet(FuncParam)> function);
|
||||
void gracefullStop(std::thread::id thread);
|
||||
void gracefullAllStop();
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::condition_variable condition_;
|
||||
std::int32_t threadCount_;
|
||||
std::vector<std::thread> threadPool_;
|
||||
std::unordered_map<std::thread, std::bool> terminating_;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user