summaryrefslogtreecommitdiff
path: root/sql/lock.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/lock.cc')
-rw-r--r--sql/lock.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/sql/lock.cc b/sql/lock.cc
index 9ce4137e380..d9bc5d43c79 100644
--- a/sql/lock.cc
+++ b/sql/lock.cc
@@ -149,8 +149,10 @@ static int lock_external(TABLE **tables,uint count)
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock)
{
DBUG_ENTER("mysql_unlock_tables");
- thr_multi_unlock(sql_lock->locks,sql_lock->lock_count);
- VOID(unlock_external(thd,sql_lock->table,sql_lock->table_count));
+ if (sql_lock->lock_count)
+ thr_multi_unlock(sql_lock->locks,sql_lock->lock_count);
+ if (sql_lock->table_count)
+ VOID(unlock_external(thd,sql_lock->table,sql_lock->table_count));
my_free((gptr) sql_lock,MYF(0));
DBUG_VOID_RETURN;
}
@@ -193,7 +195,7 @@ void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock)
if (i != found)
{
thr_multi_unlock(lock,i-found);
- sql_lock->lock_count-=found;
+ sql_lock->lock_count= found;
}
/* Then to the same for the external locks */
@@ -212,7 +214,7 @@ void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock)
if (i != found)
{
VOID(unlock_external(thd,table,i-found));
- sql_lock->table_count-=found;
+ sql_lock->table_count=found;
}
DBUG_VOID_RETURN;
}
@@ -294,7 +296,7 @@ static int unlock_external(THD *thd, TABLE **table,uint count)
DBUG_ENTER("unlock_external");
error_code=0;
- for (; count-- ; table++)
+ do
{
if ((*table)->current_lock != F_UNLCK)
{
@@ -302,7 +304,8 @@ static int unlock_external(THD *thd, TABLE **table,uint count)
if ((error=(*table)->file->external_lock(thd, F_UNLCK)))
error_code=error;
}
- }
+ table++;
+ } while (--count);
if (error_code)
print_lock_error(error_code);
DBUG_RETURN(error_code);