summaryrefslogtreecommitdiff
path: root/sql/sql_plugin.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2014-12-03 23:51:47 +0100
committerSergei Golubchik <serg@mariadb.org>2014-12-04 10:41:55 +0100
commit8360e1a5b5e44debcc7aeaa10331278eb6273176 (patch)
treea971c74f153b0779d00a64df7959ea2334de2917 /sql/sql_plugin.cc
parent0c7d773fca1497ce4edae0a72c6f01348b0ca9be (diff)
downloadmariadb-git-8360e1a5b5e44debcc7aeaa10331278eb6273176.tar.gz
MDEV-6712 THD specifics for plugins
thd_specifics service
Diffstat (limited to 'sql/sql_plugin.cc')
-rw-r--r--sql/sql_plugin.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 397dbd2d33c..1874fb5e66d 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -4094,3 +4094,51 @@ static void restore_ptr_backup(uint n, st_ptr_backup *backup)
(backup++)->restore();
}
+/****************************************************************************
+ thd specifics service, see include/mysql/service_thd_specifics.h
+****************************************************************************/
+static const int INVALID_THD_KEY= -1;
+static uint thd_key_no = 42;
+
+int thd_key_create(MYSQL_THD_KEY_T *key)
+{
+ int flags= PLUGIN_VAR_THDLOCAL | PLUGIN_VAR_STR |
+ PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_NOCMDOPT;
+ char namebuf[256];
+ snprintf(namebuf, sizeof(namebuf), "%u", thd_key_no++);
+ mysql_rwlock_wrlock(&LOCK_system_variables_hash);
+ // non-letters in the name as an extra safety
+ st_bookmark *bookmark= register_var("\a\v\a\t\a\r", namebuf, flags);
+ mysql_rwlock_unlock(&LOCK_system_variables_hash);
+ if (bookmark)
+ {
+ *key= bookmark->offset;
+ return 0;
+ }
+ return ENOMEM;
+}
+
+void thd_key_delete(MYSQL_THD_KEY_T *key)
+{
+ *key= INVALID_THD_KEY;
+}
+
+void* thd_getspecific(MYSQL_THD thd, MYSQL_THD_KEY_T key)
+{
+ DBUG_ASSERT(key != INVALID_THD_KEY);
+ if (key == INVALID_THD_KEY || (!thd && !(thd= current_thd)))
+ return 0;
+
+ return *(void**)(intern_sys_var_ptr(thd, key, true));
+}
+
+int thd_setspecific(MYSQL_THD thd, MYSQL_THD_KEY_T key, void *value)
+{
+ DBUG_ASSERT(key != INVALID_THD_KEY);
+ if (key == INVALID_THD_KEY || (!thd && !(thd= current_thd)))
+ return EINVAL;
+
+ memcpy(intern_sys_var_ptr(thd, key, true), &value, sizeof(void*));
+ return 0;
+}
+