Browse code

dialog: functions to search dialog by uuid and keep table entry locked

- helper macros to lock/unlock table entry with dlg cell structure

Daniel-Constantin Mierla authored on 23/03/2020 16:36:44
Showing 2 changed files
... ...
@@ -762,9 +762,10 @@ error:
762 762
  * the reference counter by one again iff a dialog has been found.
763 763
  * \param h_entry number of the hash table entry
764 764
  * \param h_id id of the hash table entry
765
+ * \param lmode id if 0, then dlg table entry is unlocked, otherwise is locked
765 766
  * \return dialog structure on success, NULL on failure
766 767
  */
767
-dlg_cell_t *dlg_lookup( unsigned int h_entry, unsigned int h_id)
768
+dlg_cell_t *dlg_lookup_mode(unsigned int h_entry, unsigned int h_id, int lmode)
768 769
 {
769 770
 	dlg_cell_t *dlg;
770 771
 	dlg_entry_t *d_entry;
... ...
@@ -777,24 +778,59 @@ dlg_cell_t *dlg_lookup( unsigned int h_entry, unsigned int h_id)
777 778
 
778 779
 	d_entry = &(d_table->entries[h_entry]);
779 780
 
780
-	dlg_lock( d_table, d_entry);
781
+	dlg_lock(d_table, d_entry);
781 782
 
782 783
 	for( dlg=d_entry->first ; dlg ; dlg=dlg->next ) {
783 784
 		if (dlg->h_id == h_id) {
784 785
 			ref_dlg_unsafe(dlg, 1);
785
-			dlg_unlock( d_table, d_entry);
786
+			if (likely(lmode == 0)) {
787
+				dlg_unlock(d_table, d_entry);
788
+			}
786 789
 			LM_DBG("dialog id=%u found on entry %u\n", h_id, h_entry);
787 790
 			return dlg;
788 791
 		}
789 792
 	}
790 793
 
791
-	dlg_unlock( d_table, d_entry);
794
+	dlg_unlock(d_table, d_entry);
792 795
 not_found:
793 796
 	LM_DBG("no dialog id=%u found on entry %u\n", h_id, h_entry);
794 797
 	return 0;
795 798
 }
796 799
 
797 800
 
801
+/*!
802
+ * \brief Lookup a dialog in the global list
803
+ *
804
+ * Note that the caller is responsible for decrementing (or reusing)
805
+ * the reference counter by one again iff a dialog has been found.
806
+ * \param h_entry number of the hash table entry
807
+ * \param h_id id of the hash table entry
808
+ * \return dialog structure on success, NULL on failure
809
+ */
810
+dlg_cell_t *dlg_lookup(unsigned int h_entry, unsigned int h_id)
811
+{
812
+	return dlg_lookup_mode(h_entry, h_id, 0);
813
+}
814
+
815
+/*!
816
+ * \brief Search a dialog in the global list by iuid
817
+ *
818
+ * Note that the caller is responsible for decrementing (or reusing)
819
+ * the reference counter by one again if a dialog has been found.
820
+ * \param diuid internal unique id per dialog
821
+ * \param lmode id if 0, then dlg table entry is unlocked, otherwise is locked
822
+ * \return dialog structure on success, NULL on failure
823
+ */
824
+dlg_cell_t* dlg_get_by_iuid_mode(dlg_iuid_t *diuid, int lmode)
825
+{
826
+	if(diuid==NULL)
827
+		return NULL;
828
+	if(diuid->h_id==0)
829
+		return NULL;
830
+	/* dlg ref counter is increased by next line */
831
+	return dlg_lookup_mode(diuid->h_entry, diuid->h_id, lmode);
832
+}
833
+
798 834
 /*!
799 835
  * \brief Search a dialog in the global list by iuid
800 836
  *
... ...
@@ -810,7 +846,7 @@ dlg_cell_t* dlg_get_by_iuid(dlg_iuid_t *diuid)
810 846
 	if(diuid->h_id==0)
811 847
 		return NULL;
812 848
 	/* dlg ref counter is increased by next line */
813
-	return dlg_lookup(diuid->h_entry, diuid->h_id);
849
+	return dlg_lookup_mode(diuid->h_entry, diuid->h_id, 0);
814 850
 }
815 851
 
816 852
 /*!
... ...
@@ -201,6 +201,21 @@ extern dlg_table_t *d_table;
201 201
 			} \
202 202
 		} while(0)
203 203
 
204
+/*!
205
+ * \brief Set a dialog lock (re-entrant)
206
+ * \param _dlg dialog cell
207
+ */
208
+#define dlg_cell_lock(_dlg) \
209
+	dlg_lock(d_table, &(d_table->entries[(_dlg)->h_entry]))
210
+
211
+/*!
212
+ * \brief Set a dialog lock (re-entrant)
213
+ * \param _dlg dialog cell
214
+ */
215
+#define dlg_cell_unlock(_dlg) \
216
+	dlg_unlock(d_table, &(d_table->entries[(_dlg)->h_entry]))
217
+
218
+
204 219
 /*!
205 220
  * \brief Unlink a dialog from the list without locking
206 221
  * \see unref_dlg_unsafe