ScaleOut Native C++ API Library  5.1
 All Classes Functions Variables
handle_pool.h
1 #pragma once
2 
3 #include <vector>
4 #include <boost/thread.hpp>
5 #include "soss_svccli.h"
6 
7 namespace sosscli { namespace internal {
8 
11 {
12 
13 public:
14 
16  static const int DEFAULT_POOL_SIZE = 32;
17 
20  static SOSSLIB_HANDLE get_handle();
21 
23  static void release_handle(SOSSLIB_HANDLE hdl);
24 
26  static unsigned int handles_in_use(void);
27 
33  static void set_max_connections(unsigned int max_connections);
34 
36  static unsigned int max_connections(void) { return max_pool_size_; }
37 
38 private:
39 
42  HandlePool(void) {};
43 
44  // Define copy constructor as a private no-op
45  HandlePool(const HandlePool& rhs) {};
46 
48  static boost::once_flag run_once_;
49  static bool is_init_;
50 
52  static boost::mutex pool_mutex_;
53  static boost::condition_variable wait_for_handle_available_;
54 
56  static std::vector<SOSSLIB_HANDLE> available_handles_;
57 
60  static unsigned int max_pool_size_;
61 
62  static unsigned int handles_in_use_;
63 
65  static void init_once();
66 };
67 
68 } }