1
0
forked from blue/pica
pica/database/pool.h

48 lines
1.0 KiB
C
Raw Normal View History

2023-12-30 22:42:11 +00:00
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
//SPDX-License-Identifier: GPL-3.0-or-later
2023-12-29 17:40:00 +00:00
#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;
};
}