Skip to content

Commit

Permalink
dialog: functions to search dialog by uuid and keep table entry locked
Browse files Browse the repository at this point in the history
- helper macros to lock/unlock table entry with dlg cell structure

(cherry picked from commit a4f8c02)
  • Loading branch information
miconda committed Mar 27, 2020
1 parent 01defdb commit 975d09a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
46 changes: 41 additions & 5 deletions src/modules/dialog/dlg_hash.c
Expand Up @@ -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;
Expand All @@ -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
*
Expand All @@ -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);
}

/*!
Expand Down
15 changes: 15 additions & 0 deletions src/modules/dialog/dlg_hash.h
Expand Up @@ -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
Expand Down

0 comments on commit 975d09a

Please sign in to comment.