mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-10-26 09:55:14 +00:00
중간저장(다시 큐 방식으로 돌아가되, 실시간 스트리밍 방식으로 비동기 처리를 구현할 것임)
This commit is contained in:
40
include/AsyncDownloadManager.hpp
Normal file
40
include/AsyncDownloadManager.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#ifndef _ASYNCDOWNLOADMANAGER_HPP_
|
||||
#define _ASYNCDOWNLOADMANAGER_HPP_
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#define WORKER_COUNT 5
|
||||
|
||||
namespace bumbleBee {
|
||||
class AsyncDownloadManager {
|
||||
public:
|
||||
static void enqueue(std::string query) {
|
||||
static AsyncDownloadManager dl;
|
||||
std::thread th(&bumbleBee::AsyncDownloadManager::enqueueAsyncDL, &dl, query);
|
||||
th.detach();
|
||||
}
|
||||
private:
|
||||
AsyncDownloadManager(){
|
||||
for (int i=0; i<WORKER_COUNT; i++) {
|
||||
std::thread th(&bumbleBee::AsyncDownloadManager::downloadWorker, &(*this));
|
||||
th.detach();
|
||||
}
|
||||
}
|
||||
~AsyncDownloadManager(){}
|
||||
AsyncDownloadManager(const AsyncDownloadManager& ref) = delete;
|
||||
AsyncDownloadManager& operator=(const AsyncDownloadManager& ref) = delete;
|
||||
|
||||
void enqueueAsyncDL(std::string query);
|
||||
void downloadWorker();
|
||||
|
||||
std::queue<std::string> downloadQueue;
|
||||
std::condition_variable dlQueueCondition;
|
||||
std::mutex dlQueueMutex;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user