Browse Source

modules/ims_charging: cleaned up ref/unrefs and added filename and line num to debugs

jaybeepee 9 years ago
parent
commit
44b80def0c

+ 3 - 3
modules/ims_charging/dialog.c

@@ -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) {
@@ -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;
@@ -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);
 			//}

+ 2 - 5
modules/ims_charging/ims_ro.c

@@ -667,10 +667,7 @@ error:
     // 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;
 }
@@ -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);
 

+ 3 - 3
modules/ims_charging/mod.c

@@ -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;
 }
 
@@ -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;
@@ -537,7 +537,7 @@ send_ccr:
 	//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;
 	}
 	

+ 17 - 9
modules/ims_charging/ro_session_hash.c

@@ -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);
 }
 
 /*!
@@ -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);
 }
 
 /*!
@@ -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);

+ 4 - 2
modules/ims_charging/ro_session_hash.h

@@ -206,7 +206,8 @@ 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
@@ -214,7 +215,8 @@ 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);
+#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);
 

+ 4 - 4
modules/ims_charging/ro_timer.c

@@ -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) {
@@ -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);
             }
         }
     }
@@ -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);
     }
 
@@ -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");