Module: kamailio Branch: master Commit: a4f8c0291bfd32752c0c2c323f618c6ac0c91d53 URL: https://github.com/kamailio/kamailio/commit/a4f8c0291bfd32752c0c2c323f618c6a...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2020-03-23T17:36:44+01:00
dialog: functions to search dialog by uuid and keep table entry locked
- helper macros to lock/unlock table entry with dlg cell structure
---
Modified: src/modules/dialog/dlg_hash.c Modified: src/modules/dialog/dlg_hash.h
---
Diff: https://github.com/kamailio/kamailio/commit/a4f8c0291bfd32752c0c2c323f618c6a... Patch: https://github.com/kamailio/kamailio/commit/a4f8c0291bfd32752c0c2c323f618c6a...
---
diff --git a/src/modules/dialog/dlg_hash.c b/src/modules/dialog/dlg_hash.c index 4e0e28b788..5557e87574 100644 --- a/src/modules/dialog/dlg_hash.c +++ b/src/modules/dialog/dlg_hash.c @@ -762,9 +762,10 @@ int dlg_update_rr_set(struct dlg_cell * dlg, unsigned int leg, str *rr) * the reference counter by one again iff a dialog has been found. * \param h_entry number of the hash table entry * \param h_id id of the hash table entry + * \param lmode id if 0, then dlg table entry is unlocked, otherwise is locked * \return dialog structure on success, NULL on failure */ -dlg_cell_t *dlg_lookup( unsigned int h_entry, unsigned int h_id) +dlg_cell_t *dlg_lookup_mode(unsigned int h_entry, unsigned int h_id, int lmode) { dlg_cell_t *dlg; dlg_entry_t *d_entry; @@ -777,24 +778,59 @@ dlg_cell_t *dlg_lookup( unsigned int h_entry, unsigned int h_id)
d_entry = &(d_table->entries[h_entry]);
- dlg_lock( d_table, d_entry); + dlg_lock(d_table, d_entry);
for( dlg=d_entry->first ; dlg ; dlg=dlg->next ) { if (dlg->h_id == h_id) { ref_dlg_unsafe(dlg, 1); - dlg_unlock( d_table, d_entry); + if (likely(lmode == 0)) { + dlg_unlock(d_table, d_entry); + } LM_DBG("dialog id=%u found on entry %u\n", h_id, h_entry); return dlg; } }
- dlg_unlock( d_table, d_entry); + dlg_unlock(d_table, d_entry); not_found: LM_DBG("no dialog id=%u found on entry %u\n", h_id, h_entry); return 0; }
+/*! + * \brief Lookup a dialog in the global list + * + * Note that the caller is responsible for decrementing (or reusing) + * the reference counter by one again iff a dialog has been found. + * \param h_entry number of the hash table entry + * \param h_id id of the hash table entry + * \return dialog structure on success, NULL on failure + */ +dlg_cell_t *dlg_lookup(unsigned int h_entry, unsigned int h_id) +{ + return dlg_lookup_mode(h_entry, h_id, 0); +} + +/*! + * \brief Search a dialog in the global list by iuid + * + * Note that the caller is responsible for decrementing (or reusing) + * the reference counter by one again if a dialog has been found. + * \param diuid internal unique id per dialog + * \param lmode id if 0, then dlg table entry is unlocked, otherwise is locked + * \return dialog structure on success, NULL on failure + */ +dlg_cell_t* dlg_get_by_iuid_mode(dlg_iuid_t *diuid, int lmode) +{ + if(diuid==NULL) + return NULL; + if(diuid->h_id==0) + return NULL; + /* dlg ref counter is increased by next line */ + return dlg_lookup_mode(diuid->h_entry, diuid->h_id, lmode); +} + /*! * \brief Search a dialog in the global list by iuid * @@ -810,7 +846,7 @@ dlg_cell_t* dlg_get_by_iuid(dlg_iuid_t *diuid) if(diuid->h_id==0) return NULL; /* dlg ref counter is increased by next line */ - return dlg_lookup(diuid->h_entry, diuid->h_id); + return dlg_lookup_mode(diuid->h_entry, diuid->h_id, 0); }
/*! diff --git a/src/modules/dialog/dlg_hash.h b/src/modules/dialog/dlg_hash.h index 5ecf13f871..eb933c5acb 100644 --- a/src/modules/dialog/dlg_hash.h +++ b/src/modules/dialog/dlg_hash.h @@ -201,6 +201,21 @@ extern dlg_table_t *d_table; } \ } while(0)
+/*! + * \brief Set a dialog lock (re-entrant) + * \param _dlg dialog cell + */ +#define dlg_cell_lock(_dlg) \ + dlg_lock(d_table, &(d_table->entries[(_dlg)->h_entry])) + +/*! + * \brief Set a dialog lock (re-entrant) + * \param _dlg dialog cell + */ +#define dlg_cell_unlock(_dlg) \ + dlg_unlock(d_table, &(d_table->entries[(_dlg)->h_entry])) + + /*! * \brief Unlink a dialog from the list without locking * \see unref_dlg_unsafe