422
422
effect is desired.
425
void mysql_lock_remove(Session *session, DRIZZLE_LOCK *locked,Table *table,
425
void mysql_lock_remove(Session *session, Table *table)
428
if (always_unlock == true)
429
mysql_unlock_some_tables(session, &table, /* table count */ 1);
433
for (i=0; i < locked->table_count; i++)
435
if (locked->table[i] == table)
437
uint32_t j, removed_locks, old_tables;
439
uint32_t lock_data_end;
441
assert(table->lock_position == i);
443
/* Unlock if not yet unlocked */
444
if (always_unlock == false)
445
mysql_unlock_some_tables(session, &table, /* table count */ 1);
447
/* Decrement table_count in advance, making below expressions easier */
448
old_tables= --locked->table_count;
450
/* The table has 'removed_locks' lock data elements in locked->locks */
451
removed_locks= table->lock_count;
453
/* Move down all table pointers above 'i'. */
454
memmove((locked->table+i), (locked->table+i+1),
455
(old_tables - i) * sizeof(Table*));
457
lock_data_end= table->lock_data_start + table->lock_count;
458
/* Move down all lock data pointers above 'table->lock_data_end-1' */
459
memmove((locked->locks + table->lock_data_start),
460
(locked->locks + lock_data_end),
461
(locked->lock_count - lock_data_end) *
462
sizeof(THR_LOCK_DATA*));
465
Fix moved table elements.
466
lock_position is the index in the 'locked->table' array,
467
it must be fixed by one.
468
table->lock_data_start is pointer to the lock data for this table
469
in the 'locked->locks' array, they must be fixed by 'removed_locks',
470
the lock data count of the removed table.
472
for (j= i ; j < old_tables; j++)
474
tbl= locked->table[j];
475
tbl->lock_position--;
476
assert(tbl->lock_position == j);
477
tbl->lock_data_start-= removed_locks;
480
/* Finally adjust lock_count. */
481
locked->lock_count-= removed_locks;
427
mysql_unlock_some_tables(session, &table, /* table count */ 1);
489
431
/** Abort all other threads waiting to get lock in table. */
491
void mysql_lock_abort(Session *session, Table *table, bool upgrade_lock)
433
void mysql_lock_abort(Session *session, Table *table)
493
435
DRIZZLE_LOCK *locked;
494
436
Table *write_lock_used;
496
438
if ((locked= get_lock_data(session, &table, 1, false,
497
439
&write_lock_used)))
499
for (uint32_t i=0; i < locked->lock_count; i++)
500
thr_abort_locks(locked->locks[i]->lock, upgrade_lock);
441
for (uint32_t x= 0; x < locked->lock_count; x++)
442
thr_abort_locks(locked->locks[x]->lock);
501
443
free((unsigned char*) locked);
539
DRIZZLE_LOCK *mysql_lock_merge(DRIZZLE_LOCK *a, DRIZZLE_LOCK *b)
541
DRIZZLE_LOCK *sql_lock;
542
Table **table, **end_table;
544
if (!(sql_lock= (DRIZZLE_LOCK*)
545
malloc(sizeof(*sql_lock)+
546
sizeof(THR_LOCK_DATA*)*(a->lock_count+b->lock_count)+
547
sizeof(Table*)*(a->table_count+b->table_count))))
548
return NULL; // Fatal error
549
sql_lock->lock_count=a->lock_count+b->lock_count;
550
sql_lock->table_count=a->table_count+b->table_count;
551
sql_lock->locks=(THR_LOCK_DATA**) (sql_lock+1);
552
sql_lock->table=(Table**) (sql_lock->locks+sql_lock->lock_count);
553
memcpy(sql_lock->locks,a->locks,a->lock_count*sizeof(*a->locks));
554
memcpy(sql_lock->locks+a->lock_count,b->locks,
555
b->lock_count*sizeof(*b->locks));
556
memcpy(sql_lock->table,a->table,a->table_count*sizeof(*a->table));
557
memcpy(sql_lock->table+a->table_count,b->table,
558
b->table_count*sizeof(*b->table));
561
Now adjust lock_position and lock_data_start for all objects that was
562
moved in 'b' (as there is now all objects in 'a' before these).
564
for (table= sql_lock->table + a->table_count,
565
end_table= table + b->table_count;
569
(*table)->lock_position+= a->table_count;
570
(*table)->lock_data_start+= a->lock_count;
573
/* Delete old, not needed locks */
574
free((unsigned char*) a);
575
free((unsigned char*) b);
582
482
Find duplicate lock in tables.
803
/*****************************************************************************
804
Lock table based on the name.
805
This is used when we need total access to a closed, not open table
806
*****************************************************************************/
809
Lock and wait for the named lock.
811
@param session Thread handler
812
@param table_list Lock first table in this list
816
Works together with global read lock.
824
int lock_and_wait_for_table_name(Session *session, TableList *table_list)
829
if (wait_if_global_read_lock(session, 0, 1))
831
pthread_mutex_lock(&LOCK_open); /* lock and wait for table when we need total access to table */
832
if ((lock_retcode = lock_table_name(session, table_list, true)) < 0)
834
if (lock_retcode && wait_for_locked_table_names(session, table_list))
836
unlock_table_name(table_list);
842
pthread_mutex_unlock(&LOCK_open);
843
start_waiting_global_read_lock(session);
849
704
Put a not open table with an old refresh version in the table cache.