Menu

[r1560]: / cppdb / trunk / cppdb / pool.h  Maximize  Restore  History

Download this file

63 lines (47 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef CPPDB_POOL_H
#define CPPDB_POOL_H
#include <cppdb/defs.h>
#include <cppdb/ref_ptr.h>
#include <cppdb/mutex.h>
#include <cppdb/utils.h>
#include <memory>
#include <list>
namespace cppdb {
class connection_info;
namespace backend {
class connection;
}
class CPPDB_API pool : public ref_counted {
pool();
pool(pool const &);
void operator=(pool const &);
pool(connection_info const &ci);
public:
static ref_ptr<pool> create(std::string const &connection_string);
static ref_ptr<pool> create(connection_info const &ci);
~pool();
ref_ptr<backend::connection> open();
void gc();
void put(backend::connection *c_in);
private:
ref_ptr<backend::connection> get();
struct data;
std::auto_ptr<data> d;
struct entry {
entry() : last_used(0) {}
ref_ptr<backend::connection> conn;
time_t last_used;
};
typedef std::list<entry> pool_type;
// non-mutable members
size_t limit_;
int life_time_;
connection_info ci_;
// mutex protected begin
mutex lock_;
size_t size_;
pool_type pool_;
// mutex protected end
};
}
#endif
MongoDB Logo MongoDB