diff options
-rw-r--r-- | sql/item_create.cc | 6 | ||||
-rw-r--r-- | sql/item_create.h | 1 | ||||
-rw-r--r-- | sql/item_func.cc | 28 | ||||
-rw-r--r-- | sql/item_func.h | 10 | ||||
-rw-r--r-- | sql/lex.h | 1 |
5 files changed, 44 insertions, 2 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc index b80327b657a..3bc6fa47e83 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -475,6 +475,12 @@ Item *create_func_is_free_lock(Item* a) return new Item_func_is_free_lock(a); } +Item *create_func_is_used_lock(Item* a) +{ + current_thd->lex.uncacheable(); + return new Item_func_is_used_lock(a); +} + Item *create_func_quote(Item* a) { return new Item_func_quote(a); diff --git a/sql/item_create.h b/sql/item_create.h index 14812c47cdc..0e2295b6d4f 100644 --- a/sql/item_create.h +++ b/sql/item_create.h @@ -100,6 +100,7 @@ Item *create_func_version(void); Item *create_func_weekday(Item* a); Item *create_load_file(Item* a); Item *create_func_is_free_lock(Item* a); +Item *create_func_is_used_lock(Item* a); Item *create_func_quote(Item* a); Item *create_func_geometry_from_text(Item *a); diff --git a/sql/item_func.cc b/sql/item_func.cc index 8cb63182705..72db23d1953 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1610,8 +1610,10 @@ public: bool locked; pthread_cond_t cond; pthread_t thread; + ulong thread_id; - ULL(const char *key_arg,uint length) :key_length(length),count(1),locked(1) + ULL(const char *key_arg,uint length, ulong id) + :key_length(length),count(1),locked(1), thread_id(id) { key=(char*) my_memdup((byte*) key_arg,length,MYF(0)); pthread_cond_init(&cond,NULL); @@ -1815,7 +1817,7 @@ longlong Item_func_get_lock::val_int() if (!(ull= ((ULL*) hash_search(&hash_user_locks,(byte*) res->ptr(), res->length())))) { - ull=new ULL(res->ptr(),res->length()); + ull=new ULL(res->ptr(),res->length(), thd->thread_id); if (!ull || !ull->initialized()) { delete ull; @@ -2676,6 +2678,28 @@ longlong Item_func_is_free_lock::val_int() return 0; } +longlong Item_func_is_used_lock::val_int() +{ + String *res=args[0]->val_str(&value); + THD *thd=current_thd; + ULL *ull; + + null_value=1; + if (!res || !res->length()) + return 0; + + pthread_mutex_lock(&LOCK_user_locks); + ull= (ULL*) hash_search(&hash_user_locks,(byte*) res->ptr(), + res->length()); + pthread_mutex_unlock(&LOCK_user_locks); + if (!ull || !ull->locked) + return 0; + + null_value=0; + return ull->thread_id; +} + + /************************************************************************** Spatial functions diff --git a/sql/item_func.h b/sql/item_func.h index 772b90fd38e..0429e650071 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1162,6 +1162,16 @@ public: void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;} }; +class Item_func_is_used_lock :public Item_int_func +{ + String value; +public: + Item_func_is_used_lock(Item *a) :Item_int_func(a) {} + longlong val_int(); + const char *func_name() const { return "is_used_lock"; } + void fix_length_and_dec() { decimals=0; max_length=10; maybe_null=1;} +}; + /* For type casts */ enum Item_cast diff --git a/sql/lex.h b/sql/lex.h index 9156a2d35bb..3bc5820ee66 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -512,6 +512,7 @@ static SYMBOL sql_functions[] = { { "ISEMPTY", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_isempty)}, { "ISNULL", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_isnull)}, { "IS_FREE_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_is_free_lock)}, + { "IS_USED_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_is_used_lock)}, { "LAST_INSERT_ID", SYM(LAST_INSERT_ID),0,0}, { "ISSIMPLE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_issimple)}, { "LCASE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_lcase)}, |