Use own linked list for storing disused contexts for freeing.

Seemed to be a problem with getting it to work under a hash and there
isn't really any need for a hash.
pull/211/merge
Roger A. Light 11 years ago
parent 2a922e9f06
commit dcd469c177

@ -235,7 +235,7 @@ struct mosquitto {
#ifdef WITH_BROKER
UT_hash_handle hh_id;
UT_hash_handle hh_sock;
UT_hash_handle hh_for_free;
struct mosquitto *for_free_next;
# ifdef WITH_BRIDGE
UT_hash_handle hh_bridge;
# endif

@ -142,11 +142,6 @@ void mqtt3_context_cleanup(struct mosquitto_db *db, struct mosquitto *context, b
context->address = NULL;
}
HASH_FIND(hh_for_free, db->contexts_for_free, context, sizeof(void *), ctx_tmp);
if(ctx_tmp){
HASH_DELETE(hh_for_free, db->contexts_for_free, context);
}
if(context->id){
assert(db); /* db can only be NULL here if the client hasn't sent a
CONNECT and hence wouldn't have an id. */
@ -202,3 +197,26 @@ void mqtt3_context_disconnect(struct mosquitto_db *db, struct mosquitto *ctxt)
_mosquitto_socket_close(db, ctxt);
}
void mosquitto__add_context_to_disused(struct mosquitto_db *db, struct mosquitto *context)
{
if(db->ll_for_free){
context->for_free_next = db->ll_for_free;
db->ll_for_free = context;
}else{
db->ll_for_free = context;
}
}
void mosquitto__free_disused_contexts(struct mosquitto_db *db)
{
assert(db);
struct mosquitto *context, *next;
context = db->ll_for_free;
while(context){
next = context->for_free_next;
mqtt3_context_cleanup(db, context, true);
context = next;
}
}

@ -93,10 +93,7 @@ int mosquitto_main_loop(struct mosquitto_db *db, int *listensock, int listensock
}
while(run){
HASH_ITER(hh_for_free, db->contexts_for_free, context, ctxt_tmp){
HASH_DELETE(hh_for_free, db->contexts_for_free, context);
mqtt3_context_cleanup(db, context, true);
}
mosquitto__free_disused_contexts(db);
#ifdef WITH_SYS_TREE
if(db->config->sys_interval > 0){
mqtt3_db_sys_update(db, db->config->sys_interval, start_time);
@ -367,7 +364,7 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
#else
if(context->clean_session){
#endif
HASH_ADD_KEYPTR(hh_for_free, db->contexts_for_free, context, sizeof(void *), context);
mosquitto__add_context_to_disused(db, context);
if(context->id){
HASH_DELETE(hh_id, db->contexts_by_id, context);
_mosquitto_free(context->id);

@ -381,10 +381,7 @@ int main(int argc, char *argv[])
mqtt3_context_cleanup(&int_db, ctxt, true);
}
#endif
HASH_ITER(hh_for_free, int_db.contexts_for_free, ctxt, ctxt_tmp){
HASH_DELETE(hh_for_free, int_db.contexts_for_free, ctxt);
mqtt3_context_cleanup(&int_db, ctxt, true);
}
mosquitto__free_disused_contexts(&int_db);
mqtt3_db_close(&int_db);

@ -223,6 +223,7 @@ struct mosquitto_db{
int subscription_count;
int retained_count;
#endif
struct mosquitto *ll_for_free;
};
enum mqtt3_bridge_direction{
@ -400,6 +401,8 @@ int mqtt3_subs_clean_session(struct mosquitto_db *db, struct mosquitto *context,
struct mosquitto *mqtt3_context_init(struct mosquitto_db *db, int sock);
void mqtt3_context_cleanup(struct mosquitto_db *db, struct mosquitto *context, bool do_free);
void mqtt3_context_disconnect(struct mosquitto_db *db, struct mosquitto *context);
void mosquitto__add_context_to_disused(struct mosquitto_db *db, struct mosquitto *context);
void mosquitto__free_disused_contexts(struct mosquitto_db *db);
/* ============================================================
* Logging functions

@ -500,16 +500,16 @@ int mqtt3_handle_connect(struct mosquitto_db *db, struct mosquitto *context)
ws_ctxt_user_head = ws_ctxt_user_head->next;
}
ws_ctxt_user_head->next = ws_ctxt_user;
HASH_ADD_KEYPTR(hh_for_free, db->contexts_for_free, context, sizeof(void *), context);
mosquitto__add_context_to_disused(db, context);
}else{
HASH_ADD_KEYPTR(hh_for_free, db->contexts_for_free, context, sizeof(void *), context);
mosquitto__add_context_to_disused(db, context);
HASH_DELETE(hh_sock, db->contexts_by_sock, context);
context->sock = INVALID_SOCKET;
HASH_ADD(hh_sock, db->contexts_by_sock, sock, sizeof(found_context->sock), found_context);
}
#else
HASH_ADD_KEYPTR(hh_for_free, db->contexts_for_free, context, sizeof(void *), context);
mosquitto__add_context_to_disused(db, context);
HASH_DELETE(hh_sock, db->contexts_by_sock, context);
context->sock = INVALID_SOCKET;

Loading…
Cancel
Save