connection_manager support option: bg_thread_enabled
parent
47ed8fb46c
commit
f7ac526284
|
|
@ -473,11 +473,12 @@ static int init_group_array(SFConnectionManager *cm,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sf_connection_manager_init(SFConnectionManager *cm,
|
||||
int sf_connection_manager_init_ex(SFConnectionManager *cm,
|
||||
const SFClientCommonConfig *common_cfg, const int group_count,
|
||||
const int server_group_index, const int server_count,
|
||||
const int max_count_per_entry, const int max_idle_time,
|
||||
fc_connection_callback_func connect_done_callback, void *args)
|
||||
fc_connection_callback_func connect_done_callback, void *args,
|
||||
const bool bg_thread_enabled)
|
||||
{
|
||||
const int socket_domain = AF_INET;
|
||||
int htable_init_capacity;
|
||||
|
|
@ -502,7 +503,9 @@ int sf_connection_manager_init(SFConnectionManager *cm,
|
|||
|
||||
cm->server_group_index = server_group_index;
|
||||
cm->common_cfg = common_cfg;
|
||||
cm->bg_thread_enabled = bg_thread_enabled;
|
||||
cm->max_servers_per_group = 0;
|
||||
cm->extra = NULL;
|
||||
|
||||
cm->ops.get_connection = get_connection;
|
||||
cm->ops.get_server_connection = get_server_connection;
|
||||
|
|
@ -817,6 +820,10 @@ int sf_connection_manager_start(SFConnectionManager *cm)
|
|||
__sync_bool_compare_and_swap(&group->alives, NULL, sptr_array);
|
||||
}
|
||||
|
||||
if (cm->bg_thread_enabled) {
|
||||
return fc_create_thread(&tid, connection_manager_thread_func,
|
||||
cm, SF_G_THREAD_STACK_SIZE);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,33 +101,51 @@ typedef struct sf_cm_operations {
|
|||
sf_get_connection_parameters get_connection_params;
|
||||
} SFCMOperations;
|
||||
|
||||
typedef struct sf_cm_simple_extra {
|
||||
/* master connection cache */
|
||||
struct {
|
||||
ConnectionInfo *conn;
|
||||
ConnectionInfo holder;
|
||||
} master_cache;
|
||||
void *args[2];
|
||||
} SFCMSimpleExtra;
|
||||
|
||||
typedef struct sf_connection_manager {
|
||||
int server_group_index;
|
||||
int max_servers_per_group;
|
||||
short server_group_index;
|
||||
short max_servers_per_group;
|
||||
bool bg_thread_enabled;
|
||||
const SFClientCommonConfig *common_cfg;
|
||||
SFCMConnGroupArray groups;
|
||||
ConnectionPool cpool;
|
||||
struct fast_mblock_man sptr_array_allocator; //element: SFCMServerPtrArray
|
||||
SFCMOperations ops;
|
||||
SFCMSimpleExtra *extra; //for simple
|
||||
} SFConnectionManager;
|
||||
|
||||
int sf_connection_manager_init(SFConnectionManager *cm,
|
||||
int sf_connection_manager_init_ex(SFConnectionManager *cm,
|
||||
const SFClientCommonConfig *common_cfg, const int group_count,
|
||||
const int server_group_index, const int server_count,
|
||||
const int max_count_per_entry, const int max_idle_time,
|
||||
fc_connection_callback_func connect_done_callback, void *args);
|
||||
fc_connection_callback_func connect_done_callback, void *args,
|
||||
const bool bg_thread_enabled);
|
||||
|
||||
static inline int sf_connection_manager_init(SFConnectionManager *cm,
|
||||
const SFClientCommonConfig *common_cfg, const int group_count,
|
||||
const int server_group_index, const int server_count,
|
||||
const int max_count_per_entry, const int max_idle_time,
|
||||
fc_connection_callback_func connect_done_callback, void *args)
|
||||
{
|
||||
const bool bg_thread_enabled = true;
|
||||
return sf_connection_manager_init_ex(cm, common_cfg, group_count,
|
||||
server_group_index, server_count, max_count_per_entry,
|
||||
max_idle_time, connect_done_callback, args, bg_thread_enabled);
|
||||
}
|
||||
|
||||
int sf_connection_manager_add(SFConnectionManager *cm, const int group_id,
|
||||
FCServerInfo **servers, const int count);
|
||||
|
||||
int sf_connection_manager_start(SFConnectionManager *cm);
|
||||
|
||||
ConnectionInfo *sf_connection_manager_get_master(SFConnectionManager *cm,
|
||||
const int group_index, int *err_no);
|
||||
|
||||
ConnectionInfo *sf_connection_manager_get_readable(SFConnectionManager *cm,
|
||||
const int group_index, int *err_no);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue