Commit 094e4b26 authored by Kristian Nielsen's avatar Kristian Nielsen

Clarify plugin_ref lifetimes in function comments

The mechanism in plugin_lock() et.al. which automatically unlocks
plugins unless called with NULL THD is quite subtle, and deserves
proper documentation.

(This was found during MDEV-12179 development, but is independent of
it, and so done in a separate commit).
parent da9decdc
...@@ -938,6 +938,10 @@ SHOW_COMP_OPTION plugin_status(const char *name, size_t len, int type) ...@@ -938,6 +938,10 @@ SHOW_COMP_OPTION plugin_status(const char *name, size_t len, int type)
} }
/*
If LEX is passed non-NULL, an automatic unlock of the plugin will happen
in the LEX destructor.
*/
static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc) static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc)
{ {
st_plugin_int *pi= plugin_ref_to_int(rc); st_plugin_int *pi= plugin_ref_to_int(rc);
...@@ -981,6 +985,16 @@ static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc) ...@@ -981,6 +985,16 @@ static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc)
} }
/*
Notes on lifetime:
If THD is passed as non-NULL (and with a non-NULL thd->lex), an entry is made
in the thd->lex which will cause an automatic unlock of the plugin in the LEX
destructor. In this case, no manual unlock must be done.
Otherwise, when passing a NULL THD, the caller must arrange that plugin
unlock happens later.
*/
plugin_ref plugin_lock(THD *thd, plugin_ref ptr) plugin_ref plugin_lock(THD *thd, plugin_ref ptr)
{ {
LEX *lex= thd ? thd->lex : 0; LEX *lex= thd ? thd->lex : 0;
...@@ -1017,6 +1031,16 @@ plugin_ref plugin_lock(THD *thd, plugin_ref ptr) ...@@ -1017,6 +1031,16 @@ plugin_ref plugin_lock(THD *thd, plugin_ref ptr)
} }
/*
Notes on lifetime:
If THD is passed as non-NULL (and with a non-NULL thd->lex), an entry is made
in the thd->lex which will cause an automatic unlock of the plugin in the LEX
destructor. In this case, no manual unlock must be done.
Otherwise, when passing a NULL THD, the caller must arrange that plugin
unlock happens later.
*/
plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type) plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type)
{ {
LEX *lex= thd ? thd->lex : 0; LEX *lex= thd ? thd->lex : 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment