If LEX is passed non-NULL, an automatic unlock of the plugin will happen in the LEX destructor. */
| 973 | in the LEX destructor. |
| 974 | */ |
| 975 | static plugin_ref intern_plugin_lock(LEX *lex, plugin_ref rc, |
| 976 | uint state_mask= PLUGIN_IS_READY | |
| 977 | PLUGIN_IS_UNINITIALIZED | |
| 978 | PLUGIN_IS_DELETED) |
| 979 | { |
| 980 | st_plugin_int *pi= plugin_ref_to_int(rc); |
| 981 | DBUG_ENTER("intern_plugin_lock"); |
| 982 | |
| 983 | mysql_mutex_assert_owner(&LOCK_plugin); |
| 984 | |
| 985 | if (pi->state & state_mask) |
| 986 | { |
| 987 | plugin_ref plugin; |
| 988 | #ifdef DBUG_OFF |
| 989 | /* |
| 990 | In optimized builds we don't do reference counting for built-in |
| 991 | (plugin->plugin_dl == 0) plugins. |
| 992 | */ |
| 993 | if (!pi->plugin_dl) |
| 994 | DBUG_RETURN(pi); |
| 995 | |
| 996 | plugin= pi; |
| 997 | #else |
| 998 | /* |
| 999 | For debugging, we do an additional malloc which allows the |
| 1000 | memory manager and/or valgrind to track locked references and |
| 1001 | double unlocks to aid resolving reference counting problems. |
| 1002 | */ |
| 1003 | if (!(plugin= (plugin_ref) my_malloc(PSI_NOT_INSTRUMENTED, sizeof(pi), |
| 1004 | MYF(MY_WME)))) |
| 1005 | DBUG_RETURN(NULL); |
| 1006 | |
| 1007 | *plugin= pi; |
| 1008 | #endif |
| 1009 | pi->ref_count++; |
| 1010 | DBUG_PRINT("lock",("thd: %p plugin: \"%s\" LOCK ref_count: %d", |
| 1011 | current_thd, pi->name.str, pi->ref_count)); |
| 1012 | |
| 1013 | if (lex) |
| 1014 | insert_dynamic(&lex->plugins, (uchar*)&plugin); |
| 1015 | DBUG_RETURN(plugin); |
| 1016 | } |
| 1017 | DBUG_RETURN(NULL); |
| 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | /* |
no test coverage detected