summaryrefslogtreecommitdiff
path: root/sql/sql_plugin.cc
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2014-11-28 18:38:09 +0100
committerSergei Golubchik <serg@mariadb.org>2014-11-29 20:22:00 +0100
commit6293c6936bd8aa14c62e474dab11249083bad2da (patch)
tree7c8893cd71544e1f38ddf80ab73a4907db68ad84 /sql/sql_plugin.cc
parent612c9964d35830fd54b0b1ec7893f886c393b9cb (diff)
downloadmariadb-git-MDEV-thd-specifics.tar.gz
thd_specifics serviceMDEV-thd-specifics
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 207804c53f6..0e6f2ce4ec3 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -4085,3 +4085,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;
+}
+