Skip to content

Commit

Permalink
modules/ims_charging: cleaned up ref/unrefs and added filename and li…
Browse files Browse the repository at this point in the history
…ne num to debugs
  • Loading branch information
jaybeepee committed Oct 3, 2016
1 parent 39fee94 commit 44b80de
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
6 changes: 3 additions & 3 deletions modules/ims_charging/dialog.c
Expand Up @@ -93,7 +93,7 @@ void dlg_answered(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
if (ret != 0) {
LM_CRIT("unable to insert timer for Ro Session [%.*s]\n", session->ro_session_id.len, session->ro_session_id.s);
} else {
ref_ro_session_unsafe(session, 1); // lock already acquired
ref_ro_session(session, 1, 0); // lock already acquired
}

if (ro_db_mode == DB_MODE_REALTIME) {
Expand Down Expand Up @@ -184,7 +184,7 @@ void dlg_terminated(struct dlg_cell *dlg, int type, unsigned int termcode, char*

LM_DBG("processing dlg_terminated in Ro and session [%.*s] has active = %d", ro_session->ro_session_id.len, ro_session->ro_session_id.s, ro_session->active);
if ((!ro_session->active && (ro_session->start_time != 0)) || (ro_session->ccr_sent == 1)) {
unref_ro_session_unsafe(ro_session,1,ro_session_entry);
unref_ro_session(ro_session,1,0);
LM_DBG("CCR already sent or Ro Session is not active, but may have been answered [%d]\n", (int)ro_session->start_time);
ro_session_unlock(ro_session_table, ro_session_entry);
return;
Expand Down Expand Up @@ -217,7 +217,7 @@ void dlg_terminated(struct dlg_cell *dlg, int type, unsigned int termcode, char*
}

//ro_session->start_time;
unref_ro_session_unsafe(ro_session, 1+unref, ro_session_entry); //lock already acquired
unref_ro_session(ro_session, 1+unref, 0); //lock already acquired
//unref_ro_session_unsafe(ro_session, 2+unref, ro_session_entry); //lock already acquired
ro_session_unlock(ro_session_table, ro_session_entry);
//}
Expand Down
7 changes: 2 additions & 5 deletions modules/ims_charging/ims_ro.c
Expand Up @@ -667,10 +667,7 @@ void send_ccr_interim(struct ro_session* ro_session, unsigned int used, unsigned
// since callback function will be never called because of the error, we need to release the lock on the session
// to it can be reused later.
//
struct ro_session_entry *ro_session_entry = &(ro_session_table->entries[ro_session->h_entry]);
ro_session_lock(ro_session_table, ro_session_entry);
unref_ro_session_unsafe(ro_session, 1, ro_session_entry); //unref from the initial timer that fired this event.
ro_session_unlock(ro_session_table, ro_session_entry);
unref_ro_session(ro_session, 1, 1);

return;
}
Expand Down Expand Up @@ -1372,7 +1369,7 @@ static void resume_on_initial_ccr(int is_timeout, void *param, AAAMessage *cca,
};
}

unref_ro_session(ssd->ro_session, 1); /* release our reference */
unref_ro_session(ssd->ro_session, 1, 1); /* release our reference */

create_cca_return_code(RO_RETURN_TRUE);

Expand Down
6 changes: 3 additions & 3 deletions modules/ims_charging/mod.c
Expand Up @@ -338,7 +338,7 @@ static int w_ro_set_session_id_avp(struct sip_msg *msg, char *str1, char *str2)
//set avp response with session id
res = create_response_avp_string("ro_session_id", &ro_session->ro_session_id);
dlgb.release_dlg(dlg);
unref_ro_session(ro_session, 1);
unref_ro_session(ro_session, 1, 1);
return res;
}

Expand Down Expand Up @@ -425,7 +425,7 @@ static int w_ro_ccr_stop(struct sip_msg *msg, char* c_direction, char* _code, ch
ro_session->active = -1;
// counter_add(ims_charging_cnts_h.active_ro_sessions, -1);
done:
unref_ro_session_unsafe(ro_session, 1, ro_session_entry);
unref_ro_session(ro_session, 1, 0);
ro_session_unlock(ro_session_table, ro_session_entry);
dlgb.release_dlg(dlg);
return RO_RETURN_TRUE;
Expand Down Expand Up @@ -537,7 +537,7 @@ static int w_ro_ccr(struct sip_msg *msg, char* c_route_name, char* c_direction,
//if it already exists then we go to done
if (single_ro_session_per_dialog && (ro_session = lookup_ro_session(dlg->h_entry, &dlg->callid, 0, 0))) {
LM_DBG("single_ro_session_per_dialog = 1 and ro_session already exists for this dialog -so we don't need to send another one\n");
unref_ro_session(ro_session,1);//for the lookup ro session ref
unref_ro_session(ro_session,1,1);//for the lookup ro session ref
goto done;
}

Expand Down
26 changes: 17 additions & 9 deletions modules/ims_charging/ro_session_hash.c
Expand Up @@ -50,14 +50,19 @@ void link_ro_session(struct ro_session *ro_session, int n) {
* \param ro_session Ro Session
* \param cnt increment for the reference counter
*/
void ref_ro_session(struct ro_session *ro_session, unsigned int cnt) {
void ref_ro_session_helper(struct ro_session *ro_session, unsigned int cnt, unsigned int mustlock, char *fname, int fline) {
struct ro_session_entry *ro_session_entry;

LM_DBG("ref op on %p with %d from %s:%d\n", ro_session, cnt, fname, fline);
ro_session_entry = &(ro_session_table->entries[ro_session->h_entry]);

ro_session_lock(ro_session_table, ro_session_entry);
ref_ro_session_unsafe(ro_session, cnt);
ro_session_unlock(ro_session_table, ro_session_entry);
if (mustlock)
ro_session_lock(ro_session_table, ro_session_entry);

ref_ro_session_unsafe(ro_session, cnt);

if (mustlock)
ro_session_unlock(ro_session_table, ro_session_entry);
}

/*!
Expand All @@ -66,14 +71,17 @@ void ref_ro_session(struct ro_session *ro_session, unsigned int cnt) {
* \param ro_session Ro Session
* \param cnt decrement for the reference counter
*/
void unref_ro_session(struct ro_session *ro_session, unsigned int cnt) {
void unref_ro_session_helper(struct ro_session *ro_session, unsigned int cnt, unsigned int mustlock, char *fname, int fline) {
struct ro_session_entry *ro_session_entry;

ro_session_entry = &(ro_session_table->entries[ro_session->h_entry]);
LM_DBG("unref op on %p with %d from %s:%d\n", ro_session, cnt, fname, fline);

ro_session_lock(ro_session_table, ro_session_entry);
ro_session_entry = &(ro_session_table->entries[ro_session->h_entry]);
if (mustlock)
ro_session_lock(ro_session_table, ro_session_entry);
unref_ro_session_unsafe(ro_session, cnt, ro_session_entry);
ro_session_unlock(ro_session_table, ro_session_entry);
if (mustlock)
ro_session_unlock(ro_session_table, ro_session_entry);
}

/*!
Expand Down Expand Up @@ -299,7 +307,7 @@ struct ro_session* lookup_ro_session(unsigned int h_entry, str* callid, int dire

for (ro_session = ro_session_entry->first; ro_session; ro_session = ro_session->next) {
if ((direction==0 || direction==ro_session->direction) && (strncmp(ro_session->callid.s, callid->s, callid->len)==0)) {
ref_ro_session_unsafe(ro_session,1);
ref_ro_session(ro_session, 1, 0);
LM_DBG("ref ro_session %p with 1 -> %d\n", ro_session, ro_session->ref);
ro_session_unlock(ro_session_table, ro_session_entry);
LM_DBG("ro_session id=%u found on entry %u\n", ro_session->h_id, h_entry);
Expand Down
6 changes: 4 additions & 2 deletions modules/ims_charging/ro_session_hash.h
Expand Up @@ -206,15 +206,17 @@ struct ro_session* build_new_ro_session(int direction, int auth_appid, int auth_
* \param ro_session Ro Session
* \param cnt increment for the reference counter
*/
void ref_ro_session(struct ro_session *ro_session, unsigned int cnt);
void ref_ro_session_helper(struct ro_session *ro_session, unsigned int cnt, unsigned int mustlock, char *fname, int fline);
#define ref_ro_session(ro_session, cnt, mustlock) ref_ro_session_helper(ro_session, cnt, mustlock, __FILE__, __LINE__)

/*!
* \brief Unreference a ro_session with locking
* \see unref_ro_session_unsafe
* \param ro_session Ro Session
* \param cnt decrement for the reference counter
*/
void unref_ro_session(struct ro_session *ro_session, unsigned int cnt);
void unref_ro_session_helper(struct ro_session *ro_session, unsigned int cnt, unsigned int mustlock, char *fname, int fline);
#define unref_ro_session(ro_session, cnt, mustlock) unref_ro_session_helper(ro_session, cnt, mustlock, __FILE__, __LINE__)

struct ro_session* lookup_ro_session(unsigned int h_entry, str *callid, int direction, unsigned int *del);

Expand Down
8 changes: 4 additions & 4 deletions modules/ims_charging/ro_timer.c
Expand Up @@ -319,7 +319,7 @@ void resume_ro_session_ontimeout(struct interim_ccr *i_req, int timeout_or_error
LM_CRIT("unable to insert timer for Ro Session [%.*s]\n",
i_req->ro_session->ro_session_id.len, i_req->ro_session->ro_session_id.s);
} else {
ref_ro_session_unsafe(i_req->ro_session, 1);
ref_ro_session(i_req->ro_session, 1, 0);
}

if (ro_db_mode == DB_MODE_REALTIME) {
Expand Down Expand Up @@ -359,7 +359,7 @@ void resume_ro_session_ontimeout(struct interim_ccr *i_req, int timeout_or_error
LM_CRIT("unable to insert timer for Ro Session [%.*s]\n",
i_req->ro_session->ro_session_id.len, i_req->ro_session->ro_session_id.s);
} else {
ref_ro_session_unsafe(i_req->ro_session, 1);
ref_ro_session(i_req->ro_session, 1, 0);
}
}
}
Expand All @@ -368,7 +368,7 @@ void resume_ro_session_ontimeout(struct interim_ccr *i_req, int timeout_or_error
// if call was forcefully terminated, the lock was released before dlgb.lookup_terminate_dlg() function call.
//
if (!call_terminated) {
unref_ro_session_unsafe(i_req->ro_session, 1, ro_session_entry); //unref from the initial timer that fired this event.
unref_ro_session(i_req->ro_session, 1, 0); //unref from the initial timer that fired this event.
ro_session_unlock(ro_session_table, ro_session_entry);
}

Expand Down Expand Up @@ -464,7 +464,7 @@ void ro_session_ontimeout(struct ro_tl *tl) {
LM_CRIT("unable to insert timer for Ro Session [%.*s]\n",
ro_session->ro_session_id.len, ro_session->ro_session_id.s);
} else {
ref_ro_session_unsafe(ro_session, 1);
ref_ro_session(ro_session, 1, 0);
return;
}
LM_ERR("Immediately killing call due to unknown error\n");
Expand Down

0 comments on commit 44b80de

Please sign in to comment.