00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include <plugin/user_locks/module.h>
00023
00024 #include <string>
00025
00026 namespace user_locks {
00027 namespace locks {
00028
00029 int64_t WaitFor::val_int()
00030 {
00031 drizzled::String *res= args[0]->val_str(&value);
00032
00033 if (not res || not res->length())
00034 {
00035 my_error(drizzled::ER_USER_LOCKS_INVALID_NAME_LOCK, MYF(0));
00036 return 0;
00037 }
00038
00039 null_value= false;
00040
00041 drizzled::session_id_t id= getSession().getSessionId();
00042 bool found= false;
00043
00044 while (not found)
00045 {
00046 found= user_locks::Locks::getInstance().isUsed(Key(*getSession().user(), res->c_str()), id);
00047 if (not found)
00048 {
00049 boost::this_thread::restore_interruption dl(getSession().getThreadInterupt());
00050 try {
00051 user_locks::Locks::getInstance().waitCreate();
00052 }
00053 catch(boost::thread_interrupted const& error)
00054 {
00055 my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
00056 null_value= true;
00057 return 0;
00058 }
00059 }
00060 else
00061 {
00062 if (id == getSession().getSessionId())
00063 {
00064 my_error(drizzled::ER_USER_LOCKS_CANT_WAIT_ON_OWN_LOCK, MYF(0));
00065 null_value= true;
00066 return 0;
00067 }
00068 }
00069 }
00070
00071 return id;
00072 }
00073
00074 }
00075 }