Change module command parameter types

This commit introduces safe session references that can be handled without
holding locks. This allows the safe searching of sessions with the unique
ID of the session.

Remove the use of raw pointers passed as strings. Change the comments of
the argument types and add more details to the parsing function
documentation.
This commit is contained in:
Markus Makela
2016-11-30 19:32:12 +02:00
parent 994299b4f1
commit adbd666991
5 changed files with 90 additions and 47 deletions

View File

@ -915,3 +915,40 @@ const char* session_trx_state_to_string(session_trx_state_t state)
MXS_ERROR("Unknown session_trx_state_t value: %d", (int)state);
return "UNKNOWN";
}
static bool ses_find_id(DCB *dcb, void *data)
{
void **params = (void**)data;
SESSION **ses = (SESSION**)params[0];
int *id = (int*)params[1];
bool rval = true;
if (dcb->session->ses_id == *id)
{
/** We need to increment the reference count of the session to prevent it
* from being freed while it's in use. */
atomic_add(&dcb->session->refcount, 1);
*ses = dcb->session;
rval = false;
}
return rval;
}
SESSION* session_get_ref(int id)
{
SESSION *session = NULL;
void *params[] = {&session, &id};
dcb_foreach(ses_find_id, params);
return session;
}
void session_put_ref(SESSION *session)
{
if (session)
{
session_free(session);
}
}