oblong pools

This commit is contained in:
malloc 2018-04-13 15:57:30 -05:00
parent 329c9209b2
commit f68dc50d5b
5 changed files with 51 additions and 6 deletions

View file

@ -0,0 +1 @@
#include "database.hpp"

View file

@ -0,0 +1,11 @@
#ifndef SOSC_DATABASE_H
#define SOSC_DATABASE_H
#include "sqlite/sqlite3.h"
namespace sosc {
namespace db {
}}
#endif

View file

@ -1,7 +1,6 @@
#ifndef SOSC_POOL_H #ifndef SOSC_POOL_H
#define SOSC_POOL_H #define SOSC_POOL_H
#include <numeric>
#include <vector> #include <vector>
#include <list> #include <list>
#include <thread> #include <thread>
@ -42,7 +41,7 @@ protected:
private: private:
class Stack { class Stack {
public: public:
Stack(Pool<T> *pool); Stack(Pool<T>* pool);
void Start(); void Start();
void AddClient(T* client); void AddClient(T* client);
@ -50,6 +49,8 @@ private:
void Stop(); void Stop();
private: private:
void StackThread();
std::thread thread; std::thread thread;
Pool<T> *pool; Pool<T> *pool;
bool is_open; bool is_open;
@ -61,6 +62,7 @@ private:
poolinfo_t info; poolinfo_t info;
bool is_running; bool is_running;
std::vector<Stack> stacks; std::vector<Stack> stacks;
friend class Stack; friend class Stack;
}; };
@ -72,7 +74,7 @@ Pool<T>::Pool(const poolinfo_t& info) {
template<class T> template<class T>
void Pool<T>::Start() { void Pool<T>::Start() {
if(this->is_running == true) if(this->is_running)
return; return;
for(int i = 0; i < this->info.initial_count; ++i) { for(int i = 0; i < this->info.initial_count; ++i) {
@ -85,18 +87,49 @@ void Pool<T>::Start() {
template<class T> template<class T>
bool Pool<T>::AddClient(T* client) { bool Pool<T>::AddClient(T* client) {
// TODO
return false; return false;
} }
template<class T> template<class T>
int Pool<T>::ClientCount() const { int Pool<T>::ClientCount() const {
if(!this->is_running)
return 0;
int count = 0; int count = 0;
for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i) for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i)
count += i->ClientCount(); count += i->ClientCount();
return count; return count;
} }
template<class T>
void Pool<T>::Stop() {
if(!this->is_running)
return;
for(auto i = this->stacks.begin(); i != this->stacks.end(); ++i)
i->Stop();
stacks->clear();
this->is_running = false;
}
template<class T>
Pool<T>::Stack::Stack(Pool<T>* pool) {
this->pool = pool;
this->is_open = false;
}
template<class T>
void Pool<T>::Stack::Start() {
if(this->is_open)
return;
this->thread = std::thread(this->StackThread, this);
this->is_open = true;
}
} }
#endif #endif