Commit 410782fd authored by hf@genie.(none)'s avatar hf@genie.(none)

SCRUM

IS_USED_LOCK('lock') implementation
parent 5e66c763
......@@ -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);
......
......@@ -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);
......
......@@ -1632,8 +1632,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);
......@@ -1837,7 +1839,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;
......@@ -2698,6 +2700,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
......
......@@ -1151,6 +1151,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
......
......@@ -509,6 +509,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)},
......
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