Custom memory allocator is optional, and disabled by default

Used new variable GloVars.global.use_proxysql_mem

Issue #184
pull/190/head
René Cannaò 11 years ago
parent 3e8929d9c8
commit 2401b12803

@ -26,6 +26,7 @@ class ProxySQL_GlobalVariables {
struct {
bool gdbg;
bool nostart;
bool use_proxysql_mem;
pthread_mutex_t start_mutex;
bool foreground;
#ifdef DEBUG

@ -35,6 +35,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() {
global.gdbg=false;
global.nostart=false;
global.foreground=false;
global.use_proxysql_mem=false;
pthread_mutex_init(&global.start_mutex,NULL);
#ifdef DEBUG
global.gdb=0;
@ -65,6 +66,7 @@ opt.add(
opt->add((const char *)"",0,0,0,(const char *)"Starts only the admin service",(const char *)"-n",(const char *)"--no-start");
opt->add((const char *)"",0,0,0,(const char *)"Run in foreground",(const char *)"-f",(const char *)"--foreground");
opt->add((const char *)"~/proxysql.cnf",0,1,0,(const char *)"Configuraton file",(const char *)"-c",(const char *)"--config");
opt->add((const char *)"",0,1,0,(const char *)"Disable custom memory allocator",(const char *)"-m",(const char *)"--no-memory");
opt->add((const char *)"",0,1,0,(const char *)"Datadir",(const char *)"-D",(const char *)"--datadir");
opt->add((const char *)"",0,1,0,(const char *)"Configuration DB path",(const char *)"-a",(const char *)"--admin-pathdb");
opt->add((const char *)"",0,1,0,(const char *)"Administration Unix Socket",(const char *)"-S",(const char *)"--admin-socket");
@ -116,6 +118,9 @@ void ProxySQL_GlobalVariables::process_opts_pre() {
GloVars.__cmd_proxysql_datadir=strdup(datadir.c_str());
}
if (opt->isSet("-m")) {
global.use_proxysql_mem=true;
}
#ifdef DEBUG
init_debug_struct();

@ -39,34 +39,41 @@ static inline void __push_mem_block(l_sfc *sfc, void *m) {
l_sfp * l_mem_init() {
l_sfp *s=(l_sfp *)__x_malloc(sizeof(l_sfp));
int i;
for (i=0; i<L_SFP_ARRAY_LEN; i++) {
s->sfc[i].stack=NULL;
s->sfc[i].mem_blocks=NULL;
s->sfc[i].elem_size=L_SFC_MIN_ELEM_SIZE * (1 << i) ;
s->sfc[i].alloc_cnt=0;
s->sfc[i].free_cnt=0;
s->sfc[i].blocks_cnt=0;
s->sfc[i].__mem_l_free_count=0;
}
if (GloVars.global.use_proxysql_mem==true) {
int i;
for (i=0; i<L_SFP_ARRAY_LEN; i++) {
s->sfc[i].stack=NULL;
s->sfc[i].mem_blocks=NULL;
s->sfc[i].elem_size=L_SFC_MIN_ELEM_SIZE * (1 << i) ;
s->sfc[i].alloc_cnt=0;
s->sfc[i].free_cnt=0;
s->sfc[i].blocks_cnt=0;
s->sfc[i].__mem_l_free_count=0;
}
}
return s;
}
void l_mem_destroy(l_sfp *s) {
size_t i,j;
for (i=0; i<L_SFP_ARRAY_LEN; i++) {
for (j=0;j<s->sfc[i].blocks_cnt;j++) {
free(s->sfc[i].mem_blocks[j]);
}
if (s->sfc[i].mem_blocks) {
free(s->sfc[i].mem_blocks);
}
}
if (GloVars.global.use_proxysql_mem==true) {
for (i=0; i<L_SFP_ARRAY_LEN; i++) {
for (j=0;j<s->sfc[i].blocks_cnt;j++) {
free(s->sfc[i].mem_blocks[j]);
}
if (s->sfc[i].mem_blocks) {
free(s->sfc[i].mem_blocks);
}
}
}
free(s);
}
void * __l_alloc(l_sfp *sfp, size_t size) {
if (GloVars.global.use_proxysql_mem==false) {
return malloc(size);
}
if (size>L_SFC_MAX_ELEM_SIZE) {
return __x_malloc(size);
}
@ -119,6 +126,10 @@ void * l_alloc0(size_t size) {
void __l_free(l_sfp *sfp, size_t size, void *p) {
if (GloVars.global.use_proxysql_mem==false) {
free(p);
return;
}
if (size>L_SFC_MAX_ELEM_SIZE) {
free(p);
return;

Loading…
Cancel
Save