pica/database/pool.h

48 lines
1.0 KiB
C++

//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
//SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <string>
#include <memory>
#include <queue>
#include <mutex>
#include <condition_variable>
#include "interface.h"
#include "resource.h"
namespace DB {
class Pool : public std::enable_shared_from_this<Pool> {
struct Private {};
friend class Resource;
void free(std::unique_ptr<Interface> interface);
public:
Pool(Private);
Pool(const Pool&) = delete;
Pool(Pool&&) = delete;
~Pool();
Pool& operator = (const Pool&) = delete;
Pool& operator = (Pool&&) = delete;
static std::shared_ptr<Pool> create();
Resource request();
void addInterfaces(
Interface::Type type,
std::size_t amount,
const std::string& login,
const std::string& password,
const std::string& database,
const std::string& path
);
private:
std::mutex mutex;
std::condition_variable conditional;
std::queue<std::unique_ptr<Interface>> interfaces;
};
}